From 99f7f9adac08f3a3fa3211f7a6062c26d62fa224 Mon Sep 17 00:00:00 2001
From: 林致杰 <1003392067@qq.com>
Date: 星期日, 26 六月 2022 18:35:15 +0800
Subject: [PATCH] 组别报告解析生成
---
src/main/java/com/ots/framework/web/controller/BaseController.java | 46 +++
src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java | 421 ++++++++++++++++++++++++++++++++
src/main/java/com/ots/project/exam/domain/TReportTemplate.java | 6
src/main/java/com/ots/project/tool/report/MAQ/base/RowData.java | 21 +
src/main/java/com/ots/common/utils/poi/WordUtil.java | 269 ++++++++++---------
src/main/java/com/ots/common/enums/ReportTypeEnum.java | 2
src/main/java/com/ots/project/tool/PdfUtil.java | 2
src/main/java/com/ots/project/tool/report/MAQ/base/SeriesData.java | 3
8 files changed, 638 insertions(+), 132 deletions(-)
diff --git a/src/main/java/com/ots/common/enums/ReportTypeEnum.java b/src/main/java/com/ots/common/enums/ReportTypeEnum.java
index da473a3..ca765fd 100644
--- a/src/main/java/com/ots/common/enums/ReportTypeEnum.java
+++ b/src/main/java/com/ots/common/enums/ReportTypeEnum.java
@@ -4,7 +4,7 @@
@Getter
public enum ReportTypeEnum {
Brief("Brief", "绠�鏄撶増"), Complete("Complete", "瀹屾暣鐗�"), SAQ("SAQ", "SAQ鎶ュ憡"), RuiLin("RuiLin", "鐫块偦鎶ュ憡"), CAQ("CAQ", "CAQ鎶ュ憡"),
- JAQ("JAQ","JAQ鎶ュ憡"),MAQ("MAQ", "MAQ鎶ュ憡"),MAQV2("MAQV2", "MAQV2鎶ュ憡"),PAQ("PAQ", "PAQ鎶ュ憡"),MAQIAR("MAQIAR", "MAQIAR鎶ュ憡");
+ JAQ("JAQ","JAQ鎶ュ憡"),MAQ("MAQ", "MAQ鎶ュ憡"),MAQV2("MAQV2", "MAQV2鎶ュ憡"),PAQ("PAQ", "PAQ鎶ュ憡"),MAQIAR("MAQIAR", "MAQIAR鎶ュ憡"),MAQTR("MAQTR", "MAQTR鎶ュ憡");
private final String code;
private final String message;
ReportTypeEnum(String code, String message) {
diff --git a/src/main/java/com/ots/common/utils/poi/WordUtil.java b/src/main/java/com/ots/common/utils/poi/WordUtil.java
index 9f6d490..a394a0f 100644
--- a/src/main/java/com/ots/common/utils/poi/WordUtil.java
+++ b/src/main/java/com/ots/common/utils/poi/WordUtil.java
@@ -17,6 +17,7 @@
import com.ots.project.tool.exam.ExamUtil;
import com.ots.project.tool.exam.ImageUtil;
import com.ots.project.tool.exam.ZipUtil;
+import com.ots.project.tool.report.MAQTR.chart.MAQTRChart;
import com.ots.project.tool.report.PAQ.chart.PAQChart;
import org.apache.commons.collections.map.HashedMap;
import org.apache.poi.ooxml.POIXMLDocument;
@@ -53,18 +54,18 @@
put("<FontSize_11>", "</FontSize_11>");
}};
public static final int DEFAULT_FONT_SIZE = 10;
-
+
public static boolean changWord(String inputUrl, String outputUrl,
Map<String, Object> textMap, Map<String, Object> tableMap) {
-
+
try {
-
+
XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl));
-
+
WordUtil.changeText(document, textMap);
-
+
WordUtil.changeTable(document, textMap);
-
+
File file = new File(outputUrl);
FileOutputStream stream = new FileOutputStream(file);
document.write(stream);
@@ -78,15 +79,15 @@
}
public static OutputStream getReportWord(String inputUrl, String outputUrl,
Map<String, Object> textMap, Map<String, Object> tableMap) {
-
+
try {
-
+
XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl));
-
+
WordUtil.changeText(document, textMap);
-
+
WordUtil.changeTable(document, textMap);
-
+
File file = new File(outputUrl);
return new FileOutputStream(file);
} catch (IOException e) {
@@ -98,14 +99,14 @@
}
public static boolean changWord(String inputUrl, String outputUrl,
Map<String, Object> textMap, WordParam wordParam) {
-
+
boolean changeFlag = true;
try {
-
+
XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl));
-
+
WordUtil.changeText(document, textMap);
-
+
File file = new File(outputUrl);
FileOutputStream stream = new FileOutputStream(file);
document.write(stream);
@@ -117,12 +118,12 @@
}
return changeFlag;
}
-
+
public static void changeText(XWPFDocument document, Map<String, Object> textMap) throws IOException, InvalidFormatException {
-
+
setHeader(document, textMap);
-
-
+
+
List<IBodyElement> elements = document.getBodyElements();
List<XWPFParagraph> paragraphs = new ArrayList<>();
for (IBodyElement iBodyElement : elements) {
@@ -131,10 +132,10 @@
}
}
for (XWPFParagraph paragraph : paragraphs) {
-
+
String text = paragraph.getText();
if (checkText(text)) {
-
+
List<IRunElement> iRunElements = paragraph.getIRuns();
List<XWPFRun> runs = new ArrayList<>();
for (IRunElement iRunElement : iRunElements) {
@@ -142,19 +143,19 @@
}
int runPosition = 0;
for (XWPFRun run : runs) {
-
+
String changeValueStr = changeValue(run.toString(), textMap, run, paragraph, document, runPosition);
if (!StringUtils.equals(changeValueStr, "NoChangValue")) {
run.setText(changeValueStr, 0);
}
runPosition++;
}
-
-
+
+
}
}
}
-
+
private static void setHeader(XWPFDocument document, Map<String, Object> textMap) {
try {
List<XWPFHeader> headerList = document.getHeaderList();
@@ -198,15 +199,15 @@
setTableValue(document, textMap, tables);
}
public static void changePage(XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
-
+
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph paragraph : paragraphs) {
-
+
String text = paragraph.getText();
if (text.indexOf("%page-change%") != -1) {
List<XWPFRun> runs = paragraph.getRuns();
for (XWPFRun run : runs) {
-
+
if (StringUtils.equals(run.toString(), "%page-change%")) {
run.setText("", 0);
}
@@ -216,15 +217,15 @@
}
}
public static void changeLine(XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
-
+
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph paragraph : paragraphs) {
-
+
String text = paragraph.getText();
if (text.indexOf("%line-feed%") != -1) {
List<XWPFRun> runs = paragraph.getRuns();
for (XWPFRun run : runs) {
-
+
if (StringUtils.equals(run.toString(), "%line-feed%")) {
run.setText("", 0);
run.addBreak();
@@ -235,7 +236,7 @@
}
private static void setPicture(XWPFRun run, WordParam wordParam) throws org.apache.poi.openxml4j.exceptions.InvalidFormatException, IOException {
InputStream in = new FileInputStream(wordParam.getContent());
-
+
BufferedImage bufferedImage = ImageUtil.getImage(wordParam.getContent());
int width = (int) Math.round(bufferedImage.getWidth());
int height = (int) Math.round(bufferedImage.getHeight());
@@ -243,10 +244,10 @@
run.addPicture(in, Document.PICTURE_TYPE_PNG, "TEST", width * emuSelf, height * emuSelf);
in.close();
if (wordParam.isMove()) {
-
+
CTDrawing drawing = run.getCTR().getDrawingArray(0);
CTGraphicalObject graphicalobject = drawing.getInlineArray(0).getGraphic();
-
+
CTAnchor anchor = getAnchorWithGraphic(graphicalobject, "TEST1",
Units.toEMU(wordParam.getPicWidth()), Units.toEMU(wordParam.getPicHeight()),
Units.toEMU(wordParam.getX()), Units.toEMU(wordParam.getY()), false, wordParam.getTopPosition());
@@ -254,7 +255,7 @@
drawing.removeInline(0);
}
}
-
+
public static CTAnchor getAnchorWithGraphic(CTGraphicalObject ctGraphicalObject,
String deskFileName, int width, int height,
int leftOffset, int topOffset, boolean behind, int topPosition) {
@@ -284,9 +285,9 @@
anchor.setGraphic(ctGraphicalObject);
return anchor;
}
-
+
public static void changeTable(XWPFDocument document, Map<String, Object> textMap) {
-
+
List<XWPFTable> tables = document.getTables();
setTableValue(document, textMap, tables);
}
@@ -299,7 +300,7 @@
*/
private static void setTableValue(XWPFDocument document, Map<String, Object> textMap, List<XWPFTable> tables) {
for (int i = 0; i < tables.size(); i++) {
-
+
log.info("绗�" + (i + 1) + "涓〃锛�");
try {
XWPFTable table = tables.get(i);
@@ -312,7 +313,7 @@
}
if (checkText(table.getText())) {
List<XWPFTableRow> rows = table.getRows();
-
+
eachTable(rows, textMap, document);
}
}
@@ -735,14 +736,14 @@
}
List<XWPFTable> tables = document.getTables();
for (int i = 0; i < tables.size(); i++) {
-
+
log.info("绗�" + (i + 1) + "涓〃锛�");
try {
XWPFTable table = tables.get(i);
if (table.getRows().size() > 0) {
-
+
log.info("娣诲姞琛岃〃鏍兼暟鎹細" + table.getText());
-
+
Map<Integer, List<String[]>> mapRowsMap = autoTableMap.get(i);
log.info("鎻掑叆" + table.getText());
insertTable(table, mapRowsMap.get(i), 1);
@@ -785,12 +786,12 @@
}
mapRowsMap.put(3, table4List);
}*/
-
+
public static void eachTable(List<XWPFTableRow> rows, Map<String, Object> textMap, XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
for (XWPFTableRow row : rows) {
List<XWPFTableCell> cells = row.getTableCells();
for (XWPFTableCell cell : cells) {
-
+
//濡傛灉褰撳墠琛ㄦ牸鍖呭惈%灏变唬琛ㄩ渶瑕佹浛鎹�
if (checkText(cell.getText())) {
List<XWPFParagraph> paragraphs = cell.getParagraphs();
@@ -820,13 +821,13 @@
e.printStackTrace();
}
}
-
+
public static void insertTable(XWPFTable table, List<String[]> tableList, int inserRowNum) {
-
+
for (int i = 0; i < tableList.size(); i++) {
XWPFTableRow row = table.createRow();
}
-
+
XWPFTableRow headXwpfTableRow = table.getRows().get(0);
for (int i = inserRowNum; i <= tableList.size(); i++) {
XWPFTableRow newRow = table.getRow(i);
@@ -835,7 +836,7 @@
try {
XWPFTableCell cell = cells.get(j);
cell.setText(tableList.get(i - 1)[j]);
-
+
cell.getParagraphs().get(0).getCTP().setPPr(headXwpfTableRow.getCell(0).getParagraphs().get(0).getCTP().getPPr());
} catch (Exception e) {
}
@@ -867,12 +868,12 @@
int count = oldLength - newLength;
return count;
}
-
+
public static String changeValue(String runValue, Map<String, Object> textMap, XWPFRun run, XWPFParagraph paragraph, XWPFDocument document, int runPosition) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
log.debug("changeText:{}",runValue);
Set<Map.Entry<String, Object>> textSets = textMap.entrySet();
for (Map.Entry<String, Object> textSet : textSets) {
-
+
String key = "%" + textSet.getKey() + "%";
if (runValue.indexOf("%page-change%") != -1) {
runValue = "";
@@ -894,20 +895,20 @@
}
}
}
-
+
if (checkText(runValue)) {
runValue = runValue.replaceAll("%.*%", "");
runValue = runValue.replaceAll("N/A NONE", "");
-
+
}
-
+
return runValue;
}
private static String setOtherStyle(String runValue, XWPFParagraph paragraph, int runPosition, XWPFRun oldRun) {
-
-
-
-
+
+
+
+
int position = 0;
int pointer = 0;
int end = runValue.length();
@@ -933,12 +934,12 @@
if (StringUtils.isNotEmpty(newRunStr)) {
newRunStr = newRunStr.replaceAll("<BoldText>", "");
newRunStr = newRunStr.replaceAll("</BoldText>", "");
-
+
String rgbStr = getRGBStr(newRunStr, oldRun);
if (rgbStr == null) {
rgbStr = oldRun.getColor();
}
-
+
int fontSize = getFontSize(newRunStr, oldRun);
if (fontSize == -1) {
fontSize = oldRun.getFontSize();
@@ -966,7 +967,7 @@
pointer = end;
}
}
-
+
paragraph.removeRun(runPosition);
return "NoChangValue";
}
@@ -1038,7 +1039,7 @@
private static void changOtherPicture(XWPFParagraph paragraph) {
-
+
String paragraphText = paragraph.getText();
if (paragraphText.indexOf("{start.png}") == -1) {
return;
@@ -1054,22 +1055,22 @@
position = paragraphText.indexOf("{start.png}", position);
String value = "";
if (position == -1) {
-
+
runPosition = insertPicRun(paragraph, oldRun, runPosition, paragraphText.substring(poiter, end));
break;
}
if (poiter == position) {
position = position + starLength;
-
+
runPosition = insertSmallRunPic(paragraph, runPosition);
poiter = position;
continue;
} else {
-
+
runPosition = insertPicRun(paragraph, oldRun, runPosition, paragraphText.substring(poiter, position));
poiter = position;
position = poiter + starLength;
-
+
runPosition = insertSmallRunPic(paragraph, runPosition);
poiter = position;
}
@@ -1105,7 +1106,7 @@
insertRun.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize);
return runPosition;
}
-
+
private static String changeWordAndPicValue(String runValue, XWPFRun run, Map.Entry<String, Object> textSet, String key, XWPFParagraph paragraph, XWPFDocument document) throws org.apache.poi.openxml4j.exceptions.InvalidFormatException, IOException {
if (textSet.getValue() instanceof WordParam) {
setPicture(run, (WordParam) textSet.getValue());
@@ -1128,9 +1129,9 @@
}
return runValue;
}
-
+
public AjaxResult exportBaseOrDetailReport(String fileName, List<String> deleteFileStrList, List<String> fileNameList) {
-
+
try {
zipWord(fileName, fileNameList);
} catch (FileNotFoundException e) {
@@ -1138,19 +1139,19 @@
} catch (Exception e) {
e.printStackTrace();
}
-
+
deleteFileByStr(deleteFileStrList);
return AjaxResult.success(fileName + ".zip");
}
public AjaxResult exportZipKeepFiles(String fileName, List<String> deleteFileStrList, List<String> fileNameList) throws FileNotFoundException {
-
+
zipKeepWord(fileName, fileNameList);
-
+
deleteFileByStr(deleteFileStrList);
return AjaxResult.success(fileName + ".zip");
}
-
-
+
+
public static String makeReportFile(String fileName, TReportTemplate tReportTemplate, Map<String, Object> textMap, Map<Integer, Map<Integer, List<String[]>>> autoTableMap, List<String> deleteFileStrList) {
String returnMessage = "瀵煎嚭妯℃澘杞Щ閿欒:";
InputStream in = null;
@@ -1158,28 +1159,29 @@
String zipFilePath = "";
String reportName = "";
try {
-
+
String reportType = tReportTemplate.getReportType();
reportType = getTypeIfIsSAQ(tReportTemplate, reportType);
reportType = getPositionIfJAQ(textMap, reportType);
reportName = textMap.get("sendEmailFileName") + "_" + reportType + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getTemplateType()).getCode() + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getLangType()).getCode() + ".docx";
-
+
reportName = reportName.replaceAll(" ", "_");
out = getDownLoadFileOutputStream(reportName);
-
+
log.info("reportTemplate:" + fileName);
- String templateType = tReportTemplate.getTemplateType();
- setChageWord(fileName, out, textMap, tReportTemplate.getReportType(), templateType, autoTableMap);
+ //String templateType = tReportTemplate.getTemplateType();
+ setChageWord(fileName, out, textMap, tReportTemplate.getReportType(),tReportTemplate.getDataPath(), autoTableMap);
out.flush();
changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType());
- //PAQ閲囩敤鏂扮殑doc杞琾df
- if(!ReportTypeEnum.PAQ.getCode().equals(reportType)){
- ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
- }else{
+ //PAQ銆丮AQTR閲囩敤鏂扮殑doc杞琾df
+ if(ReportTypeEnum.PAQ.getCode().equals(reportType) || ReportTypeEnum.MAQTR.getCode().equals(reportType)){
PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName);
+ }else{
+ ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
+
}
zipFilePath = getPdfPath(reportName);
-
+
deleteFileStrList.add(EssConfig.getProfile() + "/" + reportName);
} catch (Exception ex) {
returnMessage = returnMessage + ex.getMessage();
@@ -1213,7 +1215,7 @@
return reportName.substring(0, reportName.lastIndexOf(".")) + ".pdf";
}
public static void deleteFileByStr(List<String> deleteFileStrList) {
-
+
for (String deleteStr : deleteFileStrList) {
File file = new File(deleteStr);
file.delete();
@@ -1247,7 +1249,7 @@
}
ZipUtil.toZip(fileList, zipOut);
}
-
+
private static FileOutputStream getDownLoadFileOutputStream(String fileName) throws FileNotFoundException {
File outFile = new File(EssConfig.getProfile() + "/" + fileName);
if (!outFile.getParentFile().exists()) {
@@ -1255,9 +1257,21 @@
}
return new FileOutputStream(outFile);
}
- private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType, String templateType, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException, DocumentException {
- String filePath = getTemplateDownLoadPathByUpLoad(fileName);
-
+
+ /**
+ * 鍐呭鍙樻洿
+ * @param fileName
+ * @param out
+ * @param textMap
+ * @param reportType
+ * @param autoTableMap
+ * @throws IOException
+ * @throws InvalidFormatException
+ * @throws DocumentException
+ */
+ private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType,String dataPath, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, InvalidFormatException, DocumentException {
+ //String filePath = getTemplateDownLoadPathByUpLoad(fileName);
+
XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(getTemplateDownLoadPathByUpLoad(fileName)));
//璁剧疆鏂囨湰
@@ -1266,11 +1280,6 @@
//璁剧疆鏂囨湰妗�
changeTextBox(document, textMap);
- //璁剧疆鍥捐〃
- if (Objects.equals(reportType, ReportTypeEnum.PAQ.getCode())) {
- PAQChart.changeChart(document, textMap);
- }
-
//鎻掑叆琛ㄦ牸
addTableValue(document, autoTableMap);
@@ -1278,12 +1287,12 @@
changeTable(document, textMap);
//璁剧疆鍥捐〃鎺т欢
- changChar(textMap, document, reportType, templateType);
+ changChart(textMap, document, reportType,dataPath);
document.write(out);
}
private static void changeTextBox(XWPFDocument document, Map<String, Object> textMap) throws DocumentException {
List<XWPFParagraph> paragraphs = document.getParagraphs();
-
+
for (XWPFParagraph paragraph : paragraphs) {
CTR[] rArray = paragraph.getCTP().getRArray();
for (XmlObject ctr : rArray) {
@@ -1313,7 +1322,7 @@
String repText = "";
Set<Map.Entry<String, Object>> textSets = textMap.entrySet();
for (Map.Entry<String, Object> textSet : textSets) {
-
+
String key = "%" + textSet.getKey() + "%";
if (text.indexOf(key) != -1) {
text = text.replaceAll(key, (String) textMap.get(textSet.getKey()));
@@ -1338,7 +1347,7 @@
if (StringUtils.isEmpty(fileName) || CollUtil.isEmpty(jaqTableStyleList)) {
return;
}
-
+
XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(EssConfig.getProfile() + "/" + fileName));
if (Objects.isNull(document)) {
return;
@@ -1365,13 +1374,13 @@
/**
* 璁剧疆鍥炬爣鎺т欢
- * @param textMap
- * @param document
- * @param reportType
- * @param templateType
+ * @param textMap 鏇挎崲text
+ * @param document 鎶ュ憡鏂囦欢
+ * @param reportType 鎶ュ憡绫诲瀷
+ * @param dataPath MAQTR鏁版嵁璺緞
*/
- private static void changChar(Map<String, Object> textMap, XWPFDocument document, String reportType, String templateType) {
- if (StringUtils.isEmpty(reportType) || StringUtils.isEmpty(templateType)) {
+ private static void changChart(Map<String, Object> textMap, XWPFDocument document, String reportType,String dataPath) {
+ if (StringUtils.isEmpty(reportType)) {
return;
}
List<XWPFChart> charts = document.getCharts();
@@ -1384,6 +1393,10 @@
setMAQ_V2CompleteChars(textMap, charts);
} else if (StringUtils.equals(reportType, ReportTypeEnum.RuiLin.getCode())) {
setRuiLinChar(textMap, charts);
+ } else if (StringUtils.equals(reportType, ReportTypeEnum.PAQ.getCode())) {
+ PAQChart.changeChart(document, textMap);
+ } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQTR.getCode())) {
+ MAQTRChart.changeMAQTRChart(document, dataPath);
} else {
return;
}
@@ -1394,7 +1407,7 @@
String P_INCON25 = textMap.get("P_INCON25").toString();
String P_IM24 = textMap.get("P_IM24").toString();
String P_SDE23 = textMap.get("P_SDE23").toString();
-
+
for (XWPFChart xwpfChart : charts) {
try {
CTChart ctChart = xwpfChart.getCTChart();
@@ -1441,15 +1454,15 @@
setCharMap.put(12, WordUtil::set12RuilinChartList);
setCharMap.put(38, WordUtil::set38RuilinChartList);
setCharMap.put(4, WordUtil::set4RuilinChartList);
-
+
XWPFChart xwpfChart0 = charts.get(0);
List<CTNumVal> ptList = xwpfChart0.getCTChart().getPlotArea().getBarChartList().get(0).getSerList().get(0).getVal().getNumRef().getNumCache().getPtList();
setCharMap.get(char0Size).setsetRuilinChartList(textMap, ptList);
-
+
XWPFChart xwpfChart1 = charts.get(1);
ptList = xwpfChart1.getCTChart().getPlotArea().getBarChartList().get(0).getSerList().get(0).getVal().getNumRef().getNumCache().getPtList();
setCharMap.get(char1Size).setsetRuilinChartList(textMap, ptList);
-
+
@@ -1520,13 +1533,13 @@
private static void setMAQCompleteChars(Map<String, Object> textMap, List<XWPFChart> charts) {
String p_Task31 = textMap.get("P_Task31").toString();
String p_People32 = textMap.get("P_People32").toString();
-
+
XWPFChart xwpfChart = charts.get(0);
if (!setMAQbarGraph(p_Task31, p_People32, xwpfChart)) {
log.info("绗簩涓槸鏉″舰");
setMAQcanvasChart(p_Task31, p_People32, xwpfChart);
}
-
+
XWPFChart xwpfChartLeadershipFourSided = charts.get(1);
if (!setMAQcanvasChart(p_Task31, p_People32, xwpfChartLeadershipFourSided)) {
log.info("绗竴涓槸鐢诲竷");
@@ -1567,18 +1580,18 @@
}
return true;
}
-
+
private String getTemplateDownLoadPath(String fileName) {
-
+
return EssConfig.getReportTemplates() + fileName;
}
-
+
private static String getTemplateDownLoadPathByUpLoad(String fileName) {
return EssConfig.getUploadPath() + fileName;
}
-
+
public static String getTemplatePicture(String pictureName) {
-
+
return EssConfig.getReportTemplates() + pictureName;
}
private static void closeChannel(InputStream inputStream) {
@@ -1600,19 +1613,19 @@
}
}
public File getAbsoluteFileZipByName(String filename) {
- String downloadPath = EssConfig.getDownloadPath() + filename;
+ String downloadPath = EssConfig.getDownloadPath() + "/" + filename;
File desc = new File(downloadPath);
if (!desc.getParentFile().exists()) {
desc.getParentFile().mkdirs();
}
return desc;
}
-
+
public static void insertNextPageChar(XWPFDocument document) {
XWPFParagraph paragraph = document.createParagraph();
-
+
CTPPr ctpPr = paragraph.getCTP().addNewPPr();
-
+
ctpPr.addNewSectPr();
}
@@ -1627,7 +1640,7 @@
Boolean isBold = Objects.nonNull(oldRun) ? oldRun.isBold() : false;
for (int i = 0, size = dataList.size(); i < size; i++) {
Object text = dataList.get(i);
-
+
if (i == 0) {
placeholderValue = String.valueOf(text);
} else {
@@ -1645,12 +1658,12 @@
}
return placeholderValue;
}
-
+
public static XWPFParagraph createParagraph(XWPFParagraph oldParagraph, XWPFDocument templateDoc, XWPFRun oldRun, boolean isBold, String... texts) {
-
+
XmlCursor cursor = oldParagraph.getCTP().newCursor();
XWPFParagraph newPar = templateDoc.insertNewParagraph(cursor);
-
+
newPar.getCTP().setPPr(oldParagraph.getCTP().getPPr());
copyParagraph(oldParagraph, newPar, oldRun, isBold, texts);
return newPar;
@@ -1678,22 +1691,22 @@
return null;
}
-
+
private static void copyParagraph(XWPFParagraph sourcePar, XWPFParagraph targetPar, XWPFRun oldRun, boolean isBold, String... texts) {
targetPar.setAlignment(sourcePar.getAlignment());
targetPar.setVerticalAlignment(sourcePar.getVerticalAlignment());
-
+
targetPar.setAlignment(sourcePar.getAlignment());
targetPar.setVerticalAlignment(sourcePar.getVerticalAlignment());
if (texts != null && texts.length > 0) {
String[] arr = texts;
-
+
for (int i = 0, len = texts.length; i < len; i++) {
String text = arr[i];
XWPFRun run = targetPar.createRun();
run.setText(text);
-
+
run.setFontFamily(oldRun.getFontFamily());
int fontSize = oldRun.getFontSize();
run.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize);
@@ -1713,12 +1726,12 @@
jaqTableStyle.setTableNum(tableNum);
Map<Integer, String> rowColorMap = new HashMap<>();
jaqTableStyle.setRowColorMap(rowColorMap);
-
+
for (Integer i = 1; i <= inum; i++) {
if (Objects.equals(textMap.get(line + i.toString() + "C"), "1")) {
rowColorMap.put(i, "C00000");
}
-
+
}
if (CollUtil.isNotEmpty(rowColorMap)) {
diff --git a/src/main/java/com/ots/framework/web/controller/BaseController.java b/src/main/java/com/ots/framework/web/controller/BaseController.java
index 7f88ce7..eb95146 100644
--- a/src/main/java/com/ots/framework/web/controller/BaseController.java
+++ b/src/main/java/com/ots/framework/web/controller/BaseController.java
@@ -1,4 +1,5 @@
package com.ots.framework.web.controller;
+import cn.hutool.core.util.URLUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ots.common.utils.DateUtils;
@@ -11,9 +12,19 @@
import com.ots.framework.web.page.TableDataInfo;
import com.ots.framework.web.page.TableSupport;
import com.ots.project.system.user.domain.User;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.beans.PropertyEditorSupport;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
@@ -112,4 +123,39 @@
}
return json;
}
+
+ public void downDeviceManagementTemplate(String fileName, String path , HttpServletRequest req, HttpServletResponse res) throws UnsupportedEncodingException {
+ // 璇诲彇鏈嶅姟鍣ㄧ妯℃澘鏂囦欢
+ // ClassPathResource绫荤殑鏋勯�犳柟娉曟帴鏀惰矾寰勫悕绉帮紝鑷姩鍘籧lasspath璺緞涓嬫壘鏂囦欢
+ ClassPathResource classPathResource = new ClassPathResource(path);
+
+ //鍒涘缓涓存椂鏂囦欢
+ XSSFWorkbook workbook = null;
+ try (InputStream inputStream = classPathResource.getInputStream()) {
+ // 杞负POI鐨刉orkbook杈撳嚭娴侊紝杩欐牱涓嬭浇鍚� 鎵撳紑涓嶆姤閿欙紝鐩存帴杈撳嚭 娴� 鐨勮瘽锛屾墦寮�excel鍙兘鎻愮ず閿欒
+ workbook = new XSSFWorkbook(inputStream);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException("妯℃澘涓嬭浇寮傚父");
+ }
+ String userAgent = req.getHeader("User-Agent");
+ // 閽堝IE鎴栬�呬互IE涓哄唴鏍哥殑娴忚鍣細
+ if(userAgent.contains("MSIE")||userAgent.contains("Trident")) {
+ fileName = URLUtil.encode(fileName, Charset.forName("UTF-8"));
+ } else {
+ // 闈濱E娴忚鍣ㄧ殑澶勭悊锛�
+ fileName = new String(fileName.getBytes("UTF-8"),"ISO-8859-1");
+ }
+ res.setHeader("Content-disposition", "attachment; filename=" + fileName);
+ res.setContentType("application/vnd.ms-excel; charset=utf-8");
+ res.setCharacterEncoding("UTF-8");
+ // 灏嗘祦涓唴瀹瑰啓鍑哄幓
+ try (OutputStream outputStream = res.getOutputStream()) {
+ workbook.write(outputStream);
+ outputStream.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException("妯℃澘涓嬭浇寮傚父");
+ }
+ }
}
diff --git a/src/main/java/com/ots/project/exam/domain/TReportTemplate.java b/src/main/java/com/ots/project/exam/domain/TReportTemplate.java
index dbce834..828bc8f 100644
--- a/src/main/java/com/ots/project/exam/domain/TReportTemplate.java
+++ b/src/main/java/com/ots/project/exam/domain/TReportTemplate.java
@@ -23,5 +23,11 @@
@Excel(name = "妯℃澘鍦板潃")
private String location;
+
private MultipartFile locationFile;
+
+ /**
+ * 鏁版嵁鍦板潃
+ */
+ private String dataPath;
}
diff --git a/src/main/java/com/ots/project/tool/PdfUtil.java b/src/main/java/com/ots/project/tool/PdfUtil.java
index e960caa..5bd4622 100644
--- a/src/main/java/com/ots/project/tool/PdfUtil.java
+++ b/src/main/java/com/ots/project/tool/PdfUtil.java
@@ -48,7 +48,7 @@
public static void main(String[] args) {
//convertPDF("D:\\娴嬭瘎绯荤粺\\home\\鏋梍PAQ_GS_TH.docx");
- convertPDF("D:\\娴嬭瘎绯荤粺\\home\\uploadPath\\娴嬭瘯2_PAQ_GS_CN.docx");
+ convertPDF("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\娴嬭瘯_MAQTR_IA_EN.docx");
}
}
diff --git a/src/main/java/com/ots/project/tool/report/MAQ/base/RowData.java b/src/main/java/com/ots/project/tool/report/MAQ/base/RowData.java
index 89a1ab0..42d0fd5 100644
--- a/src/main/java/com/ots/project/tool/report/MAQ/base/RowData.java
+++ b/src/main/java/com/ots/project/tool/report/MAQ/base/RowData.java
@@ -10,8 +10,6 @@
* @create: 2021-06-07 23:30
**/
@Data
-@NoArgsConstructor //鏃犲弬鏋勯��
-@AllArgsConstructor //鏈夊弬鏋勯��
public class RowData {
public String name;
@@ -20,4 +18,23 @@
*/
public double value;
+ public String valueStr;
+
+ public RowData() {
+ }
+
+ public RowData(String name) {
+ this.name = name;
+ }
+
+ public RowData(String name, double value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public RowData(String name, double value, String valueStr) {
+ this.name = name;
+ this.value = value;
+ this.valueStr = valueStr;
+ }
}
diff --git a/src/main/java/com/ots/project/tool/report/MAQ/base/SeriesData.java b/src/main/java/com/ots/project/tool/report/MAQ/base/SeriesData.java
index 8f92d0d..0fbb2ef 100644
--- a/src/main/java/com/ots/project/tool/report/MAQ/base/SeriesData.java
+++ b/src/main/java/com/ots/project/tool/report/MAQ/base/SeriesData.java
@@ -23,4 +23,7 @@
public List<RowData> value;
+ public SeriesData(String name) {
+ this.name = name;
+ }
}
diff --git a/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java b/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java
new file mode 100644
index 0000000..f03f3e5
--- /dev/null
+++ b/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java
@@ -0,0 +1,421 @@
+package com.ots.project.tool.report.MAQTR.chart;
+
+import com.alibaba.fastjson.JSON;
+import com.ots.common.utils.StringUtils;
+import com.ots.project.tool.report.MAQ.base.RowData;
+import com.ots.project.tool.report.MAQ.base.SeriesData;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ooxml.POIXMLDocument;
+import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.xwpf.usermodel.XWPFChart;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.openxmlformats.schemas.drawingml.x2006.chart.*;
+
+import java.io.*;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @description: MAQTR鍥捐〃 甯︾洿绾垮拰鏁版嵁鏍囪鏁g偣鍥炬暟鎹彉鏇�
+ * @author: zhijie
+ * @create: 2022-06-16 22:01
+ **/
+@Slf4j
+public class MAQTRChart {
+
+
+ public static void main(String[] args) throws IOException {
+ try {
+ OutputStream os = new FileOutputStream("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\鏋梍PAQ_IA_CN1.docx");
+ XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\缁堢銆�0607涓枃鐗堛�慚AQ缁勫埆瀵规瘮鎶ュ憡.docx"));
+
+ String fileName = "C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\MAQ缁勫埆瀵煎叆鏁版嵁妯℃澘.xlsx";
+ //鍙樻洿鍥捐〃鏁版嵁
+ changeMAQTRChart(document,fileName);
+ document.write(os);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 鍒濆鍖栨姤鍛婃暟鎹�
+ * @param fileName 鏁版嵁婧愭枃浠跺悕
+ * @param index 妯℃澘sheet绱㈠紩
+ * @return
+ */
+ public static List<SeriesData> initData(String fileName,Integer index){
+ List<SeriesData> seriesDatas = new ArrayList<>();
+ try {
+ XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(fileName));
+ XSSFSheet sheet1 = wb.getSheetAt(index);
+
+ //鏁版嵁澶勭悊 鍏堣幏鍙栬〃澶撮暱搴� 閬嶅巻琛ㄥご琛屾暟銆佷竴涓�瀵瑰簲鏀捐繘琛ㄥご闆嗗悎閲�
+ Map<Integer,SeriesData> map = new HashMap<>();
+ XSSFRow row = sheet1.getRow(0);
+ for (int i = 0; i < row.getLastCellNum(); i++) {
+ //涓虹┖蹇界暐
+ /*if(StringUtils.isEmpty(getName(row.getCell(i)))){
+ continue;
+ }*/
+ SeriesData seriesData = new SeriesData(getName(row.getCell(i)));
+ map.put(i,seriesData);
+ //璇诲彇姣忎竴琛屾瘡涓�鍒�
+ for (int j = 1; j <= sheet1.getLastRowNum(); j++) {
+ //姣忎竴琛�
+ XSSFRow row1 = sheet1.getRow(j);
+ RowData rowData = new RowData();
+ if(seriesData.getValue() == null){
+ List<RowData> rowDatas = new ArrayList<>();
+ //璁剧疆琛ㄥご
+ rowData.setName(getName(row.getCell(i)));
+ //鏍规嵁绫诲瀷鍒ゆ柇璧嬪��
+ switch (row1.getCell(i).getCellType()) {
+ case STRING:
+ rowData.setValueStr(row1.getCell(i).getStringCellValue());
+ break;
+ case NUMERIC:
+ rowData.setValue(row1.getCell(i).getNumericCellValue());
+ break;
+ default:
+ break;
+ }
+ rowDatas.add(rowData);
+ seriesData.setValue(rowDatas);
+ }else{
+ //璁剧疆琛ㄥご
+ rowData.setName(getName(row.getCell(i)));
+ //鏍规嵁绫诲瀷鍒ゆ柇璧嬪��
+ switch (row1.getCell(i).getCellType()) {
+ case STRING:
+ rowData.setValueStr(row1.getCell(i).getStringCellValue());
+ break;
+ case NUMERIC:
+ rowData.setValue(row1.getCell(i).getNumericCellValue());
+ break;
+ default:
+ break;
+ }
+ seriesData.getValue().add(rowData);
+ }
+ }
+ seriesDatas.add(seriesData);
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return seriesDatas;
+ }
+
+ /**
+ * 鏍规嵁鍗曞厓鏍肩被鍨嬪彇鍊�
+ * @return 杩斿洖瀛楃鍊�
+ */
+ private static String getName(XSSFCell cell){
+ String name = null;
+ switch (cell.getCellType()) {
+ case STRING:
+ name = cell.getStringCellValue();
+ break;
+ case NUMERIC:
+ name = cell.getNumericCellValue()+"";
+ break;
+ }
+ return name;
+ }
+
+ /**
+ * 鏇挎崲MAQTR鍥捐〃鏁版嵁
+ * @param document 鏂囨。瀵硅薄
+ * @param fileName 鏁版嵁婧恊xcel
+ */
+ public static void changeMAQTRChart(XWPFDocument document,String fileName) {
+ if(StringUtils.isEmpty(fileName)){
+ return;
+ }
+ try {
+ List<POIXMLDocumentPart> relations = document.getRelations();
+ for (POIXMLDocumentPart part : relations) {
+ if (part instanceof XWPFChart) {
+ // 鍥捐〃鍏冪礌
+ XWPFChart chart = (XWPFChart) part;
+ String partName = chart.getPackagePart().getPartName().getName();
+
+ Integer index = 0;
+ if(partName.contains("chart1.xml")){
+ index = 0;
+ }else if(partName.contains("chart2.xml")){
+ index = 1;
+ }
+ //鑾峰彇妯℃澘鏁版嵁
+ List<SeriesData> seriesDatas = initData(fileName,index);
+ //鏁版嵁闀垮害
+ int size = seriesDatas.size();
+ // 鏌ョ湅閲岄潰鐨勫浘琛ㄦ暟鎹紝鎵嶈兘鐭ラ亾鏄粈涔堝浘琛�
+ CTPlotArea plot = chart.getCTChart().getPlotArea();
+ // excel鍐呯疆琛ㄦ牸
+ XSSFWorkbook workbook = chart.getWorkbook();
+ XSSFSheet sheet = workbook.getSheetAt(0);
+
+ //鏁g偣鍥�
+ if (!plot.getScatterChartList().isEmpty()) {
+ CTScatterChart scatterChart = plot.getScatterChartArray(0);
+
+ //鍘婚櫎澶氫綑鏁版嵁婧�
+ int remain = 8 - size;
+ if(remain != 0){
+ for (int j = 1; j <= remain; j++) {
+ int removeSize = scatterChart.getSerList().size() - j - 1;
+ scatterChart.getSerList().remove(removeSize);
+ //鍒犻櫎excel澶氫綑鍒�
+ //deleteColumn(sheet,8 - remain);
+ }
+ }
+
+ //鍒锋柊鍐呯疆excel鏁版嵁
+ refreshExcel(seriesDatas, sheet);
+ workbook.write(chart.getPackagePart().getOutputStream());
+
+ //鏁g偣鍥炬暟鎹簮 XY鍧愭爣
+ for (int i = 0; i < scatterChart.getSerList().size(); i++) {
+ //鏍规嵁鍥捐〃鏁版嵁绾胯幏鍙栧搴旀暟鎹簮 鏁板�兼槸X杞� 杈呭姪Y杞�
+ List<SeriesData> scatterDatas = new ArrayList<SeriesData>();
+ //鏈�鍚庝竴涓暟鎹簮闇�鎷垮彇鏈�鍚庝竴鍒�0000 浣滀负x杞�
+ if((i+1) == size-2){
+ scatterDatas.add(seriesDatas.get(size-1));
+ scatterDatas.add(seriesDatas.get(size-2));
+ }else{
+ scatterDatas.add(seriesDatas.get(i+1));
+ scatterDatas.add(seriesDatas.get(size-2));
+ }
+
+ CTScatterSer ser = scatterChart.getSerList().get(i);
+ updateScatterChart(scatterDatas, ser.getXVal(), ser.getYVal());
+ }
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ log.error("MAQTR鏇挎崲word鍥捐〃 鏁g偣鍥惧浘褰㈠け璐ワ細{}",e);
+ }
+ }
+
+ /**
+ * 鍒犻櫎鍒�
+ * @param sheet
+ * @param columnToDelete
+ */
+ public static void deleteColumn(XSSFSheet sheet, int columnToDelete) {
+ for (int r = 0; r <= sheet.getLastRowNum(); r++) {
+ XSSFRow row = sheet.getRow(r);
+ for (int c = columnToDelete; c <= row.getLastCellNum(); c++) {
+ XSSFCell cOld = row.getCell(c);
+ if (cOld != null) {
+ row.removeCell(cOld);
+ }
+ XSSFCell cNext = row.getCell(c + 1);
+ if (cNext != null) {
+ XSSFCell cNew = row.createCell(c, cNext.getCellType());
+ cloneCell(cNew, cNext);
+ if (r == 0) {
+ sheet.setColumnWidth(c, sheet.getColumnWidth(c + 1));
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 鍙宠竟鍒楀乏绉�,鏍峰紡鍊艰缃�
+ * @param cNew
+ * @param cOld
+ */
+ private static void cloneCell(XSSFCell cNew, XSSFCell cOld) {
+ cNew.setCellComment(cOld.getCellComment());
+ cNew.setCellStyle(cOld.getCellStyle());
+ if (CellType.BOOLEAN == cNew.getCellType()) {
+ cNew.setCellValue(cOld.getBooleanCellValue());
+ } else if (CellType.NUMERIC == cNew.getCellType()) {
+ cNew.setCellValue(cOld.getNumericCellValue());
+ } else if (CellType.STRING == cNew.getCellType()) {
+ cNew.setCellValue(cOld.getStringCellValue());
+ } else if (CellType.ERROR == cNew.getCellType()) {
+ cNew.setCellValue(cOld.getErrorCellValue());
+ } else if (CellType.FORMULA == cNew.getCellType()) {
+ cNew.setCellValue(cOld.getCellFormula());
+ }
+ }
+
+ /**
+ * 鏇存柊鍥捐〃鐨勫叧鑱� excel
+ *
+ * @param seriesDatas
+ * @param sheet
+ */
+ protected static void refreshExcel(List<SeriesData> seriesDatas, XSSFSheet sheet) {
+ XSSFRow title = sheet.getRow(0);
+ //閬嶅巻鏁版嵁鏁扮粍杩涜excel璧嬪��
+ for (int i = 0; i < seriesDatas.size(); i++) {
+ SeriesData data = seriesDatas.get(i);
+ if (data.name != null && !data.name.isEmpty()) {
+ // 绗竴琛屾爣棰�
+ XSSFCell cell = title.getCell(i);
+ if (cell == null) {
+ cell = title.createCell(i + 1);
+ }
+ cell.setCellValue(data.name);
+ }
+ int size = data.value.size();
+ //閬嶅巻鏁版嵁杩涜璧嬪��
+ for (int j = 0; j < size; j++) {
+ //浠庣浜岃寮�濮嬭祴鍊�
+ XSSFRow row = sheet.getRow(j + 1);
+ if (row == null) {
+ row = sheet.createRow(j + 1);
+ }
+ RowData cellValu = data.value.get(j);
+
+ //绗竴鍒楀紑濮嬭祴鍊�
+ XSSFCell cell = row.getCell(i);
+ if (cell == null) {
+ cell = row.createCell(i);
+ }
+ //浼樺厛浣跨敤瀛楃涓插��
+ if(StringUtils.isNotEmpty(cellValu.valueStr)){
+ cell.setCellValue(cellValu.valueStr);
+ }else{
+ cell.setCellValue(cellValu.value);
+ }
+
+ }
+ //鍒犻櫎澶氫綑琛屾暟
+ int lastRowNum = sheet.getLastRowNum();
+ //log.error("lastRowNum:{},size:{}",lastRowNum,size);
+ if (lastRowNum > size) {
+ for (int idx = lastRowNum; idx > size; idx--) {
+ sheet.removeRow(sheet.getRow(idx));
+ }
+ }
+ }
+ }
+
+
+ /**
+ * 鏇存柊 鏁g偣鍥� 缂撳瓨鏁版嵁
+ *
+ * @param seriesDatas 鏁版嵁
+ * @param xDataSource X鍧愭爣鏁版嵁缂撳瓨
+ * @param yDataSource Y鍧愭爣鏁版嵁缂撳瓨
+ */
+ protected static void updateScatterChart(List<SeriesData> seriesDatas, CTAxDataSource xDataSource,
+ CTNumDataSource yDataSource) {
+
+ //鑾峰彇xy鍧愭爣鏁版嵁鏉℃暟
+ long xNumCnt = xDataSource.getNumRef().getNumCache().getPtCount().getVal();
+ long yNumCnt = yDataSource.getNumRef().getNumCache().getPtCount().getVal();
+
+ //鑾峰彇XY鏈�鏂版暟鎹�
+ List<RowData> xRowDatas = seriesDatas.get(0).getValue();
+ int xRowDataSize = xRowDatas.size();
+ List<RowData> yRowDatas = seriesDatas.get(1).getValue();
+ int yRowDataSize = yRowDatas.size();
+
+ //鏇存柊X鍧愭爣缂撳瓨
+ for (int i = 0; i < xRowDatas.size(); i++) {
+ RowData cellValu = xRowDatas.get(i);
+ CTNumVal val = xNumCnt > i ? xDataSource.getNumRef().getNumCache().getPtArray(i)
+ : xDataSource.getNumRef().getNumCache().addNewPt();
+ val.setIdx(i);
+ val.setV(String.format("%.0f", cellValu.value));
+ }
+
+ //鏇存柊Y鍧愭爣缂撳瓨
+ for (int i = 0; i < yRowDatas.size(); i++) {
+ RowData cellValu = yRowDatas.get(i);
+ CTNumVal val = yNumCnt > i ? yDataSource.getNumRef().getNumCache().getPtArray(i)
+ : yDataSource.getNumRef().getNumCache().addNewPt();
+ val.setIdx(i);
+ val.setV(String.format("%.0f", cellValu.value));
+ }
+
+ // 鏇存柊瀵瑰簲excel鐨勮寖鍥�
+ xDataSource.getNumRef().setF(
+ replaceRowEnd(xDataSource.getNumRef().getF(),
+ xNumCnt,
+ xRowDataSize));
+ yDataSource.getNumRef().setF(
+ replaceRowEnd(yDataSource.getNumRef().getF(),
+ yNumCnt,
+ yRowDataSize));
+
+ // 鍒犻櫎澶氱殑
+ if (xNumCnt > xRowDataSize) {
+ for (int idx = xRowDataSize; idx < xNumCnt; idx++) {
+ xDataSource.getNumRef().getNumCache().removePt(xRowDataSize);
+ }
+ }
+ if (yNumCnt > yRowDataSize) {
+ for (int idx = yRowDataSize; idx < yNumCnt; idx++) {
+ yDataSource.getNumRef().getNumCache().removePt(yRowDataSize);
+ }
+ }
+ // 鏇存柊涓暟
+ xDataSource.getNumRef().getNumCache().getPtCount().setVal(xRowDataSize);
+ // 鏇存柊涓暟
+ yDataSource.getNumRef().getNumCache().getPtCount().setVal(yRowDataSize);
+ }
+
+
+ /**
+ * 鏇挎崲 褰㈠锛� Sheet1!$A$2:$A$4 鐨勫瓧绗�
+ *
+ * @param range
+ * @return
+ */
+ public static String replaceRowEnd(String range, long oldSize, long newSize) {
+ Pattern pattern = Pattern.compile("(:\\$[A-Z]+\\$)(\\d+)");
+ Matcher matcher = pattern.matcher(range);
+ if (matcher.find()) {
+ long old = Long.parseLong(matcher.group(2));
+ return range.replaceAll("(:\\$[A-Z]+\\$)(\\d+)", "$1" + Long.toString(old - oldSize + newSize));
+ }
+ return range;
+ }
+
+ /**
+ * 鑾峰彇鍥捐〃鏈夊摢浜涚被鍨�
+ * @param part
+ */
+ public static void getChartType(POIXMLDocumentPart part){
+ XWPFChart chart = (XWPFChart) part;
+ //鏍规嵁灞炴�х涓�鍒楀悕绉板垏鎹㈡暟鎹被鍨�
+ CTChart ctChart = chart.getCTChart();
+ CTPlotArea plotArea = ctChart.getPlotArea();
+
+ if (!plotArea.getBarChartList().isEmpty()) {
+ System.out.println("鏌辩姸鍥緖"+plotArea.getBarChartList().size()+"}");
+ }
+ if (!plotArea.getPieChartList().isEmpty()) {
+ System.out.println("楗煎浘{"+plotArea.getPieChartList().size()+"}");
+ }
+ if (!plotArea.getLineChartList().isEmpty()) {
+ System.out.println("绾垮舰鍥緖"+plotArea.getLineChartList().size()+"}");
+ }
+ if (!plotArea.getBar3DChartList().isEmpty()) {
+ System.out.println("鏌辩姸鍥�3D{"+plotArea.getBar3DChartList().size()+"}");
+ }
+ if (!plotArea.getScatterChartList().isEmpty()) {
+ System.out.println("鏁g偣鍥緖"+plotArea.getScatterChartList().size()+"}");
+ }
+ }
+
+}
--
Gitblit v1.9.1