Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache poi 使用Apache POI 3.8(HWPF)格式化文本_Apache Poi_Hwpf - Fatal编程技术网

Apache poi 使用Apache POI 3.8(HWPF)格式化文本

Apache poi 使用Apache POI 3.8(HWPF)格式化文本,apache-poi,hwpf,Apache Poi,Hwpf,我试图使用Apache POI 3.8在文档中插入以下文本: [粗体][正常] 但输出文档有以下内容: [粗体][正常] 守则: 导入org.apache.poi.hwpf.hwpf文档; 导入org.apache.poi.hwpf.usermodel.*; 导入java.io.*; 公共班机{ 公共静态无效主字符串[]args引发IOException{ 最终HWPFDocument doc=新HWPFDocument新文件InputStreamEmpty.dot; 最终范围=doc.getR

我试图使用Apache POI 3.8在文档中插入以下文本:

[粗体][正常]

但输出文档有以下内容:

[粗体][正常]

守则:

导入org.apache.poi.hwpf.hwpf文档; 导入org.apache.poi.hwpf.usermodel.*; 导入java.io.*; 公共班机{ 公共静态无效主字符串[]args引发IOException{ 最终HWPFDocument doc=新HWPFDocument新文件InputStreamEmpty.dot; 最终范围=doc.getRange; final CharacterRun cr1=范围。在[Bold]之后插入; cr1.setBoldtrue; 最终字符运行cr2=cr1。在[正常]之后插入; cr2.1为假; doc.writenew FileOutputStreamoutput.doc; } }
正确的做法是什么?

我就是这样做的。使用POI 3.11

paragraph = doc.createParagraph();
paragraph.setStyle(DOG_HEAD_STYLE);
XWPFRun tmpRun = paragraph.createRun();
tmpRun.setText("non bold text ");

tmpRun = paragraph.createRun();
tmpRun.setBold(true);
tmpRun.setText("bold text");
tmpRun = paragraph.createRun();
tmpRun.setBold(false);
tmpRun.setText(" non bold text again");

我是这样做的。使用POI 3.11

paragraph = doc.createParagraph();
paragraph.setStyle(DOG_HEAD_STYLE);
XWPFRun tmpRun = paragraph.createRun();
tmpRun.setText("non bold text ");

tmpRun = paragraph.createRun();
tmpRun.setBold(true);
tmpRun.setText("bold text");
tmpRun = paragraph.createRun();
tmpRun.setBold(false);
tmpRun.setText(" non bold text again");

我想你可能会有问题尝试它的整体范围。您能否尝试只获取一个段落,并在其后面添加运行记录,看看效果是否更好?final Range=doc.getRange.getParagraph0;-没有帮助,文本仍然是[粗体][正常]。我已经用XWPF尝试过类似的方法,它可以按预期工作,但我仍然需要HWPF。我认为在整个范围内尝试它可能会有问题。您能否尝试只获取一个段落,并在其后面添加运行记录,看看效果是否更好?final Range=doc.getRange.getParagraph0;-没有帮助,文本仍然是[粗体][正常]。我在XWPF上尝试过类似的方法,它按预期工作,但我仍然需要HWPF。OP明确表示他们希望使用HWPF,那么这个XWPF代码如何帮助他们?OP明确表示他们希望使用HWPF,那么这个XWPF代码如何帮助他们?