这个是更新excel中的扩展为xls文件的修改
This commit is contained in:
parent
efd81e5eb5
commit
47cce5d933
@ -74,7 +74,7 @@ public class UpFileExcelAndPptController {
|
|||||||
// model.setFileType(fileType);
|
// model.setFileType(fileType);
|
||||||
model.setFileName(name);
|
model.setFileName(name);
|
||||||
DCContext dcContext = getDCContext(model,UserContext.fromSessionId(sid));
|
DCContext dcContext = getDCContext(model,UserContext.fromSessionId(sid));
|
||||||
if (name.contains(".xlsx")||name.contains(".xls")){
|
if (name.endsWith(".xlsx")||name.endsWith(".xls")){
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//d1d4b52a-d6e2-4a6f-acac-37e07d2ae6e5
|
//d1d4b52a-d6e2-4a6f-acac-37e07d2ae6e5
|
||||||
@ -86,7 +86,7 @@ public class UpFileExcelAndPptController {
|
|||||||
model_old.setCreateUser(UserContext.fromSessionId(sid).getUID());
|
model_old.setCreateUser(UserContext.fromSessionId(sid).getUID());
|
||||||
model_old.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
model_old.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
||||||
model_old.setType("s");
|
model_old.setType("s");
|
||||||
model_old.setFileName("制度文件模版.xlsx");
|
model_old.setFileName("制度文件模版"+name.substring(name.lastIndexOf(".")));
|
||||||
DCContext dcContext_old = getDCContext(model_old,UserContext.fromSessionId(sid));
|
DCContext dcContext_old = getDCContext(model_old,UserContext.fromSessionId(sid));
|
||||||
// 读取模版文件的Excel文件
|
// 读取模版文件的Excel文件
|
||||||
String[] filePaths = {dcContext.getFilePath(),
|
String[] filePaths = {dcContext.getFilePath(),
|
||||||
@ -101,6 +101,7 @@ public class UpFileExcelAndPptController {
|
|||||||
String path = dcContext.getPath();
|
String path = dcContext.getPath();
|
||||||
String fileName = name;
|
String fileName = name;
|
||||||
|
|
||||||
|
if (name.contains(".xlsx")){
|
||||||
Utils.mergeExcel(list, path, fileName);
|
Utils.mergeExcel(list, path, fileName);
|
||||||
FileInputStream file = new FileInputStream(new File(dcContext.getFilePath()));
|
FileInputStream file = new FileInputStream(new File(dcContext.getFilePath()));
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook(file);
|
XSSFWorkbook workbook = new XSSFWorkbook(file);
|
||||||
@ -242,6 +243,149 @@ public class UpFileExcelAndPptController {
|
|||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}else {
|
||||||
|
HSSFUtils.mergeExcel(list, path, fileName);
|
||||||
|
FileInputStream file = new FileInputStream(new File(dcContext.getFilePath()));
|
||||||
|
HSSFWorkbook workbook = new HSSFWorkbook(file);
|
||||||
|
// FileInputStream file2 = new FileInputStream(new File(dcContext.getFilePath()));
|
||||||
|
// XSSFWorkbook workbook2 = new XSSFWorkbook(file2);
|
||||||
|
// 创建两个新的Sheet页
|
||||||
|
// Sheet sheet1 = workbook.createSheet("封面");
|
||||||
|
// Sheet sheet2 = workbook.createSheet("修订记录");
|
||||||
|
workbook.setSheetOrder("封面",0);
|
||||||
|
workbook.setSheetOrder("修订记录",1);
|
||||||
|
// 向新Sheet页中填充数据
|
||||||
|
// fillData(sheet1);
|
||||||
|
// fillData(sheet2);
|
||||||
|
|
||||||
|
// 保存修改后的Excel文件
|
||||||
|
// FileOutputStream outputStream = new FileOutputStream(dcContext.getFilePath());
|
||||||
|
// workbook.write(outputStream);
|
||||||
|
// workbook.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 获取指定的 sheet 页
|
||||||
|
HSSFSheet sheet = workbook.getSheet("封面");
|
||||||
|
|
||||||
|
// 查找并替换参数
|
||||||
|
//这个是替换文件编码
|
||||||
|
String file_number = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'file_number'");
|
||||||
|
if (StringUtils.isEmpty(file_number)){
|
||||||
|
replaceParameter(sheet, "{{file_code}}", "");
|
||||||
|
}else {
|
||||||
|
|
||||||
|
replaceParameter(sheet, "{{file_code}}", file_number);
|
||||||
|
}
|
||||||
|
//这个是替换生效日期
|
||||||
|
String file_date = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'effective_date'");
|
||||||
|
if (UtilString.isNotEmpty(file_date)){
|
||||||
|
|
||||||
|
replaceParameter(sheet, "{{file_date}}", file_date);
|
||||||
|
}else {
|
||||||
|
replaceParameter(sheet, "{{file_date}}", "");
|
||||||
|
}
|
||||||
|
//这个是替换适用范围
|
||||||
|
String fanwei = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'application'");
|
||||||
|
if (UtilString.isNotEmpty(fanwei)){
|
||||||
|
|
||||||
|
replaceParameter(sheet, "{{fanwei}}", fanwei);
|
||||||
|
}else {
|
||||||
|
replaceParameter(sheet, "{{fanwei}}", "");
|
||||||
|
}
|
||||||
|
//这个是替换L1-L4
|
||||||
|
String L1 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L1'");
|
||||||
|
replaceParameter(sheet, "{{L1}}", L1);
|
||||||
|
String L2 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L2'");
|
||||||
|
replaceParameter(sheet, "{{L2}}", L2);
|
||||||
|
String L3 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L3'");
|
||||||
|
replaceParameter(sheet, "{{L3}}", L3);
|
||||||
|
String L4 = DBSql.getString("select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '" + pl_uuid + "' and PROPERTYID = 'Process_Architecture_L4'");
|
||||||
|
replaceParameter(sheet, "{{L4}}", L4);
|
||||||
|
//这个是替换流程名称
|
||||||
|
String process_name = DBSql.getString("select PLNAME from app_act_coe_pal_repository where ID = '" + pl_uuid + "'");
|
||||||
|
replaceParameter(sheet, "{{process_name}}", process_name);
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
|
||||||
|
HSSFSheet sheet_xd = workbook.getSheet("修订记录");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 获取参数所在的行和列
|
||||||
|
int parameterRow = 3; // 假设参数在第二行
|
||||||
|
int parameterCol = 0; // 假设参数在第一列
|
||||||
|
|
||||||
|
// 获取数据起始行
|
||||||
|
int dataStartRow = 3; // 假设数据从第四行开始
|
||||||
|
|
||||||
|
// 定义要替换的参数数组
|
||||||
|
String[] parameters = {"{{number}}", "{{version}}", "{{company}}","{{creauser}}","{{date}}","{{shen_user}}","{{fuhe_user}}","{{shenpi_user}}","{{person}}"};
|
||||||
|
|
||||||
|
/*// 定义要插入的数据数组
|
||||||
|
String[][] data = {
|
||||||
|
{"John Doe", "30", "New York"},
|
||||||
|
{"Jane Smith", "25", "London"},
|
||||||
|
{"Michael Johnson", "40", "Sydney"}
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
PALRepositoryModel palRepositoryModel = PALRepositoryCache.getCache().get(pl_uuid);
|
||||||
|
JSONArray versionHistoryTable = getVersionHistoryTable(palRepositoryModel);
|
||||||
|
String[][] strArray2 = new String[versionHistoryTable.size()][];
|
||||||
|
System.out.println("jsonArray>>>>>>>>>>"+versionHistoryTable.toString());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [{"approver":"任国梁","Drafted_and_revised_date":"2023年5月08日"
|
||||||
|
* ,"auditor":"杜薇","Issuing_department":"总部金融中心经营管理办公室",
|
||||||
|
* "reviewer":"/","Contents_and_reasons_for_revision":"新增","P_versions":"V1.0","Drafted_and_revised_by":"赵苗"}]
|
||||||
|
*/
|
||||||
|
List<String[]> lists = new LinkedList<>();
|
||||||
|
for (int i = 0; i < versionHistoryTable.size(); i++) {
|
||||||
|
JSONObject obj2 = versionHistoryTable.getJSONObject(i);
|
||||||
|
String[] strArray = new String[9];
|
||||||
|
strArray[0] = String.valueOf(i+1);
|
||||||
|
strArray[1] = obj2.getString("P_versions");
|
||||||
|
strArray[2] = obj2.getString("Issuing_department");
|
||||||
|
strArray[3] = obj2.getString("Drafted_and_revised_by");
|
||||||
|
strArray[4] = obj2.getString("Drafted_and_revised_date");
|
||||||
|
strArray[5] = obj2.getString("auditor");
|
||||||
|
strArray[6] = obj2.getString("reviewer");
|
||||||
|
strArray[7] = obj2.getString("approver");
|
||||||
|
strArray[8] = obj2.getString("Contents_and_reasons_for_revision");
|
||||||
|
lists.add(strArray);
|
||||||
|
strArray2[i] = strArray;
|
||||||
|
}
|
||||||
|
String[][] datas = strArray2;
|
||||||
|
|
||||||
|
// 循环替换参数
|
||||||
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
|
String parameter = parameters[i];
|
||||||
|
String replacement = datas[0][i];
|
||||||
|
|
||||||
|
replaceParameter(sheet_xd, parameter, replacement, parameterRow, parameterCol);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 循环插入数据
|
||||||
|
for (int i = 0; i < datas.length; i++) {
|
||||||
|
insertData(sheet_xd, datas[i], dataStartRow + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 保存修改后的 Excel 文件
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(dcContext.getFilePath());
|
||||||
|
workbook.write(outputStream);
|
||||||
|
workbook.close();
|
||||||
|
outputStream.close();
|
||||||
|
|
||||||
|
System.out.println("封面参数替换完成!");
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user