Hi,
I'm looking for the following in calc -
create a directory name from the sheet name, create a text file then export a column (say A1-A50) into the text file.
I did something like this a few years ago in VB for excel. Looking for similar functionality in Calc.
Thanks
[Solved] Create/export Columns to text file
[Solved] Create/export Columns to text file
Last edited by Hagar Delest on Thu Mar 03, 2016 5:07 pm, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
Open office 4
Win 7 vista
Win 7 vista
Re: Create/export Columns to text file
A very simple version is
Code: Select all
oSheets = ThisComponent.Sheets
oSheet = oSheets.getByIndex(0) 'First Sheet
oCellrange = oSheet.getCellrangeByName("A1:A50")
ValueMatrix = oCellrange.DataArray
DirName = "c:\users\fjcc\desktop\" & oSheet.Name
MkDir(DirName)
FileChan = FreeFile
Open DirName & "\NewFile" for Output as FileChan
for i = 0 to 49
Write #FileChan, ValueMatrix(i)(0)
next i
Close #FileChan
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Create/export Columns to text file
Thanks,
That's pretty close, it's throwing quotes around each line in the text file though -
That's pretty close, it's throwing quotes around each line in the text file though -
Open office 4
Win 7 vista
Win 7 vista
Re: Create/export Columns to text file
I figured the quotes out, using Print instead of write...
Last question, is there a way to kick the sub off by checking if a single cell has been modified?
Example, say cell B1 has "n" and changed to "y" I'd want the sub to run.
Searching the forums, I think I may have found the answer - a listener routine.....
Will give it a try and post feedback here
Thanks!
Last question, is there a way to kick the sub off by checking if a single cell has been modified?
Example, say cell B1 has "n" and changed to "y" I'd want the sub to run.
Searching the forums, I think I may have found the answer - a listener routine.....
Will give it a try and post feedback here
Thanks!
Open office 4
Win 7 vista
Win 7 vista
Re: Create/export Columns to text file
So I got a listener to work, e.g. a change in anything from cells 1-10 runs the macro again.
However even when I call the listener from Main I still need to manually run the macro at least once to get it to work.
Can I have the macro start as soon as the file is open? (I'm trying to make this as simple and as automated as possible for end user)
However even when I call the listener from Main I still need to manually run the macro at least once to get it to work.
Can I have the macro start as soon as the file is open? (I'm trying to make this as simple and as automated as possible for end user)
Open office 4
Win 7 vista
Win 7 vista
Re: Create/export Columns to text file
Okay I believe I figured out everything I need - went into tools/customize and assigned my main sub to the "open document" action.
It looks like it executes the sub, registers the listener and writes the file if the listener detects a change....
FJCC, thanks for the help with the example snippet, it should get me where I need to go with the rest...
It looks like it executes the sub, registers the listener and writes the file if the listener detects a change....
FJCC, thanks for the help with the example snippet, it should get me where I need to go with the rest...
Open office 4
Win 7 vista
Win 7 vista