增加代码替换,PPT,excel文件的
This commit is contained in:
parent
03f30b7e8f
commit
9390b3580c
@ -23,6 +23,7 @@ import com.actionsoft.exception.AWSDataAccessException;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.microsoft.schemas.office.office.CTIdMap;
|
||||
import com.spire.presentation.*;
|
||||
import com.spire.presentation.drawing.FillFormatType;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
@ -40,7 +41,7 @@ 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.CTTextBody;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.awt.*;
|
||||
@ -48,10 +49,8 @@ import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class UpFileExcelAndPptController {
|
||||
@ -418,22 +417,183 @@ public class UpFileExcelAndPptController {
|
||||
model_old.setFileName("ppt版本模板"+name.substring(name.lastIndexOf(".")));
|
||||
DCContext dcContext_old = getDCContext(model_old,UserContext.fromSessionId(sid));
|
||||
String[] fileNames ={dcContext.getFilePath(),dcContext_old.getFilePath()} ;
|
||||
String mergedFileName = dcContext.getFilePath();
|
||||
String mergedFileName = dcContext.getPath()+"dc.pptx";
|
||||
|
||||
try (FileOutputStream outputStream = new FileOutputStream(mergedFileName)) {
|
||||
XMLSlideShow mergedSlideShow = new XMLSlideShow();
|
||||
|
||||
for (String fileName : fileNames) {
|
||||
XMLSlideShow slideShow = new XMLSlideShow(new FileInputStream(fileName));
|
||||
|
||||
for (XSLFSlide slide : slideShow.getSlides()) {
|
||||
mergedSlideShow.setPageSize(slideShow.getPageSize());
|
||||
XSLFSlide newSlide = mergedSlideShow.createSlide().importContent(slide);
|
||||
copyConditionalFormatting(slide, newSlide);
|
||||
copyImages(slide, newSlide);
|
||||
|
||||
}
|
||||
}
|
||||
mergedSlideShow.write(outputStream);
|
||||
mergedSlideShow.close();
|
||||
outputStream.close();
|
||||
//生成之后的数据pptx
|
||||
XMLSlideShow slideShows = new XMLSlideShow(new FileInputStream(mergedFileName));
|
||||
SDK.getLogAPI().consoleInfo("开始执行了吗");
|
||||
// 获取幻灯片列表
|
||||
List<XSLFSlide> slides = slideShows.getSlides();
|
||||
SDK.getLogAPI().consoleInfo("幻灯片的大小是多少>>>>>>>"+slides.size());
|
||||
//移动倒数第二个至第一张幻灯
|
||||
XSLFSlide secondslide = slides.get(slides.size()-2);
|
||||
slideShows.setSlideOrder(secondslide, 0);
|
||||
|
||||
PALRepositoryModel palRepositoryModel = PALRepositoryCache.getCache().get(pl_uuid);
|
||||
JSONArray versionHistoryTable = getVersionHistoryTable(palRepositoryModel);
|
||||
System.out.println("jsonArray>>>>>>>>>>"+versionHistoryTable.toString());
|
||||
|
||||
String process_name = DBSql.getString("select PLNAME from app_act_coe_pal_repository where ID = '" + pl_uuid + "'");
|
||||
for (XSLFSlide slide : slides) {
|
||||
for (XSLFShape shape : slide.getShapes()) {
|
||||
if (shape instanceof XSLFTable) {
|
||||
XSLFTable table = (XSLFTable) shape;
|
||||
for (XSLFTableRow row : table.getRows()) {
|
||||
for (XSLFTableCell cell : row.getCells()) {
|
||||
for (XSLFTextParagraph paragraph : cell.getTextParagraphs()) {
|
||||
for (XSLFTextRun textRun : paragraph.getTextRuns()) {
|
||||
String text = textRun.getRawText();
|
||||
|
||||
// 根据需要替换参数
|
||||
|
||||
String L1 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L1'");
|
||||
String L2 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L2'");
|
||||
String L3 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L3'");
|
||||
String L4 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L4'");
|
||||
String fanwei = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID in( 'application','form_Scope_application')");
|
||||
String file_number = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID IN('form_number','file_number')");
|
||||
String P_versions = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID IN('P_versions')");
|
||||
|
||||
String file_date = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID IN('effective_date','form_effective_date') ");
|
||||
|
||||
if (UtilString.isNotEmpty(P_versions)) {
|
||||
text = text.replace("{{file_version}}", P_versions);
|
||||
} else {
|
||||
text = text.replace("{{file_version}}", "");
|
||||
}
|
||||
if (UtilString.isNotEmpty(file_date)) {
|
||||
text = text.replace("{{file_data}}", file_date);
|
||||
} else {
|
||||
text = text.replace("{{file_data}}", "");
|
||||
}
|
||||
if (UtilString.isNotEmpty(file_number)) {
|
||||
|
||||
text = text.replace("{{file_code}}", file_number);
|
||||
} else {
|
||||
text = text.replace("{{file_code}}", "");
|
||||
}
|
||||
if (UtilString.isNotEmpty(fanwei)) {
|
||||
|
||||
text = text.replace("{{fanwei}}", fanwei);
|
||||
} else {
|
||||
text = text.replace("{{fanwei}}", "");
|
||||
}
|
||||
|
||||
text = text.replace("{{L1}}", L1);
|
||||
text = text.replace("{{L2}}", L2);
|
||||
text = text.replace("{{L3}}", L3);
|
||||
text = text.replace("{{L4}}", L4);
|
||||
textRun.setText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XSLFTable tables = (XSLFTable) shape;
|
||||
XSLFTableRow firstRow = tables.getRows().get(1);
|
||||
// 获取表格的第一行
|
||||
for (int i = 0; i < versionHistoryTable.size(); i++) {
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}else {
|
||||
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}}", 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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
SDK.getLogAPI().consoleInfo("asddasdasdas");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mergedSlideShow.write(outputStream);
|
||||
|
||||
// 获取PPT的第一页
|
||||
|
||||
|
||||
|
||||
// 替换文本框中的参数
|
||||
for (XSLFSlide slide : slides) {
|
||||
for (XSLFShape shape : slide.getShapes()) {
|
||||
if (shape instanceof XSLFTextShape) {
|
||||
XSLFTextShape textShape = (XSLFTextShape) shape;
|
||||
for (XSLFTextParagraph paragraph : textShape.getTextParagraphs()) {
|
||||
for (XSLFTextRun textRun : paragraph.getTextRuns()) {
|
||||
String text = textRun.getRawText();
|
||||
// 根据需要替换参数
|
||||
text = text.replace("{{process_name}}", process_name);
|
||||
textRun.setText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
XSLFSlide secondslide_last = slides.get(slides.size()-1);
|
||||
slideShows.setSlideOrder(secondslide_last, 1);
|
||||
FileOutputStream out = new FileOutputStream(dcContext.getFilePath());
|
||||
slideShows.write(out);
|
||||
slideShows.close();
|
||||
out.close();
|
||||
SDK.getLogAPI().consoleInfo("移动文件位置替换完成");
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -445,6 +605,11 @@ public class UpFileExcelAndPptController {
|
||||
}
|
||||
|
||||
|
||||
// 更新幻灯片ID列表
|
||||
// 更新幻灯片ID列表
|
||||
// 移动幻灯片位置
|
||||
// 移动幻灯片位置
|
||||
|
||||
private static void copyConditionalFormatting(XSLFSlide sourceSlide, XSLFSlide targetSlide) {
|
||||
List<XSLFShape> shapes = sourceSlide.getShapes();
|
||||
for (XSLFShape shape : shapes) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user