怎么用java编程_如何使用java编程方式创建一个odt文件?

看看

ODFDOM – the OpenDocument API

ODFDOM is a free OpenDocument Format

(ODF) library. Its purpose is to

provide an easy common way to create,

access and manipulate ODF files,

without requiring detailed knowledge

of the ODF specification. It is

designed to provide the ODF developer

community with an easy lightwork

programming API portable to any

object-oriented language.

The current reference implementation

is written in Java.

// Create a text document from a standard template (empty documents within the JAR)

OdfTextDocument odt = OdfTextDocument.newTextDocument();

// Append text to the end of the document.

odt.addText("This is my very first ODF test");

// Save document

odt.save("MyFilename.odt");

后来

在撰写本文(2)时,我们被告知,这些类已被弃用…大时间,OdfTextDocument API文档告诉您:

As of release 0.8.8, replaced by org.odftoolkit.simple.TextDocument in

Simple API.

这意味着您仍然在项目中包含相同的活动.jar文件,简单的odf-0.8.1-incubating-jar-with-dependencies.jar,但是您要解压缩以下.jar以获取文档:simple- odf-0.8.1-incubating-javadoc.jar,而不是odfdom-java-0.8.10-incubating-javadoc.jar。

顺便提一下,文档链接会在.zip里面下载一堆jar文件,这个文件就是“0.6.1”,但是大部分内容似乎更像是0.8.1。我不知道为什么他们在“已弃用”课程的文档中说“0.8.8”:几乎所有的内容都已被标记为不推荐。

那么等效的简单代码就是:

odt_doc = org.odftoolkit.simple.TextDocument.newTextDocument()

para = odt_doc.getParagraphByIndex( 0, False )

para.appendTextContent( 'stuff and nonsense' )

odt_doc.save( 'mySpankingNewFile.odt' )

PS正在使用Jython,但Java应该是显而易见的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值