记录一下利用POI导出简单word过程,有合并单元格和设置单元格居中,这里的设置单元格居中,是遍历每一个单元格,都设置成居中
public XWPFDocument exportWord(Object obj) {
// 封装数据
List<GasExportVo> exportWordList = makeData(obj);
// 导出表格
XWPFDocument xwpfDocument = new XWPFDocument();
FileOutputStream out;
try {
String wordName = "数据统计";
FileUtils.createDirectory(config.getFilePath() + "/gas/");
//添加标题
XWPFParagraph titleParagraph = xwpfDocument.createParagraph();
//设置段落居中
titleParagraph.setAlignment(ParagraphAlignment.CENTER);
// 设置标题
XWPFRun titleParagraphRun = titleParagraph.createRun();
titleParagraphRun.setText(wordName);
titleParagraphRun.setColor("000000");
titleParagraphRun.setFontSize(20);
// 创建表格
XWPFTable table =