0
我試圖用Apache的ODF grabit生成結構良好的OpenDocument文本文件。我希望通過對不同部分的數據使用樣式來實現這一點。所以我生成了一個包含我希望使用的所有樣式的模板文件。使用ODF工具包在段落上設置樣式
我的下一步是嘗試使用簡單的ODF API設置我的文檔。顯然這是推薦的方法。出於測試目的,我決定保持簡單。所以現在我只是想給一個預定義的風格。
這是我寫的代碼:
public static void main(String[] args) throws Exception {
TextDocument odt = TextDocument.loadDocument("template.ott");
// List the paragraph styles, just to check if 'Abc' is actually there.
// Which it is.
OdfOfficeStyles styles = odt.getOrCreateDocumentStyles();
for (OdfStyle e : styles.getStylesForFamily(OdfStyleFamily.Paragraph)) {
System.out.println(e.getStyleNameAttribute());
}
// Create a paragraph, and give it the style 'Abc'
Paragraph p = odt.addParagraph("Blah.");
p.setStyleName("Abc");
// Save the file
odt.save("result.odt");
}
然而,這似乎並沒有工作。 'Blah'。我添加的段落顯示爲默認樣式。看起來好像在過去的幾個版本中很多都發生了變化,所以文檔相當稀少。
是我想要使用Simple ODF API的可能性嗎?或者我應該看看實際的ODFDOM API?如果是這種情況,那麼代碼片段將非常感謝。
謝謝。