ODFPy 文档

发布于 2024-07-24 01:19:38 字数 1542 浏览 7 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

墨离汐 2024-07-31 01:19:38

不幸的是,文档很糟糕,生成的 Python 包装器在代码中的记录很糟糕,提供了许多参数列表类似于 func(*args) 的函数。

参考手册实际上很有用,但在您刚开始使用时就没有用了 - 它没有提供有关如何使用这些功能的任何上下文。 我建议从 教程 和所有 示例。 尽管它们可能与您的用例没有任何关系,但它们将帮助您了解该包的工作原理。 在您习惯了包的结构方式之后,您通常可以通过将 API 文档与 OpenDocument Essentials 书。

(这种关系充其量是有点脆弱的,但您通常可以从中推断出方法和属性值。例如,在使用电子表格时,书中方便的 Office 列表:值类型数据提供了构建正确的必要常量。 TableCell(valuetype=...) 实例)

此外,在 OpenOffice 中制作小文档,然后检查 xml 并将其与 ODFPy 生成的 XML 进行比较,可以极大地帮助您调试可能出错的位置。

The documentation is unfortunately horrible, and the generated Python wrapper is lousily documented in code, providing lots of functions whose argument lists look like func(*args).

The reference manual is actually useful, but not when you're starting out - it doesn't provide any context of how to use these functions. I would suggest starting with the tutorial and all the examples. Even though they may have nothing to do with your use case, they will help you get the feel of how the package works. After you've gotten used to the way the package is structured, you can often make sense of the documentation by combining the API doc with the information in the OpenDocument Essentials book.

(The relationship is somewhat tenuous at best, but you can often intuit method and attribute values from it. When working with the spreadsheet, for example, the handy list of office:value-type data in the book provided the necessary constants for building proper TableCell(valuetype=...) instances)

Also, making small documents in OpenOffice and then inspecting the xml and comparing it to the XML generated from ODFPy greatly helps you debug where you might have gone wrong.

贱人配狗天长地久 2024-07-31 01:19:38

I found more documentation (the web site has been reorganized in the past few years) in api-for-odfpy.odt.

古镇旧梦 2024-07-31 01:19:38

它有点过时了,但可以帮助某人。
我发现只有一种使用 ODFPY 的方法:

  1. 生成 ODF 文档(即 f1.ods),
  2. 复制它并在 LibreOffice/OpenOffice 或其他(即 f2.odf)中编辑,
  3. 将两个文件更改为 f1.zip 和 f2.zip
  4. 提取两个文件。

主要格式和数据位于“content.xml”和“styles.xml”中

  1. 比较两种格式,
  2. 在Python脚本中进行更改,
  3. 迭代1-7,直到获得足够的结果:D:D

这是一些日期时间格式示例,我有这样做:

from odf.opendocument import OpenDocumentSpreadsheet
from odf.style import Style, TableCellProperties
from odf.number import DateStyle, Text, Year, Month, Day, Hours, Minutes, Seconds
from odf.text import P
from odf.table import Table, TableRow, TableCell

# Generate document object
doc = OpenDocumentSpreadsheet()
table = Table(name="Exported data")
#create custom format in styles.xml
date_style = DateStyle(name="date-style1") #, language="lv", country="LV")
date_style.addElement(Year(style="long"))
date_style.addElement(Text(text=u"-"))
date_style.addElement(Month(style="long"))
date_style.addElement(Text(text=u"-"))
date_style.addElement(Day(style="long"))
date_style.addElement(Text(text=u" "))
date_style.addElement(Hours(style="long"))
date_style.addElement(Text(text=u":"))
date_style.addElement(Minutes(style="long"))
date_style.addElement(Text(text=u":"))
date_style.addElement(Seconds(style="long", decimalplaces="3"))
doc.styles.addElement(date_style)
#link to generated style from content.xml
ds = Style(name="ds1", datastylename="date-style1",parentstylename="Default", family="table-cell")
doc.automaticstyles.addElement(ds)

#create simple cell
tr = TableRow()
tc = TableCell(valuetype='string')
tc.addElement(P(text = "Date-Time"))
tr.addElement(tc)
table.addElement(tr)

#create cell with custom formatting
lineDT = #some date-time variable
tr = TableRow()
tc = TableCell(valuetype='date',datevalue = lineDT.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3],stylename=ds)
tc.addElement(P(text=lineDT.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]))
tr.addElement(tc)
table.addElement(tr)

