制度手册生成修改

This commit is contained in:
zhal 2023-10-30 15:03:46 +08:00
parent 935a169cb0
commit f02753e1c0
2 changed files with 18 additions and 174 deletions

View File

@ -546,22 +546,17 @@ public class OutputWordUtil {
}
}
// 在第一页的末尾插入分页符
//section.addParagraph().appendBreak(BreakType.Page_Break);
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
}
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
if (suffix.equals("xml")) {
// 输出文档路径及名称
File sourceFile = new UtilFile(path + fileName);
File targetFile = new UtilFile(docPath + fileName);
File targetFile = new UtilFile(docPath+ fileName);
try {
UtilFile.copyFile(sourceFile, targetFile);
} catch (Exception e) {
@ -571,185 +566,29 @@ public class OutputWordUtil {
//创建实例加载xml测试文档
Document doc = new Document();
doc.loadFromFile(docPath + fileName);
doc.loadFromFile(docPath+ fileName);
//保存为xml格式
String substring = fileName.substring(0, fileName.lastIndexOf(".xml"));
//保存为Word
doc.saveToFile(docPath + substring + ".docx", FileFormat.Docx);//支持.doc
doc.saveToFile(docPath +"/xmltodoc/"+ substring + ".doc", FileFormat.Doc);//支持.doc
}
if (suffix.equals("xml")) {
//保存为xml格式
String substring = fileName.substring(0, fileName.lastIndexOf(".xml"));
//保存为Word
/*document.insertTextFromFile(docPath + substring + ".docx", FileFormat.Docx_2013);
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);*/
Document document1 = new Document(outFile.getPath());
Document document2 = new Document(docPath + substring + ".docx");
// 获取最后第一节
Section section = document1.getLastSection();
// 获取该节第三段
Paragraph paragraph = section.getParagraphs().get(3);
// 在段落的末尾添加分页符
paragraph.appendBreak(BreakType.Page_Break);
// 在第二个文档中循环获取所有节
for (Object sectionObj : (Iterable) document2.getSections()) {
Section sec = (Section) sectionObj;
// 在所有节中循环获取所有子对象
for (Object docObj : (Iterable) sec.getBody().getChildObjects()) {
DocumentObject obj = (DocumentObject) docObj;
// 获取第一个文档的最后一节
Section lastSection = document1.getLastSection();
// 将所有子对象添加到第一个文档的最后一节中
Body body = lastSection.getBody();
body.getChildObjects().add(obj.deepClone());
}
}
document.insertTextFromFile(docPath+"/xmltodoc/" + substring + ".doc", FileFormat.Doc);
//保存结果文档
document1.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
// 获取第一个节的第一个表格
Section threesection = document1.getSections().get(1);
Table table3 = threesection.getTables().get(2);
//遍历表格单元格
for (int i = 0;i< table3.getRows().getCount();i++) {
TableRow rows = table3.getRows().get(i);
for (int j = 0; j< rows.getCells().getCount(); j++){
for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){
Paragraph p = rows.getCells().get(j).getParagraphs().get(z);
p.getFormat().setLineSpacing(12f);//设置边距为1.0
for (int k = 0; k < p.getItems().getCount(); k++) {
DocumentObject item = p.getItems().get(k);
if (item instanceof TextRange) {
TextRange textRange = (TextRange) item;
textRange.getCharacterFormat().setFontName("宋体");
textRange.getCharacterFormat().setFontSize(10.5f);
}
}
}
}
}
// 获取第一个节的第一个表格
Section fourection = document1.getSections().get(1);
Table table4 = fourection.getTables().get(3);
//遍历表格单元格
for (int i = 0;i< table4.getRows().getCount();i++) {
TableRow rows = table4.getRows().get(i);
for (int j = 0; j< rows.getCells().getCount(); j++){
for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){
Paragraph p = rows.getCells().get(j).getParagraphs().get(z);
p.getFormat().setLineSpacing(12f);//设置边距为1.0
for (int k = 0; k < p.getItems().getCount(); k++) {
DocumentObject item = p.getItems().get(k);
if (item instanceof TextRange) {
TextRange textRange = (TextRange) item;
textRange.getCharacterFormat().setFontName("宋体");
textRange.getCharacterFormat().setFontSize(10.5f);
}
}
}
}
}
document1.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
} else if (suffix.equals("doc") || suffix.equals("docx")) {
//document.insertTextFromFile(path + fileName, FileFormat.Doc);
Document document1 = new Document(outFile.getPath());
Document document2 = new Document(path + fileName);
// 获取最后第一节
Section section = document1.getLastSection();
// 获取该节第三段
Paragraph paragraph = section.getParagraphs().get(3);
// 在段落的末尾添加分页符
paragraph.appendBreak(BreakType.Page_Break);
// 在第二个文档中循环获取所有节
for (Object sectionObj : (Iterable) document2.getSections()) {
Section sec = (Section) sectionObj;
// 在所有节中循环获取所有子对象
for (Object docObj : (Iterable) sec.getBody().getChildObjects()) {
DocumentObject obj = (DocumentObject) docObj;
// 获取第一个文档的最后一节
Section lastSection = document1.getLastSection();
// 将所有子对象添加到第一个文档的最后一节中
Body body = lastSection.getBody();
body.getChildObjects().add(obj.deepClone());
}
}
document.insertTextFromFile(path + fileName, FileFormat.Docx_2013);
//保存结果文档
document1.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
// 获取第一个节的第一个表格
Section threesection = document1.getSections().get(1);
if(threesection.getTables().getCount()>3){
Table table3 = threesection.getTables().get(2);
//遍历表格单元格
for (int i = 0;i< table3.getRows().getCount();i++) {
TableRow rows = table3.getRows().get(i);
for (int j = 0; j< rows.getCells().getCount(); j++){
for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){
Paragraph p = rows.getCells().get(j).getParagraphs().get(z);
p.getFormat().setLineSpacing(12f);//设置边距为1.0
for (int k = 0; k < p.getItems().getCount(); k++) {
DocumentObject item = p.getItems().get(k);
if (item instanceof TextRange) {
TextRange textRange = (TextRange) item;
textRange.getCharacterFormat().setFontName("宋体");
textRange.getCharacterFormat().setFontSize(10.5f);
}
}
}
}
}
Table table4 = threesection.getTables().get(3);
//遍历表格单元格
for (int i = 0;i< table4.getRows().getCount();i++) {
TableRow rows = table4.getRows().get(i);
for (int j = 0; j< rows.getCells().getCount(); j++){
for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){
Paragraph p = rows.getCells().get(j).getParagraphs().get(z);
p.getFormat().setLineSpacing(12f);//设置边距为1.0
for (int k = 0; k < p.getItems().getCount(); k++) {
DocumentObject item = p.getItems().get(k);
if (item instanceof TextRange) {
TextRange textRange = (TextRange) item;
textRange.getCharacterFormat().setFontName("宋体");
textRange.getCharacterFormat().setFontSize(10.5f);
}
}
}
}
}
document1.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
}
}else if (suffix.equals("pptx")) {
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
} else if (suffix.equals("pptx")) {
isPPT = true;
}
@ -819,6 +658,10 @@ public class OutputWordUtil {
}
}
doc2.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
} catch (Exception e) {
@ -1299,6 +1142,7 @@ public class OutputWordUtil {
}
try {
System.out.println("生成附件路径是=================="+outFile.getPath());
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
} catch (Exception e) {
e.printStackTrace();