JavaPOI生成导出word(简单)

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.");
}
}

本文发布于:2024-09-24 09:19:25,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/3/380567.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:表格   添加   时间   设置   段落
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议