#save ods
doc.spreadsheet.addElement(table)
doc.save("test.ods", True)

我已经更新了代码,因为以前的版本在 MS 产品上打开错误。

It's outdated, a bit, but could help someone.
I have found only one way to work with ODFPY:

  1. generate your ODF document (i.e. f1.ods)
  2. make copy of it and edit in LibreOffice/OpenOffice or other (i.e. f2.odf)
  3. change both files to f1.zip and f2.zip
  4. extract both files.

main formatting and data is located in "content.xml" and "styles.xml"

  1. compare both formatting
  2. make changes in python script
  3. iterate 1-7 until you have sufficient result :D:D

Here is some date-time format example, I have made that way:

from odf.opendocument import OpenDocumentSpreadsheet
from odf.style import Style, TableCellProperties
from odf.number import DateStyle, Text, Year, Month, Day, Hours, Minutes, Seconds
from odf.text import P
from odf.table import Table, TableRow, TableCell

# Generate document object
doc = OpenDocumentSpreadsheet()
table = Table(name="Exported data")
#create custom format in styles.xml
date_style = DateStyle(name="date-style1") #, language="lv", country="LV")
date_style.addElement(Year(style="long"))
date_style.addElement(Text(text=u"-"))
date_style.addElement(Month(style="long"))
date_style.addElement(Text(text=u"-"))
date_style.addElement(Day(style="long"))
date_style.addElement(Text(text=u" "))
date_style.addElement(Hours(style="long"))
date_style.addElement(Text(text=u":"))
date_style.addElement(Minutes(style="long"))
date_style.addElement(Text(text=u":"))
date_style.addElement(Seconds(style="long", decimalplaces="3"))
doc.styles.addElement(date_style)
#link to generated style from content.xml
ds = Style(name="ds1", datastylename="date-style1",parentstylename="Default", family="table-cell")
doc.automaticstyles.addElement(ds)

#create simple cell
tr = TableRow()
tc = TableCell(valuetype='string')
tc.addElement(P(text = "Date-Time"))
tr.addElement(tc)
table.addElement(tr)

#create cell with custom formatting
lineDT = #some date-time variable
tr = TableRow()
tc = TableCell(valuetype='date',datevalue = lineDT.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3],stylename=ds)
tc.addElement(P(text=lineDT.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]))
tr.addElement(tc)
table.addElement(tr)

#save ods
doc.spreadsheet.addElement(table)
doc.save("test.ods", True)

I have updated code, a bit, because previous version opened wrong on MS product.

三月梨花 2024-07-31 01:19:38

尝试 ezodf
他们还有一个 doc

try ezodf
they also have a doc

2024-07-31 01:19:38

好的,这是一个快速帮助:

  1. 获取 odfpy 源代码:

    ~$ svn checkout https://svn.forge.osor.eu/svn/odfpy/trunk odfpy 
      
  2. 安装它:

    <前><代码> ~$ cd odfpy
    ~/odfpy$ python setup.py 安装

  3. 生成文档:

    ~/odfpy$ epydoc --pdf odf 
      

    我已将生成的文档上传到此处

  4. 运行这个简单的示例程序:

    from odf.opendocument 导入 OpenDocumentText 
      从 odf.text 导入 P     
      文本文档 = OpenDocumentText() 
      p = P(文本=“你好世界!”) 
      textdoc.text.addElement(p) 
      textdoc.save("helloworld", True) 
      
  5. 阅读示例并尝试理解所有内容:

    ~/odfpy$ emacs 示例/*.py 
      

希望有所帮助! 祝你好运!

Okay, here's a quick help:

  1. Grab odfpy source code:

    ~$ svn checkout https://svn.forge.osor.eu/svn/odfpy/trunk odfpy
    
  2. Install it:

     ~$ cd odfpy
     ~/odfpy$ python setup.py install
    
  3. Generate the documentation:

    ~/odfpy$ epydoc --pdf odf
    

    I have uploaded the generated documentation here.

  4. Run this simple example program:

    from odf.opendocument import OpenDocumentText
    from odf.text import P    
    textdoc = OpenDocumentText()
    p = P(text="Hello World!")
    textdoc.text.addElement(p)
    textdoc.save("helloworld", True)
    
  5. Read the examples and try to make sense of everything:

    ~/odfpy$ emacs examples/*.py
    

Hope that helps! Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文