diff --git a/src/main/java/UnitTest/WordDocumentGenerator.java b/src/main/java/UnitTest/Word_ZheXianTu.java similarity index 70% rename from src/main/java/UnitTest/WordDocumentGenerator.java rename to src/main/java/UnitTest/Word_ZheXianTu.java index 44a525a4..aa0b6ddf 100644 --- a/src/main/java/UnitTest/WordDocumentGenerator.java +++ b/src/main/java/UnitTest/Word_ZheXianTu.java @@ -9,13 +9,18 @@ import java.io.*; import java.util.ArrayList; import java.util.List; -public class WordDocumentGenerator { +public class Word_ZheXianTu { public static void main(String[] args) throws Exception { + //模板 String templatePath = "D:\\word\\line-chart-template.docx"; + //目标 + String targetFilePath="D:\\word\\test.docx"; + //统计图的名称 + String chartTitle = "收运量统计图"; + //读取模板文件 InputStream is = new FileInputStream(templatePath); XWPFDocument doc = new XWPFDocument(is); - //模拟统计图数据 //系列 String[] seriesTitles = {"日处理能力(kg)", "湿垃圾(kg)", "干垃圾(kg)"}; @@ -33,22 +38,28 @@ public class WordDocumentGenerator { values.add(value2); values.add(value3); - XWPFChart xChart = doc.getCharts().get(0);//获取第1个图表 - generateChart(xChart, seriesTitles, categories, values); - - try (FileOutputStream fos = new FileOutputStream("D:\\word\\test.docx")) { - doc.write(fos); - } + //生成统计图 + XWPFChart xChart = doc.getCharts().getFirst();//获取第1个图表 + generateChart(chartTitle,xChart, seriesTitles, categories, values); + //保存到目标文件中 + FileOutputStream fos = new FileOutputStream(targetFilePath); + doc.write(fos); + fos.close(); } - public static void generateChart(XWPFChart chart, String[] series, String[] categories, List values) { - String chartTitle = "收运量统计图"; - final List data = chart.getChartSeries();//不知道这个ChartSeries代表什么意思 - final XDDFLineChartData line = (XDDFLineChartData) data.get(0);//这里一般获取第一个,我们这里是折线图就是XDDFLineChartData - + /** + * 生成统计图 + * @param chartTitle 图表标题 + * @param chart 使用哪个图表生成 + * @param series 系列 + * @param categories x轴 + * @param values 值 + */ + public static void generateChart(String chartTitle,XWPFChart chart, String[] series, String[] categories, List values) { + final List data = chart.getChartSeries(); + final XDDFLineChartData line = (XDDFLineChartData) data.getFirst();//这里一般获取第一个,我们这里是折线图就是XDDFLineChartData final int numOfPoints = categories.length; - final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0)); final XDDFDataSource categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0); @@ -62,7 +73,6 @@ public class WordDocumentGenerator { CellReference cellReference = chart.setSheetTitle(series[i], 1);//修改系列标题 ser.setTitle(series[i], cellReference); } - chart.plot(line); chart.setTitleText(chartTitle);//折线图标题 chart.setTitleOverlay(false); diff --git a/长春云校VPN/GWSetup.exe b/长春云校VPN/GWSetup.exe new file mode 100644 index 00000000..09bf18fd Binary files /dev/null and b/长春云校VPN/GWSetup.exe differ diff --git a/长春云校VPN/云校VPN.txt b/长春云校VPN/云校VPN.txt new file mode 100644 index 00000000..217b2892 --- /dev/null +++ b/长春云校VPN/云校VPN.txt @@ -0,0 +1 @@ +dsideal01/Superadmin@123 \ No newline at end of file diff --git a/长春云校VPN/长春云校VPN.docx b/长春云校VPN/长春云校VPN.docx new file mode 100644 index 00000000..870281a1 Binary files /dev/null and b/长春云校VPN/长春云校VPN.docx differ