- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 POI API 的新手,因此,每当我使用 HWPFDocument 类在 HWPF 文档创建的 .doc 文件中写下文本时,生成的 doc 文件只有一个字母而不是整个文本,我写了。
因此,请给出我如何向其中添加更多文本的答案。
这是代码:
/**
* Create a POIFSFileSystem from an InputStream.
* Test.doc is an empty doc with no contents
*/
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("test.doc"));
/**
* Horrible word Document Format
*/
HWPFDocument hwpfDocument = new HWPFDocument(fs);
/**
* range is used for getting the range of the document except header and footer
*/
Range range = hwpfDocument.getRange();
range.numParagraphs();
/**
* creating Paragraph
*/
/**
* Inserts a paragraph into the end of this range.
* ParagraphProperties -> for creating Paragraph, index of the paragraph
*/
/*Paragraph paragraph1 = range.insertBefore(new ParagraphProperties(), 0);
paragraph1.setJustification((byte) 0); // 0-left, 1-center, 2-right, 3-left and right*/
CharacterRun characterRun1 = range.insertBefore("Document");
/**
* setting the font size
*/
characterRun1.setFontSize(2 * 12); // takes as an argument half points
/**
* making Text Bold Italic
*/
characterRun1.setBold(true);
characterRun1.setItalic(true);
characterRun1.setColor(111);
characterRun1.setData(true);
//characterRun1.replaceWith("Document");
hwpfDocument.write(new FileOutputStream("hpwf-create-doc.doc", true));
最佳答案
如果可以,从使用 HWPFDocument 切换到 XWPFDocument(生成 .docx 而不是 .doc)。 .docx 格式在底层更明智(它基于 XML 而不是二进制),因此 POI 通常用它做得更好。
否则,请尝试使用更简单的模板文档。 word 文件格式对各种位都非常挑剔,您可能遇到过这样的情况,即 POI 不知道需要更新文件中的某些内容,然后 word 默默反对。
关于java - 如何在java中的.doc文件中使用POI hwpfdocument写入大量文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6149298/
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在尝试从 microsoft-word 中提取数据并将其转换为 sql 语句并将其插入 Oracle 数据库。 当 ms-word 中的数据包含通过 [Shift-Enter] 创建的新行而不只是
我正在尝试使用 HWPFDocument 创建 word 文档。我能够创建具有某些功能的文档,但无法获得一些东西。我的问题很简单,但我无法弄清楚一些事情。我想将这个简单的 HTML 转换成创建的 wo
当前使用: org.apache.poipoi3.10-FINAL 我正在尝试编写一个简单的程序来获取 doc/x 文件的字数。但由于某种原因,它无法找到该特定方法。是在另一个包里还是别的东西里?我一
我必须更改 doc word 中的文本并转换为 pdf。我已经更改了文本,但是 IDK,如何将 HWPFDocument 转换为 pdf。 在调用 XWPFDocument document = ne
我正在考虑将 Apache POI 包含到我的应用程序中。主要目标是输出 RTF 文档,但 DOC 也不错。但文档中关于编写 HWPFDocument 的内容并不是很详细,而且我在网上找到的所有内容都
首先,我觉得使用 Apache POI API 不是很容易,就像任何其他 Java API 一样,因为我很困惑哪些是修改 docx 内容所需的所有 jar 文件,我正在使用 poi-scratchpa
我想从 .doc 文件中删除单词元数据。我的 .docx 文件可以与 XWPFDocument 配合使用,但以下用于删除元数据的代码对于大型 (> 1MB) 文件会失败。例如,使用带有图像的 6MB
我是一名优秀的程序员,十分优秀!