我有一个非常简单的LibreOffice Calc电子表格,其中包含列标题和列(单元格可以是多行),有些像:
id
我想以(半)自动方式获取包含以下内容的纯文本文件:
| id | Prio | Domain | Comment | ... |
|----|------|--------|----------------|-----|
| 1 | A | Foo | Something | |
|----|------|--------|----------------|-----|
| 2 | A | Bar | Something else | |
| | | | Possibly on | |
| | | | multiple lines | |
|----|------|--------|----------------|-----|
| 1 | C | Baz | Something else | |
这有可能吗? 我知道LO宏功能(例如:this),所以琐碎的答案可能是“是”,但我从未使用它们所以我需要一些指导(我甚至不知道如何使用这样的的东西)。
答案 0 :(得分:0)
There are a lot of different ways this could be done. One idea is to go to File -> Save As
and save as type CSV. In the filter settings, check Quote all text cells
to make it easier to handle newlines.
Then write a script that uses the python csv module, for example:
import csv
with open('Untitled 1.csv') as csvfile:
spamreader = csv.reader(csvfile, dialect='excel',)
for row in spamreader:
print("row: ", end="")
print(', '.join(row))
To avoid the Save As
step, you could write a macro instead. It might be easier to write it in python rather than Basic, because file handling and string manipulation can be difficult in Basic.