導航:首頁 > 編程語言 > 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亂碼相關的資料

熱點內容
注冊伺服器地址指什麼 瀏覽:431
文本命令行 瀏覽:95
撲克牌睡眠解壓 瀏覽:190
rc4演算法流程圖 瀏覽:157
胡蘿卜解壓方法 瀏覽:35
掃描pdf格式軟體 瀏覽:876
程序員在銀行開賬戶 瀏覽:516
android資料庫下載 瀏覽:749
中午伺服器崩潰怎麼辦 瀏覽:425
產品經理和程序員待遇 瀏覽:442
解憂程序員免費閱讀 瀏覽:109
錄像免壓縮 瀏覽:508
總結所學過的簡便演算法 瀏覽:362
南昌哪些地方需要程序員 瀏覽:761
三台伺服器配置IP地址 瀏覽:175
如何用命令方塊連續對話 瀏覽:280
win7linux共享文件夾 瀏覽:304
命令符打開本地服務 瀏覽:601
android應用程序源碼 瀏覽:705
安卓開發工程師簡歷怎麼寫 瀏覽:63