テキストを段落に入れるのを手伝ってください。私はこのコードを持っています:
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));
}
しかし、問題は、「from」文字列を範囲に直接入れると、結果のドキュメントに含まれますが、段落を作成して代わりにそこに入れると、ドキュメントが空になることです。Apache tika とその WordExtractor で処理しても何も得られません。
ところで /poi/template.doc は空のドキュメントです。
私がこのようにすれば:
Paragraph par1 = range.getParagraph(0);
CharacterRun run1 = par1.insertAfter(from);
from が "whatever" の場合、ドキュメントの先頭に "w" (イニシャル) の文字があります。これは一体何なのでしょうか。