导航:首页 > 编程语言 > java读取word乱码

java读取word乱码

发布时间:2022-07-01 22:22:59

java使用POI读写word 乱码



public static void main(String args[])
throws Exception
{
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p1 = doc.createParagraph();
p1.setAlignment(ParagraphAlignment.CENTER);
p1.setBorderBottom(Borders.DOUBLE);
p1.setBorderTop(Borders.DOUBLE);
p1.setBorderRight(Borders.DOUBLE);
p1.setBorderLeft(Borders.DOUBLE);
p1.setBorderBetween(Borders.SINGLE);
p1.setVerticalAlignment(TextAlignment.TOP);
XWPFRun r1 = p1.createRun();
r1.setBold(true);
r1.setText("The quick brown fox");
r1.setBold(true);
r1.setFontFamily("Courier");
r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
r1.setTextPosition(100);
XWPFParagraph p2 = doc.createParagraph();
p2.setAlignment(ParagraphAlignment.RIGHT);
p2.setBorderBottom(Borders.DOUBLE);
p2.setBorderTop(Borders.DOUBLE);
p2.setBorderRight(Borders.DOUBLE);
p2.setBorderLeft(Borders.DOUBLE);
p2.setBorderBetween(Borders.SINGLE);
XWPFRun r2 = p2.createRun();
r2.setText("jumped over the lazy dog");
r2.setStrike(true);
r2.setFontSize(20);
XWPFRun r3 = p2.createRun();
r3.setText("and went away");
r3.setStrike(true);
r3.setFontSize(20);
r3.setSubscript(VerticalAlign.SUPERSCRIPT);
XWPFParagraph p3 = doc.createParagraph();
p3.setWordWrap(true);
p3.setPageBreak(true);
p3.setAlignment(ParagraphAlignment.BOTH);
p3.setSpacingLineRule(LineSpacingRule.EXACT);
p3.setIndentationFirstLine(600);
XWPFRun r4 = p3.createRun();
r4.setTextPosition(20);
r4.setText("To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; ");
r4.addBreak(BreakType.PAGE);
r4.setText("No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream: ay, there's the rub; .......");
r4.setItalic(true);
XWPFRun r5 = p3.createRun();
r5.setTextPosition(-10);
r5.setText("For in that sleep of death what dreams may come");
r5.addCarriageReturn();
r5.setText("When we have shuffled off this mortal coil,Must give us pause: there's the respectThat makes calamity of so long life;");
r5.addBreak();
r5.setText("For who would bear the whips and scorns of time,The oppressor's wrong, the proud man's contumely,");
r5.addBreak(BreakClear.ALL);
r5.setText("The pangs of despised love, the law's delay,The insolence of office and the spurns.......");
FileOutputStream out = new FileOutputStream("simple.docx");
doc.write(out);
out.close();
}

㈡ 请问java中用jacob将html转word中文乱码怎么解决

有中文乱码一般都是字符编码的问题,那你就是设置一下字符编码看看能不能解决这个问题。

㈢ JAVA读写文件,如何避免中文乱码

1、你要将所有的文件的编码都设置成UTF-8,还有,你的MyEclipse或者Eclipse应该配置jsp还有java文件还有项目都设置为UTF-8.
2、eclipse 中使用模板新建 JSP,xhtml等 文件时,默认的编码为:ISO-8859-1。 ISO-8859-1 编码对于中文的显示是不支持的,如果要支持简体中文,则编码方式应为 GBK 或者 GB2312 或者 UTF-8(推荐) 等。右键菜单栏window --> preferences --> 在type filter text中输入jsp; --> 选择下面的jsp -> 选择creating files组中的encoding 为UTF-8编码就可以了
如果要使新建立工程、java文件直接使UTF-8则需要做以下工作: 
1、windows->Preferences...打开"首选项"对话框,左侧导航树,导航到general->Workspace,右侧 Text file encoding,选择Other,改变为UTF-8,以后新建立工程其属性对话框中的Text file encoding即为UTF-8。
2、windows->Preferences...打开"首选项"对话框,左侧导航树,导航到general->Content Types,右侧Context Types树,点开Text,选择Java Source File,在下面的Default encoding输入框中输入UTF-8,点Update,则设置Java文件编码为UTF-8。其他java应用开发相关的文件 如:properties、XML等已经由Eclipse缺省指定,分别为ISO8859-1,UTF-8,如开发中确需改变编码格式则可以在此指定。

阅读全文

与java读取word乱码相关的资料

热点内容
云服务器建设原理 浏览:256
javajunit4for 浏览:843
华为服务器如何进阵列卡配置 浏览:433
apache服务器ip地址访问 浏览:718
如何买到安卓手机预装软件 浏览:537
冤罪百度云不要压缩 浏览:85
苏州云存储服务器 浏览:173
解压收纳原声 浏览:384
java注册验证 浏览:374
火花app怎么上推荐 浏览:980
什么app能游戏投屏到电视上 浏览:455
服务器托管到云端是什么意思 浏览:835
app保存草稿怎么用 浏览:808
安卓如何进入proumb 浏览:144
主机虚拟云服务器 浏览:619
删除分区加密的空间会不会恢复 浏览:706
京东app客户上门怎么看搜索量 浏览:741
怎么在农行app购买黄金 浏览:46
c型开发板和单片机 浏览:146
虚拟机建立用户的模板文件夹 浏览:904