处理修订记录在WPS样式问题

This commit is contained in:
zhaol 2025-05-22 11:41:00 +08:00
parent 203b17ca46
commit 672dbc5807
2 changed files with 11 additions and 14 deletions

View File

@ -595,18 +595,22 @@ public class OutputWordUtil {
//添加表格
Table table = section.addTable(true);
table.getTableFormat().setHorizontalAlignment(RowAlignment.Center);
table.resetCells(data.length + 1, header.length);
table.autoFit(AutoFitBehaviorType.Fixed_Column_Widths);
table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window);
TableRow row = table.getRows().get(0);
row.isHeader(true);
row.setHeightType(TableRowHeightType.Exactly);
float[] columnWidths = {10f,15f,12f,15f,12f,12f,12f,25f};
table.setPreferredWidth(new PreferredWidth(WidthType.Twip, (short) 8335f));
float[] columnWidths = {10f,17f,13f,17f,13f,13f,13f,25f};
// 设置列宽
for (int i = 0; i < columnWidths.length; i++) {
row.getCells().get(i).setWidth(columnWidths[i]);
row.getCells().get(i).setCellWidthType(CellWidthType.Percentage);
}
@ -614,19 +618,17 @@ public class OutputWordUtil {
row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
Paragraph p = row.getCells().get(i).addParagraph();
p.getFormat().setHorizontalAlignment(Center);
TextRange txtRange = p.appendText(header[i]);
txtRange.getCharacterFormat().setBold(true);
txtRange.getCharacterFormat().setFontName("宋体");
txtRange.getCharacterFormat().setFontSize(10.5f);
p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
}
//将数据添加到其余行
for (int r = 0; r < data.length; r++) {
TableRow dataRow = table.getRows().get(r + 1);
@ -644,9 +646,6 @@ public class OutputWordUtil {
text.getCharacterFormat().setFontSize(10.5f);
// 设置列宽
for (int i = 0; i < columnWidths.length; i++) {
row.getCells().get(i).setWidth(columnWidths[i]);
@ -654,20 +653,18 @@ public class OutputWordUtil {
}
}
}
//遍历表格单元格
for (int i = 0;i< table.getRows().getCount();i++) {
for (int i = 0;i< table.getRows().getCount();i++) {
TableRow rows = table.getRows().get(i);
for (int j = 0; j< rows.getCells().getCount(); j++){
for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){
Paragraph p = rows.getCells().get(j).getParagraphs().get(z);
p.getFormat().setLineSpacing(12f);//设置边距为1.0
p.getFormat().setHorizontalAlignment(Left);
p.getFormat().setHorizontalAlignment(Center);
}
}
}
@ -1080,7 +1077,7 @@ public class OutputWordUtil {
for (int r = 0; r < data.length; r++) {
TableRow dataRow = table.getRows().get(r + 1);
//dataRow.setHeight(25);
dataRow.setHeightType(TableRowHeightType.Auto);
//dataRow.setHeightType(TableRowHeightType.Auto);
dataRow.getRowFormat().setBackColor(Color.white);
for (int c = 0; c < data[r].length; c++) {