月报导出--office版本
This commit is contained in:
+98
-5
@@ -1025,17 +1025,26 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
}
|
||||
}
|
||||
|
||||
//封面
|
||||
//封面(office版本)
|
||||
private void coverCn(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
String titleCN,
|
||||
XWPFDocument document) {
|
||||
//封面标识
|
||||
String flag = "cover";
|
||||
String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "年") + "月";
|
||||
//标题前面添加一个换行
|
||||
WordUtil.exportWord(document, "", null, ParagraphAlignment.CENTER, 0, null,
|
||||
false, false, "Blue Sky Noto Regular",null,null,"break");
|
||||
|
||||
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";
|
||||
//添加标题
|
||||
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
|
||||
false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
|
||||
//标题下面添加9个换行
|
||||
for (int i = 0; i < 9; i++) {
|
||||
WordUtil.exportWord(document, "", null, ParagraphAlignment.CENTER, 0, null,
|
||||
false, false, "Blue Sky Noto Regular",null,null,"break");
|
||||
}
|
||||
WordUtil.exportWord(document, moth, null, ParagraphAlignment.CENTER, 0, 12,
|
||||
false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
|
||||
@@ -1060,7 +1069,42 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
//添加下一页
|
||||
document.createParagraph().createRun().addBreak(BreakType.PAGE);
|
||||
}
|
||||
//封面
|
||||
//封面(WPS版本)
|
||||
// private void coverCn(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
// String titleCN,
|
||||
// XWPFDocument document) {
|
||||
// //封面标识
|
||||
// String flag = "cover";
|
||||
// String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "年") + "月";
|
||||
//
|
||||
// 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";
|
||||
// WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
|
||||
// false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
// WordUtil.exportWord(document, moth, null, ParagraphAlignment.CENTER, 0, 12,
|
||||
// false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
//
|
||||
// String year = lawsMonthlyReportWriteEOS.get(0).getMonth().split("-")[0];
|
||||
// String mothNew = lawsMonthlyReportWriteEOS.get(0).getMonth().split("-")[1];
|
||||
// int mothLast = Integer.valueOf(mothNew) + 1;
|
||||
//
|
||||
// //添加说明 2022/7/15 至 2022/8/14 期间发布的主要内容
|
||||
// String text = year + "/" + mothNew +"/15 至 "+year+"/"+mothLast+"/14期间发布的主要内容";
|
||||
// WordUtil.exportWord(document, text, null, ParagraphAlignment.CENTER, 0, 11,
|
||||
// false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
//
|
||||
// //添加换行
|
||||
// WordUtil.exportWord(document, "\r\n", null, ParagraphAlignment.CENTER, 0, null,
|
||||
// false, false, null,null,null,flag);
|
||||
//
|
||||
// //添加说明 编辑: 整车工程 - 法规与认证&环保与材料科团队
|
||||
// String text1 = "编辑: 整车工程 - 法规与认证&环保与材料科团队";
|
||||
// WordUtil.exportWord(document, text1, null, ParagraphAlignment.CENTER, 0, 11,
|
||||
// false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
//
|
||||
// //添加下一页
|
||||
// document.createParagraph().createRun().addBreak(BreakType.PAGE);
|
||||
// }
|
||||
//封面(office版本)
|
||||
private void coverEn(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
String titleCN,
|
||||
XWPFDocument document) {
|
||||
@@ -1074,11 +1118,19 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
String mothNewEn = getMothEn(mothNew);
|
||||
String mothLastEn = getMothEn(String.valueOf(mothLast));
|
||||
|
||||
// String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "年") + "月";
|
||||
//标题前面添加一个换行
|
||||
WordUtil.exportWord(document, "", null, ParagraphAlignment.CENTER, 0, null,
|
||||
false, false, "Blue Sky Noto Regular",null,null,"break");
|
||||
|
||||
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";
|
||||
//添加标题
|
||||
WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
|
||||
false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
//标题下面添加8个换行
|
||||
for (int i = 0; i < 8; i++) {
|
||||
WordUtil.exportWord(document, "", null, ParagraphAlignment.CENTER, 0, null,
|
||||
false, false, "Blue Sky Noto Regular",null,null,"break");
|
||||
}
|
||||
|
||||
WordUtil.exportWord(document, moth, null, ParagraphAlignment.CENTER, 0, 12,
|
||||
false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
|
||||
@@ -1101,6 +1153,47 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
|
||||
//添加下一页
|
||||
document.createParagraph().createRun().addBreak(BreakType.PAGE);
|
||||
}
|
||||
//封面(WPS版本)
|
||||
// private void coverEn(List<LawsMonthlyReportWriteEO> lawsMonthlyReportWriteEOS,
|
||||
// String titleCN,
|
||||
// XWPFDocument document) {
|
||||
// //封面标识
|
||||
// String flag = "cover";
|
||||
//
|
||||
// String year = lawsMonthlyReportWriteEOS.get(0).getMonth().split("-")[0];
|
||||
// String mothNew = lawsMonthlyReportWriteEOS.get(0).getMonth().split("-")[1];
|
||||
// int mothLast = Integer.valueOf(mothNew) + 1;
|
||||
// String moth = mothNew+"/"+year;
|
||||
// String mothNewEn = getMothEn(mothNew);
|
||||
// String mothLastEn = getMothEn(String.valueOf(mothLast));
|
||||
//
|
||||
//// String moth = lawsMonthlyReportWriteEOS.get(0).getMonth().replaceAll("-", "年") + "月";
|
||||
//
|
||||
// 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";
|
||||
// WordUtil.exportWord(document, titleCN, null, ParagraphAlignment.CENTER, 0, 18,
|
||||
// false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
// WordUtil.exportWord(document, moth, null, ParagraphAlignment.CENTER, 0, 12,
|
||||
// false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
//
|
||||
//
|
||||
//
|
||||
// //添加说明 Update between July 15, 2022 and August 14, 2022
|
||||
// String text = "Update between "+mothNewEn+" 15,"+year+" and "+mothLastEn+" 14,"+year;
|
||||
// WordUtil.exportWord(document, text, null, ParagraphAlignment.CENTER, 0, 11,
|
||||
// false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
//
|
||||
// //添加换行
|
||||
// WordUtil.exportWord(document, "\r\n", null, ParagraphAlignment.CENTER, 0, null,
|
||||
// false, false, null,null,null,flag);
|
||||
//
|
||||
// //添加说明 编辑: 整车工程 - 法规与认证&环保与材料科团队
|
||||
// String text1 = "Edit By: Regulation & Homologation, Environmental & Materials Team";
|
||||
// WordUtil.exportWord(document, text1, null, ParagraphAlignment.CENTER, 0, 11,
|
||||
// false, false, "Blue Sky Noto Regular",null,null,flag);
|
||||
//
|
||||
// //添加下一页
|
||||
// document.createParagraph().createRun().addBreak(BreakType.PAGE);
|
||||
// }
|
||||
|
||||
private String getMothEn(String moth){
|
||||
String result = "";
|
||||
|
||||
+142
-49
@@ -128,6 +128,10 @@ public class WordUtil {
|
||||
}
|
||||
|
||||
XWPFRun titleParagraphRun = titleParagraph.createRun();
|
||||
//封面中的换行
|
||||
if("break".equals(flag)){
|
||||
titleParagraphRun.addBreak();
|
||||
}
|
||||
if (isNewline) {
|
||||
titleParagraphRun.setText("\r");
|
||||
} else {
|
||||
@@ -202,45 +206,7 @@ public class WordUtil {
|
||||
styles.addStyle(style);
|
||||
}
|
||||
|
||||
// @SneakyThrows
|
||||
// public static void exportHeardAndFoot(XWPFDocument document){
|
||||
//// XWPFDocument document = new XWPFDocument();
|
||||
//
|
||||
// // create header-footer
|
||||
// XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy();
|
||||
// if (headerFooterPolicy == null) headerFooterPolicy = document.createHeaderFooterPolicy();
|
||||
//
|
||||
// // create header start
|
||||
// XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
|
||||
//
|
||||
// XWPFParagraph paragraph = header.createParagraph();
|
||||
// paragraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
//
|
||||
// XWPFRun run = paragraph.createRun();
|
||||
// run.setText("Header");
|
||||
//
|
||||
// // create footer start
|
||||
// XWPFFooter footer = headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
|
||||
//
|
||||
// paragraph = footer.createParagraph();
|
||||
// paragraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
//
|
||||
// run = paragraph.createRun();
|
||||
// run.setText("Footer");
|
||||
//
|
||||
// CTSectPr sectPr = document.getDocument().getBody().getSectPr();
|
||||
// if (sectPr == null) sectPr = document.getDocument().getBody().addNewSectPr();
|
||||
// CTPageMar pageMar = sectPr.getPgMar();
|
||||
// if (pageMar == null) pageMar = sectPr.addNewPgMar();
|
||||
// pageMar.setLeft(BigInteger.valueOf(2000)); //720 TWentieths of an Inch Point (Twips) = 720/20 = 36 pt = 36/72 = 0.5"
|
||||
// pageMar.setRight(BigInteger.valueOf(720));
|
||||
// pageMar.setTop(BigInteger.valueOf(1440)); //1440 Twips = 1440/20 = 72 pt = 72/72 = 1"
|
||||
// pageMar.setBottom(BigInteger.valueOf(1440));
|
||||
//
|
||||
// pageMar.setHeader(BigInteger.valueOf(2000)); //45.4 pt * 20 = 908 = 45.4 pt header from top
|
||||
// pageMar.setFooter(BigInteger.valueOf(568)); //28.4 pt * 20 = 568 = 28.4 pt footer from bottom
|
||||
//
|
||||
// }
|
||||
//主要内容生成页眉页脚(office版本)
|
||||
@SneakyThrows
|
||||
public static void exportHeardAndFoot(XWPFDocument document,String month){
|
||||
XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy();
|
||||
@@ -266,7 +232,7 @@ public class WordUtil {
|
||||
picture.getCTPicture().getBlipFill().getBlip().setEmbed(blipID);
|
||||
run.addTab();
|
||||
is.close();
|
||||
run.setText(" "+month);
|
||||
run.setText(" "+month);
|
||||
run.setFontSize(11);
|
||||
run.setFontFamily("Blue Sky Noto Regular");
|
||||
}
|
||||
@@ -313,20 +279,107 @@ public class WordUtil {
|
||||
|
||||
CTSectPr sectPr = document.getDocument().getBody().getSectPr();
|
||||
if (sectPr == null) sectPr = document.getDocument().getBody().addNewSectPr();
|
||||
//设置页面大小
|
||||
//设置页面大小(21*29.7)
|
||||
CTPageSz pgSz = sectPr.addNewPgSz();
|
||||
pgSz.setW(BigInteger.valueOf(11907));
|
||||
pgSz.setH(BigInteger.valueOf(16840));
|
||||
pgSz.setW(BigInteger.valueOf(11905));
|
||||
pgSz.setH(BigInteger.valueOf(16838));
|
||||
CTPageMar pageMar = sectPr.getPgMar();
|
||||
if (pageMar == null) pageMar = sectPr.addNewPgMar();
|
||||
pageMar.setLeft(BigInteger.valueOf(1803)); //左边距
|
||||
pageMar.setRight(BigInteger.valueOf(1803));//右边距
|
||||
pageMar.setLeft(BigInteger.valueOf(1797)); //左边距
|
||||
pageMar.setRight(BigInteger.valueOf(1797));//右边距
|
||||
pageMar.setTop(BigInteger.valueOf(1440)); //页眉高度
|
||||
pageMar.setBottom(BigInteger.valueOf(1440));//页脚高度
|
||||
|
||||
pageMar.setHeader(BigInteger.valueOf(720)); //页眉上边框到顶部的距离
|
||||
pageMar.setFooter(BigInteger.valueOf(720)); //页脚下边框到底部的距离
|
||||
}
|
||||
//主要内容生成页眉页脚(WPS版本)
|
||||
// @SneakyThrows
|
||||
// public static void exportHeardAndFoot(XWPFDocument document,String month){
|
||||
// XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy();
|
||||
// if (headerFooterPolicy == null) headerFooterPolicy = document.createHeaderFooterPolicy();
|
||||
// XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
|
||||
//
|
||||
//// String logoFilePath = "/jero-boot/home/weilai.png";
|
||||
// String logoFilePath = WordUtil.class.getClassLoader().getResource("static/home/weilai.png").getPath();
|
||||
// //页眉第一个段落展示logo-----------------------------------------------------------------------------------
|
||||
// if (org.apache.commons.lang3.StringUtils.isNotBlank(logoFilePath)) {
|
||||
// XWPFParagraph logo = header.createParagraph();
|
||||
// logo.setAlignment(ParagraphAlignment.LEFT);
|
||||
// XWPFRun run = logo.createRun();
|
||||
//
|
||||
// String imgFile = logoFilePath;
|
||||
// InputStream is = WordUtil.class.getClassLoader().getResourceAsStream("static/home/weilai.png");
|
||||
//// InputStream is = new FileInputStream(imgFile);
|
||||
// XWPFPicture picture = run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, imgFile, Units.toEMU(95), Units.toEMU(35));
|
||||
// String blipID = "";
|
||||
// for(XWPFPictureData picturedata : header.getAllPackagePictures()) { //这段必须有,不然打开的logo图片不显示
|
||||
// blipID = header.getRelationId(picturedata);
|
||||
// }
|
||||
// picture.getCTPicture().getBlipFill().getBlip().setEmbed(blipID);
|
||||
// run.addTab();
|
||||
// is.close();
|
||||
// run.setText(" "+month);
|
||||
// run.setFontSize(11);
|
||||
// run.setFontFamily("Blue Sky Noto Regular");
|
||||
// }
|
||||
// //页眉第二个段落展示日期------------------------------------------------------------
|
||||
// XWPFParagraph paragraph = header.createParagraph();//创建新的段落
|
||||
//// paragraph.setAlignment(ParagraphAlignment.RIGHT);//段落文本的对齐方式
|
||||
// XWPFRun run = paragraph.createRun();
|
||||
//// run.setText(month);
|
||||
//
|
||||
// //页脚(三个段落分别展示3个内容)-----------------------------------------------------
|
||||
// XWPFFooter footer = headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
|
||||
//
|
||||
// paragraph = footer.createParagraph();
|
||||
// paragraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
// run = paragraph.createRun();
|
||||
// run.setText("NIO Internal");
|
||||
// run.setFontSize(11);
|
||||
// run.setFontFamily("Blue Sky Standard Regular");
|
||||
//
|
||||
// paragraph = footer.createParagraph();
|
||||
// paragraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
// run = paragraph.createRun();
|
||||
// run.setText("NIO.com");
|
||||
// run.setFontSize(11);
|
||||
// run.setFontFamily("Blue Sky Noto Regular");
|
||||
//
|
||||
// //生成页码---------------------------------------------------------------------
|
||||
// paragraph = footer.createParagraph();
|
||||
// paragraph.setAlignment(ParagraphAlignment.RIGHT);
|
||||
// run = paragraph.createRun();
|
||||
// CTFldChar fldChar = run.getCTR().addNewFldChar();
|
||||
// fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));
|
||||
//
|
||||
// run = paragraph.createRun();
|
||||
// CTText ctText = run.getCTR().addNewInstrText();
|
||||
// ctText.setStringValue("PAGE \\* MERGEFORMAT");
|
||||
// ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
|
||||
//
|
||||
// fldChar = run.getCTR().addNewFldChar();
|
||||
// fldChar.setFldCharType(STFldCharType.Enum.forString("end"));
|
||||
// //----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// CTSectPr sectPr = document.getDocument().getBody().getSectPr();
|
||||
// if (sectPr == null) sectPr = document.getDocument().getBody().addNewSectPr();
|
||||
// //设置页面大小
|
||||
// CTPageSz pgSz = sectPr.addNewPgSz();
|
||||
// pgSz.setW(BigInteger.valueOf(11907));
|
||||
// pgSz.setH(BigInteger.valueOf(16840));
|
||||
// CTPageMar pageMar = sectPr.getPgMar();
|
||||
// if (pageMar == null) pageMar = sectPr.addNewPgMar();
|
||||
// pageMar.setLeft(BigInteger.valueOf(1803)); //左边距
|
||||
// pageMar.setRight(BigInteger.valueOf(1803));//右边距
|
||||
// pageMar.setTop(BigInteger.valueOf(1440)); //页眉高度
|
||||
// pageMar.setBottom(BigInteger.valueOf(1440));//页脚高度
|
||||
//
|
||||
// pageMar.setHeader(BigInteger.valueOf(720)); //页眉上边框到顶部的距离
|
||||
// pageMar.setFooter(BigInteger.valueOf(720)); //页脚下边框到底部的距离
|
||||
// }
|
||||
|
||||
/**
|
||||
* 主页面(只有页脚)
|
||||
@@ -356,18 +409,58 @@ public class WordUtil {
|
||||
if (sectPr == null) sectPr = document.getDocument().getBody().addNewSectPr();
|
||||
//设置页面大小
|
||||
CTPageSz pgSz = sectPr.addNewPgSz();
|
||||
pgSz.setW(BigInteger.valueOf(11907));
|
||||
pgSz.setH(BigInteger.valueOf(16840));
|
||||
pgSz.setW(BigInteger.valueOf(11905));
|
||||
pgSz.setH(BigInteger.valueOf(16838));
|
||||
CTPageMar pageMar = sectPr.getPgMar();
|
||||
if (pageMar == null) pageMar = sectPr.addNewPgMar();
|
||||
pageMar.setLeft(BigInteger.valueOf(1803)); //左边距
|
||||
pageMar.setRight(BigInteger.valueOf(1803));//右边距
|
||||
pageMar.setLeft(BigInteger.valueOf(1797)); //左边距
|
||||
pageMar.setRight(BigInteger.valueOf(1797));//右边距
|
||||
pageMar.setTop(BigInteger.valueOf(1440)); //页眉高度
|
||||
pageMar.setBottom(BigInteger.valueOf(1440));//页脚高度
|
||||
|
||||
pageMar.setHeader(BigInteger.valueOf(500)); //页眉上边框到顶部的距离
|
||||
pageMar.setFooter(BigInteger.valueOf(1200)); //页脚下边框到底部的距离
|
||||
}
|
||||
// /**
|
||||
// * 主页面(只有页脚 WPS版本)
|
||||
// * @param document
|
||||
// * @param month
|
||||
// */
|
||||
// @SneakyThrows
|
||||
// public static void exportHeardAndFootMain(XWPFDocument document,String month){
|
||||
// XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy();
|
||||
// if (headerFooterPolicy == null) headerFooterPolicy = document.createHeaderFooterPolicy();
|
||||
//// XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
|
||||
//// XWPFParagraph paragraph = header.createParagraph();//创建新的段落
|
||||
//// XWPFRun run = paragraph.createRun();
|
||||
//
|
||||
// XWPFFooter footer = headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
|
||||
// XWPFParagraph paragraph = footer.createParagraph();
|
||||
// paragraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
// XWPFRun run = paragraph.createRun();
|
||||
// run.setText("NIO Internal");
|
||||
// run.setFontSize(18);
|
||||
// run.setFontFamily("Blue Sky Standard Regular");
|
||||
//// run.setFontFamily("Blue Sky Noto Regular");
|
||||
// run.setBold(true);
|
||||
//
|
||||
//
|
||||
// CTSectPr sectPr = document.getDocument().getBody().getSectPr();
|
||||
// if (sectPr == null) sectPr = document.getDocument().getBody().addNewSectPr();
|
||||
// //设置页面大小
|
||||
// CTPageSz pgSz = sectPr.addNewPgSz();
|
||||
// pgSz.setW(BigInteger.valueOf(11907));
|
||||
// pgSz.setH(BigInteger.valueOf(16840));
|
||||
// CTPageMar pageMar = sectPr.getPgMar();
|
||||
// if (pageMar == null) pageMar = sectPr.addNewPgMar();
|
||||
// pageMar.setLeft(BigInteger.valueOf(1803)); //左边距
|
||||
// pageMar.setRight(BigInteger.valueOf(1803));//右边距
|
||||
// pageMar.setTop(BigInteger.valueOf(1440)); //页眉高度
|
||||
// pageMar.setBottom(BigInteger.valueOf(1440));//页脚高度
|
||||
//
|
||||
// pageMar.setHeader(BigInteger.valueOf(500)); //页眉上边框到顶部的距离
|
||||
// pageMar.setFooter(BigInteger.valueOf(1200)); //页脚下边框到底部的距离
|
||||
// }
|
||||
|
||||
/**
|
||||
* 导出工具示例
|
||||
|
||||
Reference in New Issue
Block a user