预报导出--添加目录级别

This commit is contained in:
zhn
2022-09-26 14:07:17 +08:00
parent 827afe009e
commit 7c497c7c57
2 changed files with 72 additions and 26 deletions
@@ -648,8 +648,8 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
FileOutputStream outContentCn = new FileOutputStream(wordFileContentCn);
//封面
cover(lawsMonthlyReportWriteEOS, titleCN, documentContentCn);
//目录
catalogue(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, "目录", documentContentCn,CutEnum.CN.getValue());
// //目录
// catalogue(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, "目录", documentContentCn,CutEnum.CN.getValue());
wordContent(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, titleCN,
documentContentCn,CutEnum.CN.getValue(),loginUserList);
// documentContentCn.createTOC();
@@ -662,8 +662,8 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
FileOutputStream outContentEn = new FileOutputStream(wordFileContentEn);
//封面
cover(lawsMonthlyReportWriteEOS, titleEN, documentContentEn);
//目录
catalogue(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, "catalogue", documentContentEn,CutEnum.EN.getValue());
// //目录
// catalogue(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, "catalogue", documentContentEn,CutEnum.EN.getValue());
wordContent(lawsMonthlyReportWriteEOS, lawsMonthlyReportTitleTemplateEOS, reportTitleOneList, titleEN,
documentContentEn,CutEnum.EN.getValue(), loginUserList);
documentContentEn.write(outContentEn);
@@ -737,9 +737,9 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "") + "";
//单独设置每页右侧的时间
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
false, false, "Blue Sky Noto Regular",null);
false, false, "Blue Sky Noto Regular",null,null);
WordUtil.exportWord(document, content, null, ParagraphAlignment.LEFT, 0, 12,
false, true, "Blue Sky Noto Regular",null);
false, true, "Blue Sky Noto Regular",null,null);
//生成页脚
WordUtil.exportHeardAndFootMain(document,moth);
int oneCount = 1;
@@ -756,7 +756,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(StringUtils.isNotBlank(oneTitle)){
WordUtil.exportWord(document, oneNumber+" "+oneTitle, null, ParagraphAlignment.LEFT,
0, 12, false, true, "Blue Sky Noto Regular",null);
0, 12, false, true, "Blue Sky Noto Regular","0","一级标题");
oneCount++;
}
@@ -779,7 +779,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(StringUtils.isNotBlank(twoTitle)){
WordUtil.exportWord(document, twoNumber+" "+twoTitle, null, ParagraphAlignment.LEFT,
2, 12, false, true, "Blue Sky Noto Regular",null);
2, 12, false, true, "Blue Sky Noto Regular","1","二级标题");
twoCount++;
}
@@ -793,7 +793,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(org.apache.commons.lang3.StringUtils.isNotBlank(reportTitle)){
WordUtil.exportWord(document, reportCount+". "+reportTitle, null, ParagraphAlignment.LEFT,
6, 12, false, false, "Blue Sky Noto Regular",null);
6, 12, false, false, "Blue Sky Noto Regular","2","三级标题");
reportCount++;
}
}
@@ -810,7 +810,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "") + "";
//单独设置每页右侧的时间
WordUtil.exportWord(document, catalogue, null, ParagraphAlignment.LEFT, 0, 18,
false, false, "Blue Sky Noto Regular",null);
false, false, "Blue Sky Noto Regular",null,null);
int oneCount = 1;
@@ -826,7 +826,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(StringUtils.isNotBlank(oneTitle)){
WordUtil.exportWord(document, oneNumber+" "+oneTitle, null, ParagraphAlignment.LEFT,
0, 12, false, true, "Blue Sky Noto Regular",null);
0, 12, false, true, "Blue Sky Noto Regular",null,null);
oneCount++;
}
@@ -849,7 +849,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(StringUtils.isNotBlank(twoTitle)){
WordUtil.exportWord(document, twoNumber+" "+twoTitle, null, ParagraphAlignment.LEFT,
2, 12, false, true, "Blue Sky Noto Regular",null);
2, 12, false, true, "Blue Sky Noto Regular",null,null);
twoCount++;
}
@@ -863,7 +863,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(org.apache.commons.lang3.StringUtils.isNotBlank(reportTitle)){
WordUtil.exportWord(document, reportCount+". "+reportTitle, null, ParagraphAlignment.LEFT,
6, 12, false, false, "Blue Sky Noto Regular",null);
6, 12, false, false, "Blue Sky Noto Regular",null,null);
reportCount++;
}
}
@@ -879,9 +879,9 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
titleCN = "\r\n\r\n" + titleCN + "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
false, false, "Blue Sky Noto Regular",null);
false, false, "Blue Sky Noto Regular",null,null);
WordUtil.exportWord(document, moth, null, ParagraphAlignment.CENTER, 0, 12,
false, true, "Blue Sky Noto Regular",null);
false, true, "Blue Sky Noto Regular",null,null);
}
private void wordContent(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
List<LawsMonthlyReportTitleTemplateEO> lawsMonthlyReportTitleTemplateEOS,
@@ -902,8 +902,9 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
//生成页眉页脚
WordUtil.exportHeardAndFoot(document,moth);
//生成标题
WordUtil.exportWord(document, "\r\n\r\n\r\n", null, ParagraphAlignment.CENTER, 0, 18,
false, true, "Blue Sky Noto Regular",null);
WordUtil.exportWord(document, "", null, ParagraphAlignment.CENTER, 0, 18,
// WordUtil.exportWord(document, "\r\n\r\n\r\n", null, ParagraphAlignment.CENTER, 0, 18,
false, true, "Blue Sky Noto Regular",null,null);
int oneCount = 1;
for (LawsMonthlyReportTitleTemplateEO lawsMonthlyReportTitleTemplateEO : reportTitleOneList) {
@@ -918,7 +919,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(StringUtils.isNotBlank(oneTitle)){
WordUtil.exportWord(document, oneNumber+" "+oneTitle, null, ParagraphAlignment.LEFT,
0, 14, false, true, "Blue Sky Noto Regular","Heading1");
0, 14, false, true, "Blue Sky Noto Regular","0","一级标题");
oneCount++;
}
@@ -941,7 +942,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(StringUtils.isNotBlank(twoTitle)){
WordUtil.exportWord(document, twoNumber+" "+twoTitle, null, ParagraphAlignment.LEFT,
2, 12, false, true, "Blue Sky Noto Regular","Heading2");
2, 12, false, true, "Blue Sky Noto Regular","1","二级标题");
twoCount++;
}
//二级目录下放--->新征求意见清单模板, 新发布标准清单模板
@@ -950,13 +951,13 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
for (LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO : askList) {
WordUtil.exportWordExcelAsk(document,lawsMonthlyReportWriteEO,cut);
WordUtil.exportWord(document, null, null, null,
0, 0, false, true, null,null);
0, 0, false, true, null,null,null);
}
for (LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO : issueList) {
WordUtil.exportWordExcelIssue(document,lawsMonthlyReportWriteEO,cut);
WordUtil.exportWord(document, null, null, null, 0, 0,
false, true, null,null);
false, true, null,null,null);
}
for (LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO : lawsMonthlyReportWriteEOList) {
@@ -969,7 +970,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
}
if(StringUtils.isNotBlank(reportTitle)){
WordUtil.exportWord(document, reportCount+". "+reportTitle, null, ParagraphAlignment.LEFT,
6, 11, false, false, "Blue Sky Noto Regular","Heading3");
6, 11, false, false, "Blue Sky Noto Regular","2","三级标题");
}
@@ -22,18 +22,26 @@ import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFPicture;
import org.apache.poi.xwpf.usermodel.XWPFPictureData;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFStyle;
import org.apache.poi.xwpf.usermodel.XWPFStyles;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.xmlbeans.impl.xb.xmlschema.SpaceAttribute;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFldChar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblLayoutType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblLayoutType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
@@ -61,6 +69,7 @@ public class WordUtil {
* @param isBold 是否加粗,默认不加粗
* @param fontFamily 字体,默认宋体
* @param directoryLevel 目录级别
* @param styleName 标题样式
*/
public static void exportWord(XWPFDocument document,
String text,
@@ -70,14 +79,17 @@ public class WordUtil {
Integer fontSize,
Boolean isNewline,
Boolean isBold,
String fontFamily,String directoryLevel) {
String fontFamily,
String directoryLevel,
String styleName) {
//添加标题
XWPFParagraph titleParagraph = document.createParagraph();
//设置标题级别
if(StringUtils.isNotEmpty(directoryLevel)){
titleParagraph.setStyle(directoryLevel);
addCustomHeadingStyle(document,styleName,Integer.parseInt(directoryLevel));
}
XWPFParagraph titleParagraph = document.createParagraph();
titleParagraph.setStyle(styleName);
//设置段落左对齐
if (align == null) {
@@ -128,6 +140,39 @@ public class WordUtil {
}
}
/**
* 增加自定义标题样式。这里用的是stackoverflow的源码
*
* @param docxDocument 目标文档
* @param strStyleId 样式名称
* @param headingLevel 样式级别
*/
private static void addCustomHeadingStyle(XWPFDocument docxDocument, String strStyleId, int headingLevel) {
CTStyle ctStyle = CTStyle.Factory.newInstance();
ctStyle.setStyleId(strStyleId);
CTString styleName = CTString.Factory.newInstance();
styleName.setVal(strStyleId);
ctStyle.setName(styleName);
CTDecimalNumber indentNumber = CTDecimalNumber.Factory.newInstance();
indentNumber.setVal(BigInteger.valueOf(headingLevel));
// lower number > style is more prominent in the formats bar
ctStyle.setUiPriority(indentNumber);
CTOnOff onoffnull = CTOnOff.Factory.newInstance();
ctStyle.setUnhideWhenUsed(onoffnull);
// style shows up in the formats bar
ctStyle.setQFormat(onoffnull);
// style defines a heading of the given level
CTPPr ppr = CTPPr.Factory.newInstance();
ppr.setOutlineLvl(indentNumber);
ctStyle.setPPr(ppr);
XWPFStyle style = new XWPFStyle(ctStyle);
// is a null op if already defined
XWPFStyles styles = docxDocument.createStyles();
style.setType(STStyleType.PARAGRAPH);
styles.addStyle(style);
}
// @SneakyThrows
// public static void exportHeardAndFoot(XWPFDocument document){
//// XWPFDocument document = new XWPFDocument();