pptx文件表格样式缺失修复

This commit is contained in:
Mr-wang 2023-07-27 14:31:31 +08:00
parent 90d105bc3e
commit d5bed8f8fe

View File

@ -45,6 +45,8 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableProperties;
import org.openxmlformats.schemas.presentationml.x2006.main.*;
import org.springframework.util.StringUtils;
@ -455,6 +457,7 @@ public class UpFileExcelAndPptController {
System.out.println("jsonArray>>>>>>>>>>"+versionHistoryTable.toString());
String process_name = DBSql.getString("select PLNAME from app_act_coe_pal_repository where ID = '" + pl_uuid + "'");
int q = 0;
for (XSLFSlide slide : slides) {
for (XSLFShape shape : slide.getShapes()) {
if (shape instanceof XSLFTable) {
@ -510,82 +513,83 @@ public class UpFileExcelAndPptController {
}
}
if (q!=0) {
XSLFTable tables = (XSLFTable) shape;
XSLFTable tables = (XSLFTable) shape;
XSLFTableRow firstRow = tables.getRows().get(1);
XSLFTableRow firstRow = tables.getRows().get(1);
// 获取表格的第一行
for (int i = 1; i < versionHistoryTable.size(); i++) {
XSLFTableRow newRow = table.addRow();
for (int col = 0; col < firstRow.getCells().size(); col++) {
XSLFTableCell cell = firstRow.getCells().get(col);
XSLFTableCell newCell = newRow.addCell();
newCell.setText(cell.getText());
newCell.setFillColor(cell.getFillColor());
newCell.setBorderColor(XSLFTableCell.BorderEdge.bottom, cell.getBorderColor(XSLFTableCell.BorderEdge.bottom));
newCell.setBorderColor(XSLFTableCell.BorderEdge.top, cell.getBorderColor(XSLFTableCell.BorderEdge.top));
newCell.setBorderColor(XSLFTableCell.BorderEdge.left, cell.getBorderColor(XSLFTableCell.BorderEdge.left));
newCell.setBorderColor(XSLFTableCell.BorderEdge.right, cell.getBorderColor(XSLFTableCell.BorderEdge.right));
newCell.setBorderWidth(XSLFTableCell.BorderEdge.bottom, cell.getBorderWidth(XSLFTableCell.BorderEdge.bottom));
newCell.setBorderWidth(XSLFTableCell.BorderEdge.top, cell.getBorderWidth(XSLFTableCell.BorderEdge.top));
newCell.setBorderWidth(XSLFTableCell.BorderEdge.left, cell.getBorderWidth(XSLFTableCell.BorderEdge.left));
newCell.setBorderWidth(XSLFTableCell.BorderEdge.right, cell.getBorderWidth(XSLFTableCell.BorderEdge.right));
newCell.setVerticalAlignment(cell.getVerticalAlignment());
newCell.setHorizontalCentered(cell.isHorizontalCentered());
newCell.setLeftInset(cell.getLeftInset());
newCell.setRightInset(cell.getRightInset());
newCell.setTopInset(cell.getTopInset());
newCell.setBottomInset(cell.getBottomInset());
}
}
for (int i = 0; i < versionHistoryTable.size(); i++) {
if(versionHistoryTable.size()==1){
JSONObject obj2 = versionHistoryTable.getJSONObject(0);
for (int col = 0; col < firstRow.getCells().size(); col++) {
XSLFTableCell cell = firstRow.getCells().get(col);
String text = cell.getText();
JSONObject obj2 = versionHistoryTable.getJSONObject(i);
// 替换参数
if (i == 0) {
for (int col = 0; col < firstRow.getCells().size(); col++) {
XSLFTableCell cell = firstRow.getCells().get(col);
String text = cell.getText();
text = text.replace("{{version}}", obj2.getString("P_versions"));
text = text.replace("{{company}}", obj2.getString("Issuing_department"));
text = text.replace("{{creauser}}", obj2.getString("Drafted_and_revised_by"));
text = text.replace("{{date}}", obj2.getString("Drafted_and_revised_date"));
text = text.replace("{{shen_user}}",obj2.getString("auditor") );
text = text.replace("{{fuhe_user}}", obj2.getString("reviewer"));
text = text.replace("{{shenpi_user}}", obj2.getString("approver"));
text = text.replace("{{person}}", obj2.getString("Contents_and_reasons_for_revision"));
cell.setText(text);
text = text.replace("{{version}}", obj2.getString("P_versions"));
text = text.replace("{{company}}", obj2.getString("Issuing_department"));
text = text.replace("{{creauser}}", obj2.getString("Drafted_and_revised_by"));
text = text.replace("{{date}}", obj2.getString("Drafted_and_revised_date"));
text = text.replace("{{shen_user}}", obj2.getString("auditor"));
text = text.replace("{{fuhe_user}}", obj2.getString("reviewer"));
text = text.replace("{{shenpi_user}}", obj2.getString("approver"));
text = text.replace("{{person}}", obj2.getString("Contents_and_reasons_for_revision"));
cell.setText(text);
}
}else {
}
} else {
System.out.println("版本2的时候怎么不进");
XSLFTableRow newRow = table.getRows().get(i+1);
for (int col = 0; col < newRow.getCells().size(); col++) {
XSLFTableCell cell = newRow.getCells().get(col);
String text = cell.getText();
text = text.replace("{{version}}", obj2.getString("P_versions"));
text = text.replace("{{company}}", obj2.getString("Issuing_department"));
text = text.replace("{{creauser}}", obj2.getString("Drafted_and_revised_by"));
text = text.replace("{{date}}", obj2.getString("Drafted_and_revised_date"));
text = text.replace("{{shen_user}}", obj2.getString("auditor"));
text = text.replace("{{fuhe_user}}", obj2.getString("reviewer"));
text = text.replace("{{shenpi_user}}", obj2.getString("approver"));
text = text.replace("{{person}}", obj2.getString("Contents_and_reasons_for_revision"));
cell.setText(text);
JSONObject obj2 = versionHistoryTable.getJSONObject(0);
for (int col = 0; col < firstRow.getCells().size(); col++) {
XSLFTableCell cell = firstRow.getCells().get(col);
String text = cell.getText();
}
}
text = text.replace("{{version}}", obj2.getString("P_versions"));
text = text.replace("{{company}}", obj2.getString("Issuing_department"));
text = text.replace("{{creauser}}", obj2.getString("Drafted_and_revised_by"));
text = text.replace("{{date}}", obj2.getString("Drafted_and_revised_date"));
text = text.replace("{{shen_user}}",obj2.getString("auditor") );
text = text.replace("{{fuhe_user}}", obj2.getString("reviewer"));
text = text.replace("{{shenpi_user}}", obj2.getString("approver"));
text = text.replace("{{person}}", obj2.getString("Contents_and_reasons_for_revision"));
cell.setText(text);
}
for (int i =1; i < versionHistoryTable.size(); i++) {
JSONObject obj = versionHistoryTable.getJSONObject(i);
// 替换参数
XSLFTableRow newRow = table.addRow();
// 复制单元格
for (int col = 0; col < firstRow.getCells().size(); col++) {
XSLFTableCell cell = firstRow.getCells().get(col);
XSLFTableCell newCell = newRow.addCell();
newCell.setText(cell.getText());
}
for (int col = 0; col < newRow.getCells().size(); col++) {
XSLFTableCell cell = newRow.getCells().get(col);
String text = cell.getText();
text = text.replace("{{version}}", obj.getString("P_versions"));
text = text.replace("{{company}}", obj.getString("Issuing_department"));
text = text.replace("{{creauser}}", obj.getString("Drafted_and_revised_by"));
text = text.replace("{{date}}", obj.getString("Drafted_and_revised_date"));
text = text.replace("{{shen_user}}",obj.getString("auditor") );
text = text.replace("{{fuhe_user}}", obj.getString("reviewer"));
text = text.replace("{{shenpi_user}}", obj.getString("approver"));
text = text.replace("{{person}}", obj.getString("Contents_and_reasons_for_revision"));
cell.setText(text);
}
}
}
// 获取表格的第一行
}
}
SDK.getLogAPI().consoleInfo("asddasdasdas");
}
}
q++;
}