1
誰かが段落にテキストを入れるのを手伝ってください。私はこのコードを持っている:ApacheのpoiでHWPFドキュメントを作成するには
private void createDOCDocument(String from, File file) throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(DOCGenerator.class.getClass().getResourceAsStream("/poi/template.doc"));
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
Paragraph par1 = range.insertAfter(new ParagraphProperties(), 0);
CharacterRun run1 = par1.insertAfter(from);
run1.setFontSize(11);
DocumentSummaryInformation dsi = doc.getDocumentSummaryInformation();
CustomProperties cp = dsi.getCustomProperties();
if (cp == null)
cp = new CustomProperties();
cp.put("myProperty", "foo bar baz");
dsi.setCustomProperties(cp);
doc.write(new FileOutputStream(file));
}
をしかし、問題は、私は、文字列「から」直接の範囲にを入れた場合、それは結果の文書になることですが、私は、段落を作成して、代わりにそこにそれを置く場合、ドキュメントは空です。私がApacheのtikaとそのWordExtractorで処理しても、それは何も得られません。
btw /poi/template.docは空のドキュメントです。
私はこのようにそれを行う場合:
Paragraph par1 = range.getParagraph(0);
CharacterRun run1 = par1.insertAfter(from);
とからは、ドキュメントに先頭に(初期)「W」の文字があり、「何」である...これは一体何でしょうか?