Hi,
there is a way to automatically save the columns of a sheet as different text files?
Willy
Here an example
Hi,
there is a way to automatically save the columns of a sheet as different text files?
Willy
Here an example
When you say āautomaticā, what is exactly?
An file with exactly you want, will help to help you.
With a button or a menu item, something like that.
With button not is automatic, but, if this itās ok for youā¦ only I need an example.
Iāve attached a simple example of file.
Thanks
I see your file, but, Only in your mind are how to needed export this information. A text file can be many different things.
Ok, now there is an image (I cannot attach txt files!) with that I would like
First version in Basic. Caution: If you have a few data, this code work fine, with many (5000+) rows, maybe run slow then we need refactory code.
Sub export_to_txt()
path_target = "/home/mau/"
doc = ThisComponent
sheet = doc.CurrentController.ActiveSheet
cell = sheet.getCellRangeByname("A1")
cursor = sheet.createCursorByRange(cell)
cursor.collapseToCurrentRegion()
data = cursor.DataArray
For c = 0 To UBound(data(0))
ff = FreeFile()
path = path_target & data(0)(c) & ".txt"
Open path For Output As ff
Print #ff, data(0)(c)
For r = 1 To UBound(data)
Print #ff, data(r)(c)
Next r
Close #ff
Next c
End Sub
Version Python, more simple:
import uno
def main():
doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.CurrentController.ActiveSheet
cursor = sheet.createCursorByRange(sheet['A1'])
cursor.collapseToCurrentRegion()
data = cursor.DataArray
for c in range(len(data[0])):
values = [r[c] for r in data]
path = '/home/mau/{}.txt'.format(values[0])
with open(path, 'w') as f:
f.write('\n'.join(values))
return
Version using my library easymacro
import easymacro as app
def main():
data = app.get_cell('A1').current_region.data
for c in range(len(data[0])):
values = [r[c] for r in data]
path = '/home/mau/{}.txt'.format(values[0])
app.save_file(path, data='\n'.join(values))
return
Thanks a lot!!
Python & LibreOffice? Iāve discovered a new wonderful world
Iāve used the first python macro, a couple of adjustments and it works like a charm!
I quickly tried the second version, but I couldnāt get it to work (probably I havenāt understood where to put easymacro.py ).
I think there is also an error here in the doc: https://gitlab.com/mauriciobaeza/zaz/-/wikis/easymacro.py
I think a final colon ā:ā is missing here:
def test_easymacro()
Thanks, I fixed it.
hey mauricio, i copy-pasted it and it shows an I/O error in line 16. can you please advice?