poi word 表格设置居中、左对齐缩进、边框、字体

这篇博客主要介绍了如何在Java中利用POI库来操作Word表格,包括设置表格内容居中、左对齐缩进以及添加边框。作者提到了在使用POI-tl模板引擎时的依赖,并且指出为了实现完整的双边框样式,需要注意左右上角和右下角边框样式的匹配问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 个人记录使用

        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();
                }
                //缩进距离
           
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值