[Solved] Print range of cells or Clipboard content into file

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Crls7
Posts: 5
Joined: Tue Aug 12, 2008 1:29 pm

[Solved] Print range of cells or Clipboard content into file

Post by Crls7 »

Hi everyone.
I apologize if question I'll ask has already been answered, I did try search, but didn't find anything that would help me. I only know how to do simple things, and now I am stuck with this.

I have file that does certain calculations on first 2 sheets and passes some results into range of cells on Sheet3.
There I made 3 PushButtons and assigned to each macro that will sort above mentioned range of cells in certain fashion, then copy them all into clipboard. Till there everything works just fine.
Now what I need is to print that clipboard content into simple text file. Can you please tell me how ? All syntaxes I have found are:
Print #FileNo, "This is last line of text"
Write #FileNo,sValue,400
but I can't figure how to send specific range of cells to file.

Another question is: Can I somehow in macro that is run when MouseButtonPressed on one PushButton, disable all others PushButtons of that sheet? Or change their Label?

Thank you ever so much!
Last edited by Crls7 on Thu Aug 21, 2008 3:51 pm, edited 1 time in total.
OOo 2.4.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Print range of cells or Clipboard content into file

Post by Villeroy »

http://api.openoffice.org/docs/common/r ... tDataArray
The returned array is an array of rows containing arrays of values. A1:B2 is ((A1,B1),(A2,B2))
Each element of the result contains a double or a string.
... empty cells are represented by an empty string, error values are of Basic type Null.

Code: Select all

aRows() = myRange.getDataArray()
dim aLines(uBound(aRows())
for r = lBound(aRows()) To lBound(aRows())
  aCols() = aRows(r)
  aLines(r) = Join(aCols(), ";")
next r
fh= freefile()
open "/tmp/bla.txt" for append as fh
for i = 0 to uBound aLines()
  sLine = aLines(i)
  print sLine fh
next i
Join is a built-in function of the Basic language, documented in the help files. I'm unshure about the open nor print statement (not used since many years), but it is documented in the help and it's the same shit as in other Basic dialects.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Crls7
Posts: 5
Joined: Tue Aug 12, 2008 1:29 pm

Re: Print range of cells or Clipboard content into file

Post by Crls7 »

This did not work, but I got answer at one other forum. Hoping they wouldn't mind me passing thsi info, and in case anyone else has similar program, here it is:

I was given a function made by Andrew Pitonyak
Function ConvertClipToText as String

with it I copy to clipboard and to file defined range:

Code: Select all

args2(0).Name = "ToPoint"
args2(0).Value = "$C$6:$T$26"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
rem ----------------------------------
sString = convertClipToText()
Filename = "c:/blabla.txt" 
FileNo = Freefile
Open Filename For Output As #FileNo 
Print #FileNo, sString 
Close #FileNo
OOo 2.4.X on Ms Windows XP
Post Reply