POI 导出word时不能换行解决
来源:互联网 发布:曼德拉效应 知乎 编辑:程序博客网 时间:2024/05/17 19:18
今天遇到这个问题,郁闷了很久,还好终于解决了,在此给大家分享下经验!
其它的就不说了,上代码:
思路:将需要换行的地方断开,分别生成段,这样就ok了
public void buildWord(String title, String content, String exportPath) {
FileOutputStream out = null;
try {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph head = doc.createParagraph();
head.setAlignment(ParagraphAlignment.LEFT);
head.setVerticalAlignment(TextAlignment.TOP);
XWPFRun r1 = head.createRun();
r1.setBold(true);
r1.setText(title);
r1.setBold(true);
r1.setFontFamily("Verdana");
r1.setFontSize(12);
XWPFParagraph body = null;
String[] subContent = content.split("\r");
int counter = 0;
for(String str : subContent)
{
counter++;
body = doc.createParagraph();
body.setAlignment(ParagraphAlignment.LEFT);
body.setSpacingAfter(0);
body.setSpacingBefore(0);
XWPFRun r4 = body.createRun();
r4.setText(str);
r4.setFontSize(10);
r4.setFontFamily("Verdana");
}
System.out.println("total phase:"+counter);
String tmpName = SDF.format(new Date());
out = new FileOutputStream(exportPath+File.separator+tmpName+".docx");
doc.write(out);
} catch (Exception e) {
e.printStackTrace();
}finally
{
try {
if(out != null)
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("done!");
}
- POI 导出word时不能换行解决
- poi导出word 表格 单元格内换行
- FreeMarker导出word,解决\n换行问题
- POI写Word换行
- POI写Word换行
- POI操作word 换行
- POI 导出word
- poi导出word[1]
- poi导出word[2]
- POI模板导出word
- POI导出word 文档
- 使用poi导出word
- POI 导出word
- POI 导出 Word 表格
- poi导出word
- POI导出Excel强制换行
- POI根据模版导出word
- POI Word 模板导出教程
- PowerShell 如何 远程连接
- java管道学习
- linux常用命令
- [sg函数] hdu 1847 Good Luck in CET-4 Everybody!
- Linux系统结构 和linux kernel基本架构
- POI 导出word时不能换行解决
- JavaScript 注入攻击
- Spring security防止用户重复登录
- Simple and Protected GSSAPI Negotiation Mechanism (SPNEGO)
- listview baseadapter
- img内联替换元素
- SIFT+SVM 使用Bag of Features
- 2101-view-autocomplete
- BlueTooth: 蓝牙基带数据传输机理分析