个人记录使用
1.表格居中与左对齐缩进二选一
2.边框设置可参考 POI 设置Word表格边框、表格文字水平居中
package com.gsafety.anjian.analysis.util;
/**
* 设置poi-tl生成嵌套子模板中的表格垂直居中
*
*/
import com.deepoove.poi.NiceXWPFDocument;
import com.deepoove.poi.XWPFTemplate;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class PoilUtil {
private static String notpath = "/evn_ets_rescueprogramme/moduleflag-1/";
public static void setExcelVertical(XWPFTemplate template, String dirPath) {
NiceXWPFDocument document = template.getXWPFDocument();
List<XWPFTable> tables = document.getTables();
if (tables!=null && tables.size()>1) {
for (int z = 1; z < tables.size(); z++) {
XWPFTable table = tables.get(z);
CTTblLayoutType type = table.getCTTbl().getTblPr().addNewTblLayout();
type.setType(STTblLayoutType.FIXED);
//设置表格居中
CTJc jc = table.getCTTbl().getTblPr().getJc();
if(jc == null){
jc = table.getCTTbl().getTblPr().addNewJc();
}
jc.setVal(STJc.CENTER);
table.getCTTbl().getTblPr().setJc(jc);
//设置表格左对齐缩进
/*CTTblWidth tblInd = table.getCTTbl().getTblPr().getTblInd();
if(null == tblInd){
tblInd = table.getCTTbl().getTblPr().addNewTblInd();
}
//缩进距离