首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用apache poi创建HWPF文档

如何用apache poi创建HWPF文档
EN

Stack Overflow用户
提问于 2011-08-14 23:21:33
回答 1查看 3K关注 0票数 1

请谁帮我把文字放入段落。我有这样的代码:

代码语言:javascript
复制
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处理它,它也什么也得不到。

btw /poi/template.doc为空文档。

如果我这样做:

代码语言:javascript
复制
Paragraph par1 = range.getParagraph(0);
CharacterRun run1 = par1.insertAfter(from);

在文档的开头有"w“(首字母)字符...见鬼,这是什么?

EN

回答 1

Stack Overflow用户

发布于 2011-08-15 03:11:54

尝试使用最近的夜间构建/ svn检出POI。HWPF代码库目前正在由Sergey进行大量的工作,像您所描述的那样的bug最近已经被修复。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7057666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档