Page 1 of 1

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

PostPosted: Tue Aug 12, 2008 1:51 pm
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!

Re: Print range of cells or Clipboard content into file

PostPosted: Thu Aug 14, 2008 1:11 pm
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   Expand viewCollapse view
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.

Re: Print range of cells or Clipboard content into file

PostPosted: Thu Aug 21, 2008 3:50 pm
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   Expand viewCollapse view
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