【问题标题】:How to produce a formatted report from LibreOffice Calc spreadsheet?如何从 LibreOffice Calc 电子表格生成格式化报告?
【发布时间】:2016-08-31 07:17:53
【问题描述】:

我有一个非常简单的 LibreOffice Calc 电子表格,其中包含列标题和列(单元格可以是多行),类似于:

| id | Prio | Domain | Comment        | ... |
|----|------|--------|----------------|-----|
|  1 |    A | Foo    | Something      |     |
|----|------|--------|----------------|-----|
|  2 |    A | Bar    | Something else |     |
|    |      |        | Possibly on    |     |
|    |      |        | multiple lines |     |
|----|------|--------|----------------|-----|
|  1 |    C | Baz    | Something else |     |

我想以(半)自动化的方式获得一个纯文本文件,其中包含以下内容:

id:      1
Prio:    A
Domain:  Foo
Comment: Something
...

id:      2
Prio:    A
Domain:  Bar
Comment: Something else
         Possibly on
         multiple lines
...

id:      3
Prio:    C
Domain:  Baz
Comment: Something else
...

这有可能吗? 我知道 LO 宏功能(例如:this),所以简单的答案可能是“是”,但我从未使用过它们,所以我需要一些指导(我什至不知道如何使用这样的东西) .

【问题讨论】:

    标签: report libreoffice-calc libreoffice-basic


    【解决方案1】:

    有很多不同的方法可以做到这一点。一种想法是转到File -> Save As 并保存为 CSV 类型。在过滤器设置中,勾选Quote all text cells,以便更轻松地处理换行符。

    然后编写一个使用python csv module的脚本,例如:

    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))
    

    为避免Save As 步骤,您可以编写一个宏。用python 编写它可能比Basic 更容易,因为在Basic 中文件处理和字符串操作可能很困难。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多