制度手册使用spire生成手册
This commit is contained in:
parent
24fd1ab36d
commit
db1ef96d41
Binary file not shown.
@ -1,21 +1,13 @@
|
||||
package com.actionsoft.apps.coe.pal.pal.output;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
|
||||
import com.actionsoft.apps.coe.pal.log.CoEOpLogAPI;
|
||||
import com.actionsoft.apps.coe.pal.log.CoEOpLogConst;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.constant.OutputConst;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.dao.OutputTask;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppManager;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppProfile;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.model.OutputTaskModel;
|
||||
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
||||
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
|
||||
import com.actionsoft.bpms.server.UserContext;
|
||||
@ -25,14 +17,16 @@ import com.actionsoft.bpms.util.ClassReflect;
|
||||
import com.actionsoft.bpms.util.UUIDGener;
|
||||
import com.actionsoft.bpms.util.UtilFile;
|
||||
import com.actionsoft.bpms.util.UtilString;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.constant.OutputConst;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.dao.OutputTask;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppManager;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppProfile;
|
||||
import com.actionsoft.apps.coe.pal.pal.output.model.OutputTaskModel;
|
||||
import com.actionsoft.exception.AWSException;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
/**
|
||||
* 报告生成器内部API封装
|
||||
@ -66,11 +60,9 @@ public class OutputAPIManager {
|
||||
throw new AWSException("Not Find OutputAppProfile! profileId=" + profileId);
|
||||
// --------dc context-----------
|
||||
DCPluginProfile dcProfile = SDK.getDCAPI().getDCProfile(appProfile.getAppContext().getId(), OutputConst.EXT_APP_DC_OUTPUT);
|
||||
System.out.println("这是一个什么东西>>>>>>"+dcProfile);
|
||||
if (dcProfile == null)
|
||||
throw new AWSException("Not Find DCProfile! repositoryName=" + OutputConst.EXT_APP_DC_OUTPUT);
|
||||
DCContext dcContext = new DCContext(null, dcProfile, appProfile.getAppContext().getId(), wsId, id, OutputConst.FILE_WIZARD_CONFIG);
|
||||
System.out.println("dc里边的是什么东西>>>>>>>>>>>>"+dcContext);
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = new ByteArrayInputStream(jsonData.getBytes("UTF-8"));
|
||||
@ -157,7 +149,7 @@ public class OutputAPIManager {
|
||||
* @param id 任务Id
|
||||
* @param profileId 报告生成器扩展App的配置Id
|
||||
*/
|
||||
public String getWizardJsonData(String wsId, String id, String profileId) throws AWSException {
|
||||
public String getWizardJsonData(String wsId, String id, String profileId) throws AWSException {
|
||||
// --------app appProfile----------
|
||||
OutputAppProfile appProfile = OutputAppManager.getProfile(profileId);
|
||||
if (appProfile == null)
|
||||
|
||||
@ -1,26 +1,46 @@
|
||||
package com.actionsoft.apps.coe.pal.pal.output.util;
|
||||
|
||||
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
|
||||
import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache;
|
||||
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel;
|
||||
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodModel;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.dao.DesignerShapeRelationDao;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.model.DesignerShapeRelationModel;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel;
|
||||
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
||||
import com.actionsoft.bpms.org.model.DepartmentModel;
|
||||
import com.actionsoft.bpms.org.model.RoleModel;
|
||||
import com.actionsoft.bpms.org.model.UserModel;
|
||||
import com.actionsoft.bpms.server.DispatcherRequest;
|
||||
import com.actionsoft.bpms.server.UserContext;
|
||||
import com.actionsoft.bpms.server.fs.DCContext;
|
||||
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
|
||||
import com.actionsoft.bpms.util.UtilFile;
|
||||
import com.actionsoft.bpms.util.UtilString;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sini.com.spire.doc.*;
|
||||
import com.sini.com.spire.doc.collections.SectionCollection;
|
||||
import com.sini.com.spire.doc.documents.*;
|
||||
import com.sini.com.spire.doc.fields.DocPicture;
|
||||
import com.sini.com.spire.doc.fields.TextRange;
|
||||
import com.sini.com.spire.doc.formatting.CharacterFormat;
|
||||
import com.sini.com.spire.doc.formatting.ParagraphFormat;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class OutputWordUtil {
|
||||
@ -186,6 +206,719 @@ public class OutputWordUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成word文件
|
||||
*
|
||||
* @param dataMap
|
||||
* @param tempPath
|
||||
* @param tempName
|
||||
* @param docName
|
||||
*/
|
||||
public static void createZdDoc2(JSONObject dataMap, String tempPath, String tempName, String docName, JSONObject wizardJsonData, String repositoryId, String docPath) throws FileNotFoundException {
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.setDefaultEncoding("UTF-8");
|
||||
|
||||
// 设置模本装置方法和路径
|
||||
try {
|
||||
UtilFile temps = new UtilFile(tempPath);
|
||||
configuration.setDirectoryForTemplateLoading(temps);
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
Template t = null;
|
||||
try {
|
||||
t = configuration.getTemplate(tempName, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 输出文档路径及名称
|
||||
File outFile = new File(docName);
|
||||
Writer out = null;
|
||||
try {
|
||||
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (t != null && out != null) {
|
||||
t.process(dataMap, out);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
} catch (TemplateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
//***********************************************************使用spire 生成模板后复制文件****************************************************/
|
||||
List<Map<String, Object>> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容
|
||||
if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序
|
||||
OutputWordUtil.orderByNumber(repositoryFileElements);
|
||||
}
|
||||
|
||||
String controlShapeId = "";
|
||||
if (repositoryFileElements != null) {
|
||||
int index = 1;// 流程步骤序号
|
||||
int dangerIndex = 1;// 风险序号
|
||||
int regulateIndex = 1;// 控制序号
|
||||
for (Map<String, Object> shape : repositoryFileElements) {
|
||||
String type = shape.get("type").toString();
|
||||
if ("regulation".equals(type)) {
|
||||
controlShapeId = shape.get("id").toString();
|
||||
} else if ("I/O_L4".equals(type)) {
|
||||
controlShapeId = shape.get("id").toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UserContext userContext = DispatcherRequest.getUserContext();
|
||||
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("listDef", "");
|
||||
result.put("content", "");
|
||||
if (UtilString.isEmpty(controlShapeId)) {
|
||||
|
||||
}
|
||||
PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId);
|
||||
if (repositoryModel == null) {
|
||||
|
||||
}
|
||||
String content = "";
|
||||
StringBuilder listStr = new StringBuilder();
|
||||
// 读取附件
|
||||
// 流程附件列表
|
||||
UpFileDao upFileDao = new UpFileDao();
|
||||
List<UpfileModel> search = upFileDao.search(repositoryModel.getId(), controlShapeId, null);
|
||||
|
||||
DCContext dcContextpdf = null;
|
||||
File file = null;
|
||||
|
||||
|
||||
if (search != null && search.size() > 0) {
|
||||
long b1 = System.currentTimeMillis();
|
||||
// 复制附件
|
||||
for (UpfileModel upfileModel : search) {
|
||||
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
|
||||
|
||||
if (dcProfile != null) {
|
||||
dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
|
||||
String path = dcContextpdf.getPath();
|
||||
String fileName = dcContextpdf.getFileName();
|
||||
|
||||
//创建 Document 类的对象并从磁盘加载 Word 文档
|
||||
Document document = new Document(outFile.getPath());
|
||||
|
||||
/*//获取最后一节
|
||||
Section section = document.getLastSection();
|
||||
Paragraph paragraph = section.addParagraph();
|
||||
|
||||
paragraph.appendBreak(BreakType.Page_Break);*/
|
||||
|
||||
|
||||
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
|
||||
if (suffix.equals("xml")) {
|
||||
// 输出文档路径及名称
|
||||
File sourceFile = new UtilFile(path + fileName);
|
||||
File targetFile = new UtilFile(docPath + fileName);
|
||||
try {
|
||||
UtilFile.copyFile(sourceFile, targetFile);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//创建实例,加载xml测试文档
|
||||
com.sini.com.spire.doc.Document doc = new com.sini.com.spire.doc.Document();
|
||||
doc.loadFromFile(docPath + fileName);
|
||||
|
||||
//保存为xml格式
|
||||
String substring = fileName.substring(0, fileName.lastIndexOf(".xml"));
|
||||
//保存为Word
|
||||
doc.saveToFile(docPath + substring + ".docx", FileFormat.Docx);//支持.doc
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (suffix.equals("xml")) {
|
||||
//保存为xml格式
|
||||
String substring = fileName.substring(0, fileName.lastIndexOf(".xml"));
|
||||
//保存为Word
|
||||
document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013);
|
||||
} else {
|
||||
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);
|
||||
|
||||
|
||||
//加载文档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);
|
||||
}
|
||||
}
|
||||
|
||||
// 将页脚复制到目标文档的第三节以及后续节
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
|
||||
}
|
||||
}
|
||||
long b2 = System.currentTimeMillis();
|
||||
|
||||
System.err.println("复制附件用时:"
|
||||
+ (b2 - b1) / 1000 + "秒");
|
||||
}
|
||||
|
||||
|
||||
/****************************插入支持文件、相关文件、附则等信息********************************************************/
|
||||
Document doc = new Document(outFile.getPath());
|
||||
//获取最后一节
|
||||
Section section = doc.getLastSection();
|
||||
|
||||
//添加段落,设置一级序列
|
||||
Paragraph paragraph = section.addParagraph();
|
||||
|
||||
|
||||
//paragraph.appendBreak(BreakType.Page_Break);
|
||||
//Section section2 = doc.addSection();
|
||||
|
||||
//相关文件 R_relevant_flies
|
||||
JSONArray relevant_flies = new JSONArray(); //组织职责Table
|
||||
List<DesignerShapeRelationModel> relationList2 = DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "", "related_files");
|
||||
int count = 0;
|
||||
if (relationList2.size() > 0) {
|
||||
for (DesignerShapeRelationModel relation : relationList2) {
|
||||
String relationFileId = relation.getRelationFileId();// 支持或相关文件的ID
|
||||
PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId);
|
||||
if (model != null) {
|
||||
count++;
|
||||
String name = model.getName();
|
||||
JSONObject tmp = new JSONObject();
|
||||
tmp.put("name", name);
|
||||
tmp.put("desc", count);
|
||||
|
||||
relevant_flies.add(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
CharacterFormat format = new CharacterFormat();
|
||||
//创建字体格式
|
||||
format.setFontName("宋体");
|
||||
//添加段落,设置一级序列
|
||||
Paragraph paragraph1 = section.addParagraph();
|
||||
|
||||
|
||||
//paragraph1.appendBreak(BreakType.Page_Break);
|
||||
|
||||
|
||||
ParagraphFormat paragraphFormat1 = paragraph1.getFormat();
|
||||
paragraphFormat1.setHorizontalAlignment(HorizontalAlignment.Left);
|
||||
|
||||
TextRange tr = paragraph1.appendText("相关文件");
|
||||
tr.getCharacterFormat().setBold(true);
|
||||
tr.getCharacterFormat().setFontName("宋体");
|
||||
tr.getCharacterFormat().setFontSize(12);
|
||||
//tr.applyCharacterFormat(format); //应用字体格式
|
||||
paragraph1.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式
|
||||
|
||||
|
||||
//定义表格数据
|
||||
String[] header = {"序号", "文件名称"};
|
||||
|
||||
String[][] strArray2 = new String[relevant_flies.size()][];
|
||||
List<String[]> list = new LinkedList<>();
|
||||
for (int i = 0; i < relevant_flies.size(); i++) {
|
||||
JSONObject jsonObject = relevant_flies.getJSONObject(i);
|
||||
String[] strArray = new String[2];
|
||||
strArray[0] = jsonObject.getString("desc").toString();
|
||||
strArray[1] = jsonObject.getString("name").toString();
|
||||
list.add(strArray);
|
||||
strArray2[i] = strArray;
|
||||
}
|
||||
|
||||
String[][] data = strArray2;
|
||||
|
||||
//添加表格
|
||||
Table table = section.addTable(true);
|
||||
table.resetCells(data.length + 1, header.length);
|
||||
|
||||
TableRow row = table.getRows().get(0);
|
||||
row.isHeader(true);
|
||||
row.setHeight(20);
|
||||
row.setHeightType(TableRowHeightType.Exactly);
|
||||
for (int i = 0; i < header.length; i++) {
|
||||
row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
|
||||
Paragraph p = row.getCells().get(i).addParagraph();
|
||||
p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
|
||||
TextRange txtRange = p.appendText(header[i]);
|
||||
txtRange.getCharacterFormat().setBold(true);
|
||||
}
|
||||
|
||||
//将数据添加到其余行
|
||||
for (int r = 0; r < data.length; r++) {
|
||||
TableRow dataRow = table.getRows().get(r + 1);
|
||||
dataRow.setHeight(25);
|
||||
dataRow.setHeightType(TableRowHeightType.Exactly);
|
||||
dataRow.getRowFormat().setBackColor(Color.white);
|
||||
for (int c = 0; c < data[r].length; c++) {
|
||||
dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
|
||||
dataRow.getCells().get(c).addParagraph().appendText(data[r][c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//支持文件
|
||||
JSONArray supportfiles = new JSONArray(); //组织职责Table
|
||||
List<DesignerShapeRelationModel> relationList = DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "", "support_files");
|
||||
int index = 0;
|
||||
if (relationList.size() > 0) {
|
||||
for (DesignerShapeRelationModel relation : relationList) {
|
||||
String relationFileId = relation.getRelationFileId();// 支持或相关文件的ID
|
||||
PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId);
|
||||
if (model != null) {
|
||||
index++;
|
||||
String name = model.getName();
|
||||
JSONObject tmp = new JSONObject();
|
||||
tmp.put("name", name);
|
||||
tmp.put("desc", index);
|
||||
supportfiles.add(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CharacterFormat format2 = new CharacterFormat();
|
||||
//创建字体格式
|
||||
format2.setFontName("宋体");
|
||||
//添加段落,设置一级序列
|
||||
Paragraph paragraph2 = section.addParagraph();
|
||||
ParagraphFormat paragraphFormat2 = paragraph2.getFormat();
|
||||
paragraphFormat2.setHorizontalAlignment(HorizontalAlignment.Left);
|
||||
TextRange tr2 = paragraph2.appendText("支持文件");
|
||||
tr2.getCharacterFormat().setBold(true);
|
||||
tr2.getCharacterFormat().setFontName("宋体");
|
||||
tr2.getCharacterFormat().setFontSize(12);
|
||||
paragraph2.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式
|
||||
|
||||
|
||||
//定义表格数据
|
||||
String[] header = {"序号", "文件名称"};
|
||||
String[][] strArray2 = new String[supportfiles.size()][];
|
||||
List<String[]> list = new LinkedList<>();
|
||||
for (int i = 0; i < supportfiles.size(); i++) {
|
||||
JSONObject jsonObject = supportfiles.getJSONObject(i);
|
||||
String[] strArray = new String[2];
|
||||
strArray[0] = jsonObject.getString("desc").toString();
|
||||
strArray[1] = jsonObject.getString("name").toString();
|
||||
list.add(strArray);
|
||||
strArray2[i] = strArray;
|
||||
}
|
||||
|
||||
String[][] data = strArray2;
|
||||
|
||||
//添加表格
|
||||
Table table = section.addTable(true);
|
||||
table.resetCells(data.length + 1, header.length);
|
||||
|
||||
TableRow row = table.getRows().get(0);
|
||||
row.isHeader(true);
|
||||
row.setHeight(20);
|
||||
row.setHeightType(TableRowHeightType.Exactly);
|
||||
for (int i = 0; i < header.length; i++) {
|
||||
row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
|
||||
Paragraph p = row.getCells().get(i).addParagraph();
|
||||
p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
|
||||
TextRange txtRange = p.appendText(header[i]);
|
||||
txtRange.getCharacterFormat().setBold(true);
|
||||
}
|
||||
|
||||
//将数据添加到其余行
|
||||
for (int r = 0; r < data.length; r++) {
|
||||
TableRow dataRow = table.getRows().get(r + 1);
|
||||
dataRow.setHeight(25);
|
||||
dataRow.setHeightType(TableRowHeightType.Exactly);
|
||||
dataRow.getRowFormat().setBackColor(Color.white);
|
||||
for (int c = 0; c < data[r].length; c++) {
|
||||
dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
|
||||
dataRow.getCells().get(c).addParagraph().appendText(data[r][c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*CharacterFormat format3=new CharacterFormat();
|
||||
//创建字体格式
|
||||
format3.setFontName("宋体");
|
||||
//添加段落,设置一级序列
|
||||
Paragraph paragraph3 = section.addParagraph();
|
||||
TextRange tr3 = paragraph3.appendText("7.附则");
|
||||
tr3.getCharacterFormat().setBold(true);
|
||||
tr3.getCharacterFormat().setFontName("宋体");
|
||||
paragraph3.applyStyle(BuiltinStyle.Heading_7); //应用标题1样式
|
||||
|
||||
//添加段落
|
||||
Paragraph paragraph5 = section.addParagraph();
|
||||
|
||||
// 附则处理
|
||||
List<String> T_supplementary_articles_table = new ArrayList<>();
|
||||
String [] tmp = dataMap.getString("pl_T_supplementary_articles").split("\n");
|
||||
for (int i = 0; i < tmp.length; i++) {
|
||||
if (UtilString.isNotEmpty(tmp[i])) {
|
||||
T_supplementary_articles_table.add(tmp[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TextRange tr5 = paragraph5.appendText(T_supplementary_articles_table.toString());
|
||||
tr5.getCharacterFormat().setFontName("宋体");*/
|
||||
|
||||
|
||||
//查询模型文件属性上传附件信息
|
||||
List<UpfileModel> search2 = upFileDao.searchByRepositoryId(repositoryModel.getId(), "f");
|
||||
|
||||
DCContext dcContextModel = null;
|
||||
|
||||
|
||||
// 排序
|
||||
Collections.sort(search2, new Comparator<UpfileModel>() {
|
||||
@Override
|
||||
public int compare(UpfileModel o1, UpfileModel o2) {
|
||||
String p1 = o1.getFileName();
|
||||
String p2 = o2.getFileName();
|
||||
if (p1.substring(0, 2).equals("附件") && p2.substring(0, 2).equals("附件") && p1.contains(":") && p2.contains(":")) {
|
||||
return Integer.parseInt(p1.substring(2, p1.indexOf(":"))) - Integer.parseInt(p2.substring(2, p2.indexOf(":")));
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//读取模型附件插入手册中文档对象
|
||||
if (search2 != null && search2.size() > 0) {
|
||||
|
||||
|
||||
//附件如果为空,不插入附件标题
|
||||
CharacterFormat format4 = new CharacterFormat();
|
||||
//创建字体格式
|
||||
format4.setFontName("宋体");
|
||||
//添加段落
|
||||
Paragraph paragraph4 = section.addParagraph();
|
||||
|
||||
ParagraphFormat paragraphFormat4 = paragraph4.getFormat();
|
||||
paragraphFormat4.setHorizontalAlignment(HorizontalAlignment.Left);
|
||||
|
||||
TextRange tr4 = paragraph4.appendText("附件");
|
||||
|
||||
|
||||
tr4.getCharacterFormat().setBold(true);
|
||||
tr4.getCharacterFormat().setFontName("宋体");
|
||||
tr4.getCharacterFormat().setFontSize(12);
|
||||
paragraph4.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式
|
||||
|
||||
|
||||
long b1 = System.currentTimeMillis();
|
||||
|
||||
for (UpfileModel upfileModel : search2) {
|
||||
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
|
||||
if (dcProfile != null) {
|
||||
|
||||
// 处理DocCenter
|
||||
dcContextModel = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, "file", upfileModel.getPl_uuid(), upfileModel.getFileName());
|
||||
//添加段落
|
||||
Paragraph paragraph5 = section.addParagraph();
|
||||
|
||||
//加载一个图片,它将作为外部文件的符号显示在Word文档中
|
||||
//获取最后一个.的位置
|
||||
int lastIndexOf = dcContextModel.getFileName().lastIndexOf(".");
|
||||
//获取文件的后缀名 .jpg
|
||||
String suffix = dcContextModel.getFileName().substring(lastIndexOf);
|
||||
|
||||
DocPicture pdfIcon = new DocPicture(doc);
|
||||
|
||||
InputStream stream1 = new FileInputStream(dcContextModel.getFilePath());
|
||||
DocPicture pic1 = new DocPicture(doc);
|
||||
|
||||
if (suffix.equals(".doc") || suffix.equals(".docx")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/word.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".doc")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "doc");
|
||||
} else if (suffix.equals(".docx")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "docx");
|
||||
}
|
||||
} else if (suffix.equals(".pdf")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/pdf.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
paragraph5.appendOleObject(stream1, pic1, "pdf");
|
||||
} else if (suffix.equals(".xls") || suffix.equals(".xlsx")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/xls.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".xls")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "xls");
|
||||
} else if (suffix.equals(".xlsx")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "xlsx");
|
||||
}
|
||||
} else if (suffix.equals(".png") || suffix.equals(".jgp")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/png.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".png")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "png");
|
||||
} else if (suffix.equals(".jpg")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "jpg");
|
||||
}
|
||||
} else if (suffix.equals(".zip") || suffix.equals(".rar")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/zip.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".zip")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "zip");
|
||||
} else if (suffix.equals(".rar")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "rar");
|
||||
}
|
||||
} else if (suffix.equals(".mp3") || suffix.equals(".mp4")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/mp3.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".mp3")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "mp3");
|
||||
} else if (suffix.equals(".mp4")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "mp4");
|
||||
}
|
||||
} else if (suffix.equals(".txt")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/txt.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
paragraph5.appendOleObject(stream1, pic1, "txt");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
long b2 = System.currentTimeMillis();
|
||||
System.err.println("插入附件用时:"
|
||||
+ (b2 - b1) / 1000 + "秒");
|
||||
}
|
||||
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成word文件
|
||||
*
|
||||
* @param dataMap
|
||||
* @param tempPath
|
||||
* @param tempName
|
||||
* @param docName
|
||||
*/
|
||||
public static void createBdDoc2(JSONObject dataMap, String tempPath, String tempName, String docName, String repositoryId) throws FileNotFoundException {
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.setDefaultEncoding("UTF-8");
|
||||
|
||||
// 设置模本装置方法和路径
|
||||
try {
|
||||
UtilFile temps = new UtilFile(tempPath);
|
||||
configuration.setDirectoryForTemplateLoading(temps);
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
Template t = null;
|
||||
try {
|
||||
t = configuration.getTemplate(tempName, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 输出文档路径及名称
|
||||
File outFile = new File(docName);
|
||||
Writer out = null;
|
||||
try {
|
||||
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (t != null && out != null) {
|
||||
t.process(dataMap, out);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
} catch (TemplateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
/**************************************************插入文件对象**********************************************************************/
|
||||
Document doc = new Document(outFile.getPath());
|
||||
//获取最后一节
|
||||
Section section = doc.getLastSection();
|
||||
|
||||
|
||||
CharacterFormat format4 = new CharacterFormat();
|
||||
//创建字体格式
|
||||
format4.setFontName("宋体");
|
||||
//添加段落
|
||||
Paragraph paragraph = section.addParagraph();
|
||||
|
||||
|
||||
ParagraphFormat paragraphFormat4 = paragraph.getFormat();
|
||||
paragraphFormat4.setHorizontalAlignment(HorizontalAlignment.Left);
|
||||
|
||||
TextRange tr4 = paragraph.appendText("表单/模板");
|
||||
|
||||
tr4.getCharacterFormat().setBold(true);
|
||||
tr4.getCharacterFormat().setFontName("宋体");
|
||||
paragraph.applyStyle(BuiltinStyle.Heading_1); //应用标题1样式
|
||||
|
||||
//doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
|
||||
|
||||
PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId);
|
||||
|
||||
UpFileDao upFileDao = new UpFileDao();
|
||||
//查询模型文件属性上传附件信息
|
||||
List<UpfileModel> search = upFileDao.searchByRepositoryId(repositoryModel.getId(), "s");
|
||||
|
||||
|
||||
DCContext dcContextModel = null;
|
||||
UserContext userContext = DispatcherRequest.getUserContext();
|
||||
if (search != null && search.size() > 0) {
|
||||
// 复制附件
|
||||
for (UpfileModel upfileModel : search) {
|
||||
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
|
||||
|
||||
if (dcProfile != null) {
|
||||
dcContextModel = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
|
||||
String path = dcContextModel.getPath();
|
||||
String fileName = dcContextModel.getFileName();
|
||||
|
||||
|
||||
//添加段落
|
||||
Paragraph paragraph5 = section.addParagraph();
|
||||
|
||||
//加载一个图片,它将作为外部文件的符号显示在Word文档中
|
||||
//获取最后一个.的位置
|
||||
int lastIndexOf = dcContextModel.getFileName().lastIndexOf(".");
|
||||
//获取文件的后缀名 .jpg
|
||||
String suffix = dcContextModel.getFileName().substring(lastIndexOf);
|
||||
|
||||
DocPicture pdfIcon = new DocPicture(doc);
|
||||
|
||||
InputStream stream1 = new FileInputStream(dcContextModel.getFilePath());
|
||||
DocPicture pic1 = new DocPicture(doc);
|
||||
|
||||
if (suffix.equals(".doc") || suffix.equals(".docx")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/word.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".doc")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "doc");
|
||||
} else if (suffix.equals(".docx")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "docx");
|
||||
}
|
||||
} else if (suffix.equals(".pdf")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/pdf.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
paragraph5.appendOleObject(stream1, pic1, "pdf");
|
||||
} else if (suffix.equals(".xls") || suffix.equals(".xlsx")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/xls.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".xls")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "xls");
|
||||
} else if (suffix.equals(".xlsx")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "xlsx");
|
||||
}
|
||||
} else if (suffix.equals(".png") || suffix.equals(".jgp")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/png.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".png")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "png");
|
||||
} else if (suffix.equals(".jpg")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "jpg");
|
||||
}
|
||||
} else if (suffix.equals(".zip") || suffix.equals(".rar")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/zip.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".zip")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "zip");
|
||||
} else if (suffix.equals(".rar")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "rar");
|
||||
}
|
||||
} else if (suffix.equals(".mp3") || suffix.equals(".mp4")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/mp3.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
if (suffix.equals(".mp3")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "mp3");
|
||||
} else if (suffix.equals(".mp4")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "mp4");
|
||||
}
|
||||
} else if (suffix.equals(".txt")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/txt.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName());
|
||||
paragraph5.appendOleObject(stream1, pic1, "txt");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将文件的扩展属性设置默认值为空字符串(防止没有设置扩展属性而使得导出文件出错)
|
||||
*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user