1

请有人帮助我将文本放入段落中。我有这个代码:

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”(初始)字符的开头......这到底是什么?

4

1 回答 1

4

尝试最近每晚构建/ svn 结帐 POI。HWPF 代码库目前正在由 Sergey 进行大量工作,并且最近修复了您所描述的错误。

于 2011-08-14T19:11:54.250 回答