W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
這里術(shù)語“document"是指MS-Word文件。 閱讀完本章后,您將能夠使用Java程序創(chuàng)建新文檔并打開現(xiàn)有文檔。
以下簡(jiǎn)單程序用于創(chuàng)建空白MS-Word文檔:
import java.io.File; import java.io.FileOutputStream; import org.apache.poi.xwpf.usermodel.XWPFDocument; public class CreateDocument { public static void main(String[] args)throws Exception { //Blank Document XWPFDocument document= new XWPFDocument(); //Write the Document in file system FileOutputStream out = new FileOutputStream( new File("createdocument.docx")); document.write(out); out.close(); System.out.println( "createdocument.docx written successully"); } }
將上述Java代碼保存為CreateDocument.java,然后從命令提示符處編譯并執(zhí)行它,如下所示:
$javac CreateDocument.java $java CreateDocument
如果您的系統(tǒng)環(huán)境配置有POI庫,它將編譯并執(zhí)行,以在當(dāng)前目錄中生成名為createdocument.docx的空Excel文件,并在命令提示符中顯示以下輸出:
createdocument.docx written successfully
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: