请谁帮我把文字放入段落。我有这样的代码:
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为空文档。
如果我这样做:
Paragraph par1 = range.getParagraph(0);
CharacterRun run1 = par1.insertAfter(from);在文档的开头有"w“(首字母)字符...见鬼,这是什么?
发布于 2011-08-15 03:11:54
尝试使用最近的夜间构建/ svn检出POI。HWPF代码库目前正在由Sergey进行大量的工作,像您所描述的那样的bug最近已经被修复。
https://stackoverflow.com/questions/7057666
复制相似问题