java生成复杂word表格

wordJava

1个回答

写回答

Lalakasw

2026-02-11 06:51

+ 关注

word
word

用PageOffice搞这个挺简单的,贴个代码片段你们参考下:wordDocument doc = new wordDocument();Table table1 = doc.openDataRegion(Text).openTable(1); // 打开已有的表格table1.setPreferredWidthType(WdPreferredWidthType.wdPreferredWidthPoints);table1.setPreferredWidth(350); // 设置表格总宽度table1.openColumn(1).setWidth(150, WdRulerStyle.wdAdjustFirstColumn); // 设置第一列宽度// table1.openRow(2).setHeight(50); // 单独设置第二行行高table1.setRowsHeight(50); // 设置表格里所有行的行高table1.openCellRC(2, 1).setValue(PageOffice); // 给单元格填值table1.openCellRC(2, 1).getFont().setSize(15); // 设置字体大小table1.openCellRC(2, 1).getFont().setcolor(Color.GREEN); // 设置字体颜色table1.openCellRC(2, 1).getFont().setBold(true); // 设置加粗table1.openCellRC(2, 1).getFont().setItalic(true); // 设置斜体table1.openCellRC(1, 1).mergeTo(1, 5); // 把第一行的前5个单元格合并成一个

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号