JavaPOI⽣成导出word(简单)该功能只是针对简单的需求导出⼀个空⽩或简单数据的word⽂件
/**
* @Title: PoiToWord.java
* @Package com.ls
* @Description: TODO(⽤⼀句话描述该⽂件做什么)
*/
package *;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
/**
* @ClassName: PoiToWord
* @Description: TODO(这⾥⽤⼀句话描述这个类的作⽤)
*
*/
public class PoiToWord {
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("C:/Users/LapTop/Desktop/create_table.docx"));
// XWPFParagraph titleParagraph = ateParagraph();
// titleParagraph.setAlignment(ParagraphAlignment.CENTER);
//
// XWPFRun titleParagraphRun = ateRun();
// titleParagraphRun.setText("Java PoI");
// titleParagraphRun.setColor("000000");
// titleParagraphRun.setFontSize(20);
//
// // 段落
// XWPFParagraph firstParagraph = ateParagraph();
/
/ XWPFRun run = ateRun();
// run.setText("Java POI ⽣成word⽂件。");
// run.setColor("696969");
msinfo// run.setFontSize(16);
//
// // 设置段落背景颜⾊
// CTShd cTShd = CTR().addNewRPr().addNewShd();
// cTShd.setVal(STShd.CLEAR);
// cTShd.setFill("97FFFF");
//
// // 换⾏
/
/ XWPFParagraph paragraph1 = ateParagraph();
// XWPFRun paragraphRun1 = ateRun();
// paragraphRun1.setText("\r");
//
// XWPFTable infoTable = ateTable();
// // 去表格边框
// CTTbl().getTblPr().unsetTblBorders();
//
// // 列宽⾃动分割
// CTTblWidth infoTableWidth = CTTbl().addNewTblPr().addNewTblW(); // infoTableWidth.setType(STTblWidth.DXA);
// infoTableWidth.setW(BigInteger.valueOf(9072));
//
// // 表格第⼀⾏
// XWPFTableRow infoTableRowOne = Row(0);
// Cell(0).setText("职位");
// infoTableRowOne.addNewTableCell().setText(": Java 开发⼯程师");
//
// // 表格第⼆⾏
// XWPFTableRow infoTableRowTwo = ateRow();
// Cell(0).setText("姓名");
// Cell(1).setText(": seawater");
/
/
// // 表格第三⾏
// XWPFTableRow infoTableRowThree = ateRow();
// Cell(0).setText("⽣⽇");
// Cell(1).setText(": xxx-xx-xx");
//
// // 表格第四⾏
// XWPFTableRow infoTableRowFour = ateRow();
// Cell(0).setText("性别");
// Cell(1).setText(": 男");
//
/
/ // 表格第五⾏
// XWPFTableRow infoTableRowFive = ateRow();
// Cell(0).setText("现居地");
// Cell(1).setText(": xx");
//
// // 两个表格之间加个换⾏
// XWPFParagraph paragraph = ateParagraph();
// XWPFRun paragraphRun = ateRun();
// paragraphRun.setText("\r");
//
// // ⼯作经历表格
/
/ XWPFTable ComTable = ateTable();
//
// // 列宽⾃动分割
// CTTblWidth comTableWidth = CTTbl().addNewTblPr().addNewTblW(); // comTableWidth.setType(STTblWidth.DXA);
// comTableWidth.setW(BigInteger.valueOf(9072));
//
// // 表格第⼀⾏
// XWPFTableRow comTableRowOne = Row(0);
// Cell(0).setText("开始时间"); // comTableRowOne.addNewTableCell().setText("结束时间");
// comTableRowOne.addNewTableCell().setText("公司名称");
// comTableRowOne.addNewTableCell().setText("title");
//
// // 表格第⼆⾏
// XWPFTableRow comTableRowTwo = ateRow();
// Cell(0).setText("2016-09-06");
// Cell(1).setText("⾄今");
// Cell(2).setText("seawater");
// Cell(3).setText("Java开发⼯程师");
//
// // 表格第三⾏
// XWPFTableRow comTableRowThree = ateRow();
/
/ Cell(0).setText("2016-09-06");
// Cell(1).setText("⾄今");
// Cell(2).setText("seawater");
// Cell(3).setText("Java开发⼯程师");
//
// CTSectPr sectPr = Document().getBody().addNewSectPr();
// XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);
// 添加页眉
// CTP ctpHeader = wInstance();
// CTR ctrHeader = ctpHeader.addNewR();
// CTText ctHeader = ctrHeader.addNewT();
/
/ String headerText = "Java POI create MS word file.";
// ctHeader.setStringValue(headerText);
// XWPFParagraph headerParagraph = new XWPFParagraph(ctpHeader, document); // // 设置为右对齐
// headerParagraph.setAlignment(ParagraphAlignment.RIGHT);
// XWPFParagraph[] parsHeader = new XWPFParagraph[1];
// parsHeader[0] = headerParagraph;
// ateHeader(XWPFHeaderFooterPolicy.DEFAULT, parsHeader);
//
// // 添加页脚
// CTP ctpFooter = wInstance();
// CTR ctrFooter = ctpFooter.addNewR();
// CTText ctFooter = ctrFooter.addNewT();
// String footerText = "umishu/";
// ctFooter.setStringValue(footerText);
// XWPFParagraph footerParagraph = new XWPFParagraph(ctpFooter, document); // headerParagraph.setAlignment(ParagraphAlignment.CENTER);
// XWPFParagraph[] parsFooter = new XWPFParagraph[1];
// parsFooter[0] = footerParagraph;
// ateFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);
document.write(out);
out.close();
System.out.println("create_table document written success.");
}
}