发布生成手册\根据页面方向复制页眉页脚问题
This commit is contained in:
parent
4b05df7bc5
commit
d11a4a3dca
Binary file not shown.
@ -3682,4 +3682,20 @@ public class CoEPALController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量创建流程手册
|
||||
*
|
||||
* @param me
|
||||
* @param uuids
|
||||
* @param teamId
|
||||
* @param wsId
|
||||
* @return
|
||||
*/
|
||||
@Mapping("com.actionsoft.apps.coe.pal.publisher_output_pr_reports_create")
|
||||
public String createOutputPrReports(UserContext me, String uuids, String teamId, String wsId) {
|
||||
DesignerRelationShapeWeb web = new DesignerRelationShapeWeb(me);
|
||||
return web.createOutputPrReports(wsId, teamId, uuids);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -311,6 +311,7 @@ public class OutputWordUtil {
|
||||
String path = dcContextpdf.getPath();
|
||||
String fileName = dcContextpdf.getFileName();
|
||||
|
||||
|
||||
//创建 Document 类的对象并从磁盘加载 Word 文档
|
||||
Document document = new Document(outFile.getPath());
|
||||
|
||||
@ -335,7 +336,7 @@ public class OutputWordUtil {
|
||||
}
|
||||
|
||||
//创建实例,加载xml测试文档
|
||||
com.sini.com.spire.doc.Document doc = new com.sini.com.spire.doc.Document();
|
||||
Document doc = new Document();
|
||||
doc.loadFromFile(docPath + fileName);
|
||||
|
||||
//保存为xml格式
|
||||
@ -343,6 +344,7 @@ public class OutputWordUtil {
|
||||
//保存为Word
|
||||
doc.saveToFile(docPath + substring + ".docx", FileFormat.Docx);//支持.doc
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -355,61 +357,98 @@ public class OutputWordUtil {
|
||||
document.insertTextFromFile(path + fileName, FileFormat.Docx_2013);
|
||||
}
|
||||
// document.insertTextFromFile("/Users/sunlh/Downloads/手册格式问题测试文档(3)new.docx", FileFormat.Docx_2013);
|
||||
//保存结果文档
|
||||
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
try {
|
||||
//保存结果文档
|
||||
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
|
||||
|
||||
//加载文档1
|
||||
com.sini.com.spire.doc.Document doc1 = new com.sini.com.spire.doc.Document();
|
||||
doc1.loadFromFile(tempPath + "制度-手册5.doc");
|
||||
|
||||
|
||||
//获取section
|
||||
Section section1 = doc1.getSections().get(0);
|
||||
|
||||
//获取文档1的页眉页脚
|
||||
HeaderFooter headerword = section1.getHeadersFooters().getHeader();
|
||||
HeaderFooter footerword = section1.getHeadersFooters().getFooter();
|
||||
|
||||
//加载文档2
|
||||
com.sini.com.spire.doc.Document doc2 = new com.sini.com.spire.doc.Document();
|
||||
|
||||
|
||||
doc2.loadFromFile(outFile.getPath());
|
||||
|
||||
|
||||
SectionCollection sections = doc2.getSections();
|
||||
|
||||
|
||||
// 获取源文档的页眉页脚
|
||||
Section sourceSection = doc1.getSections().get(0);
|
||||
HeaderFooter sourceHeader = sourceSection.getHeadersFooters().getHeader();
|
||||
HeaderFooter sourceFooter = sourceSection.getHeadersFooters().getFooter();
|
||||
|
||||
// 将页眉复制到目标文档的第三节以及后续节
|
||||
for (int i = 2; i < doc2.getSections().getCount(); i++) {
|
||||
Section targetSection = doc2.getSections().get(i);
|
||||
HeaderFooter targetHeader = targetSection.getHeadersFooters().getHeader();
|
||||
targetHeader.getChildObjects().clear();
|
||||
for (int j = 0; j < sourceHeader.getChildObjects().getCount(); j++) {
|
||||
DocumentObject obj = sourceHeader.getChildObjects().get(j).deepClone();
|
||||
targetHeader.getChildObjects().add(obj);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭文档对象
|
||||
if (document != null) {
|
||||
document.close();
|
||||
document.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// 将页脚复制到目标文档的第三节以及后续节
|
||||
for (int i = 2; i < doc2.getSections().getCount(); i++) {
|
||||
Section targetSection = doc2.getSections().get(i);
|
||||
HeaderFooter targetFooter = targetSection.getHeadersFooters().getFooter();
|
||||
targetFooter.getChildObjects().clear();
|
||||
for (int j = 0; j < sourceFooter.getChildObjects().getCount(); j++) {
|
||||
DocumentObject obj = sourceFooter.getChildObjects().get(j).deepClone();
|
||||
targetFooter.getChildObjects().add(obj);
|
||||
//复制页眉页脚操作
|
||||
try {
|
||||
//加载纵向模板文档用于复制
|
||||
Document doc1 = new Document();
|
||||
doc1.loadFromFile(tempPath + "制度-手册5.doc");
|
||||
|
||||
//获取section
|
||||
Section section1 = doc1.getSections().get(0);
|
||||
|
||||
//加载文档2
|
||||
Document doc2 = new Document();
|
||||
doc2.loadFromFile(outFile.getPath());
|
||||
SectionCollection sections = doc2.getSections();
|
||||
|
||||
|
||||
//加载文档1
|
||||
Document doc3 = new Document();
|
||||
doc3.loadFromFile(tempPath + "横板页眉页脚模板.doc");
|
||||
|
||||
// 获取源文档的页眉页脚
|
||||
/*Section sourceSection = doc1.getSections().get(0);
|
||||
HeaderFooter sourceHeader = sourceSection.getHeadersFooters().getHeader();
|
||||
HeaderFooter sourceFooter = sourceSection.getHeadersFooters().getFooter();*/
|
||||
|
||||
|
||||
// 将页眉复制到目标文档的第三节以及后续节
|
||||
for (int i = 2; i < doc2.getSections().getCount(); i++) {
|
||||
Section targetSection = doc2.getSections().get(i);
|
||||
|
||||
PageSetup pageSetup = targetSection.getPageSetup();
|
||||
PageOrientation orientation = pageSetup.getOrientation();
|
||||
|
||||
|
||||
// 根据合并文档节的页面方向选择模板
|
||||
PageOrientation mergeOrientation = pageSetup.getOrientation();
|
||||
Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1;
|
||||
|
||||
// 复制模板文档的页眉和页脚到新文档
|
||||
HeaderFooter sourceHeader = templateDoc.getSections().get(0).getHeadersFooters().getHeader();
|
||||
|
||||
HeaderFooter targetHeader = targetSection.getHeadersFooters().getHeader();
|
||||
targetHeader.getChildObjects().clear();
|
||||
|
||||
for (int j = 0; j < sourceHeader.getChildObjects().getCount(); j++) {
|
||||
|
||||
DocumentObject obj = sourceHeader.getChildObjects().get(j).deepClone();
|
||||
targetHeader.getChildObjects().add(obj);
|
||||
}
|
||||
}
|
||||
// 将页脚复制到目标文档的第三节以及后续节
|
||||
for (int i = 2; i < doc2.getSections().getCount(); i++) {
|
||||
Section targetSection = doc2.getSections().get(i);
|
||||
HeaderFooter targetFooter = targetSection.getHeadersFooters().getFooter();
|
||||
|
||||
PageSetup pageSetup = targetSection.getPageSetup();
|
||||
|
||||
PageOrientation mergeOrientation = pageSetup.getOrientation();
|
||||
Document templateDoc = (mergeOrientation == PageOrientation.Landscape) ? doc3 : doc1;
|
||||
HeaderFooter sourceFooter = templateDoc.getSections().get(0).getHeadersFooters().getFooter();
|
||||
|
||||
targetFooter.getChildObjects().clear();
|
||||
for (int j = 0; j < sourceFooter.getChildObjects().getCount(); j++) {
|
||||
DocumentObject obj = sourceFooter.getChildObjects().get(j).deepClone();
|
||||
targetFooter.getChildObjects().add(obj);
|
||||
}
|
||||
|
||||
}
|
||||
doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭文档对象
|
||||
if (document != null) {
|
||||
document.close();
|
||||
}
|
||||
}
|
||||
|
||||
doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
|
||||
}
|
||||
}
|
||||
long b2 = System.currentTimeMillis();
|
||||
@ -650,7 +689,6 @@ public class OutputWordUtil {
|
||||
//读取模型附件插入手册中文档对象
|
||||
if (search2 != null && search2.size() > 0) {
|
||||
|
||||
|
||||
//附件如果为空,不插入附件标题
|
||||
CharacterFormat format4 = new CharacterFormat();
|
||||
//创建字体格式
|
||||
@ -750,7 +788,15 @@ public class OutputWordUtil {
|
||||
System.err.println("插入附件用时:"
|
||||
+ (b2 - b1) / 1000 + "秒");
|
||||
}
|
||||
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
|
||||
try {
|
||||
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭文档对象
|
||||
doc.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1684,6 +1730,7 @@ public class OutputWordUtil {
|
||||
return n1.compareTo(n2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String getNum(Map<String, Object> json) {
|
||||
|
||||
@ -4154,4 +4154,59 @@ public class DesignerRelationShapeWeb extends ActionWeb {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量创建流程手册
|
||||
*
|
||||
* @param wsId
|
||||
* @param teamId
|
||||
* @param uuids
|
||||
* @return
|
||||
*/
|
||||
public String createOutputPrReports(String wsId, String teamId, String uuids) {
|
||||
// 校验流程手册是否安装并启动
|
||||
if (!SDK.getAppAPI().isActive("com.actionsoft.apps.coe.pal.output.pr"))
|
||||
return ResponseObject.newErrResponse("流程手册未安装或已暂停").toString();
|
||||
if (!SDK.getAppAPI().isActive("com.awspaas.user.apps.coe.pal.output.bd"))
|
||||
return ResponseObject.newErrResponse("表单手册未安装或已暂停").toString();
|
||||
if (!SDK.getAppAPI().isActive("com.awspaas.user.apps.coe.pal.output.zd"))
|
||||
return ResponseObject.newErrResponse("制度手册未安装或已暂停").toString();
|
||||
ResponseObject ro = ResponseObject.newOkResponse();
|
||||
JSONObject result = new JSONObject();
|
||||
JSONArray array = JSONArray.parseArray(uuids);
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
String uuid = array.getString(i);
|
||||
// 校验
|
||||
PALRepositoryModel model = PALRepositoryCache.getCache().get(uuid);
|
||||
if (model == null)
|
||||
throw new AWSException("没有找到文件:" + uuid);
|
||||
String taskId = "";
|
||||
if (model.getMethodId().contains("process.")) {
|
||||
taskId = PALRepositoryQueryAPIManager.getInstance().createOutputReportPr(wsId, _uc.getUID(), teamId, uuid);
|
||||
JSONObject object = JSONObject.parseObject(taskId);
|
||||
if ("ok".equals(object.getString("result")))
|
||||
taskId = object.getJSONObject("data").getString("taskId");
|
||||
else
|
||||
throw new AWSException("创建流程手册失败:" + uuid);
|
||||
} else if ("data.form".equals(model.getMethodId())) {
|
||||
taskId = PALRepositoryQueryAPIManager.getInstance().createOutputReportBd(wsId, _uc.getUID(), teamId, uuid);
|
||||
JSONObject object = JSONObject.parseObject(taskId);
|
||||
if ("ok".equals(object.getString("result")))
|
||||
taskId = object.getJSONObject("data").getString("taskId");
|
||||
else
|
||||
throw new AWSException("创建表单手册失败:" + uuid);
|
||||
} else if ("control.policy".equals(model.getMethodId())) {
|
||||
taskId = PALRepositoryQueryAPIManager.getInstance().createOutputReportZd(wsId, _uc.getUID(), teamId, uuid);
|
||||
JSONObject object = JSONObject.parseObject(taskId);
|
||||
if ("ok".equals(object.getString("result")))
|
||||
taskId = object.getJSONObject("data").getString("taskId");
|
||||
else
|
||||
throw new AWSException("创建制度手册失败:" + uuid);
|
||||
}
|
||||
result.put(uuid, UtilString.isEmpty(taskId) ? "" : taskId);
|
||||
}
|
||||
ro.put("data", result);
|
||||
return ro.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user