文件下载

This commit is contained in:
2023-03-07 13:53:43 +08:00
parent 4b48e7f55e
commit bc3cd91c6a
23 changed files with 677 additions and 265 deletions

View File

@ -58,6 +58,8 @@ public class BarChart
XWPFParagraph paragraph = header.createParagraph();
paragraph.setAlignment(ParagraphAlignment.BOTH); //设置段落左对齐
paragraph.setBorderBottom(Borders.THICK); //设置下划线
// paragraph.setSpacingLineRule(LineSpacingRule.AUTO);
paragraph.setSpacingBetween(40,LineSpacingRule.EXACT);
// paragraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run = paragraph.createRun();
@ -66,7 +68,7 @@ public class BarChart
/*
* 取到图片的字节流
* */
String logoFilePath="/home/sjs/ruoyi/shate/jpg/shate.png";
String logoFilePath="shate.png";
if (StringUtils.isNotEmpty(logoFilePath)) {
File file=new File(logoFilePath);
InputStream is = new FileInputStream(file);
@ -126,21 +128,12 @@ public class BarChart
}
public static void drawTable(XWPFDocument document, String[] xAxisData,Double[] yAxisData) throws Exception {
/*int numOfPoints = categories.length;
String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
String valuesDataRangeA = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
String valuesDataRangeB = chart.formatRange(new CellRangeAddress(1, numOfPoints, 2, 2));
XDDFDataSource<String> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
XDDFNumericalDataSource<Double> valuesDataA = XDDFDataSourcesFactory.fromArray(valuesA, valuesDataRangeA, 1);
XDDFNumericalDataSource<Double> valuesDataB = XDDFDataSourcesFactory.fromArray(valuesB, valuesDataRangeB, 2);*/
// 创建chart图表对象,抛出异常
XWPFChart chart = document.createChart(15 * Units.EMU_PER_CENTIMETER, 10 * Units.EMU_PER_CENTIMETER);
// 图表相关设置
chart.setTitleText(""); // 图表标题
// XWPFChart chart = document.createChart(15 * Units.EMU_PER_CENTIMETER, 10 * Units.EMU_PER_CENTIMETER);
XWPFChart chart=document.createChart(15 * Units.EMU_PER_CENTIMETER, 11 * Units.EMU_PER_CENTIMETER);
chart.setTitleText("");
chart.setTitleOverlay(false); // 图例是否覆盖标题
//XDDFChartLegend legend = chart.getOrAddLegend();
//legend.setPosition(LegendPosition.TOP); // 图例位置:上下左右
chart.setChartBottomMargin(50);
// X轴(分类轴)相关设置
XDDFCategoryAxis xAxis =chart.createCategoryAxis(AxisPosition.BOTTOM); // 创建X轴,并且指定位置
xAxis.setTitle(""); // x轴标题
@ -158,9 +151,11 @@ public class BarChart
barChart.setVaryColors(false);
// 加载柱状图数据集
XDDFBarChartData.Series barSeries = (XDDFBarChartData.Series) barChart.addSeries(xAxisSource, yAxisSource);
barSeries.setTitle(" ", null); // 图例标题
barSeries.setTitle(" ", null); // 图例标题
// 绘制柱状图
chart.plot(barChart);
}
//插入图片
@ -219,13 +214,25 @@ public class BarChart
public static void setPicTitle(XWPFDocument document,String date)
{
XWPFParagraph Paragraph = document.createParagraph();
// Paragraph.setAlignment(ParagraphAlignment.CENTER);
//// 边框
// Paragraph.setBorderBottom(Borders.NIL);
// Paragraph.setBorderTop(Borders.NIL);
// Paragraph.setBorderRight(Borders.NIL);
// Paragraph.setBorderLeft(Borders.NIL);
// Paragraph.setBorderBetween(Borders.SINGLE);
// Paragraph.setSpacingAfter(5);
// Paragraph.setSpacingBeforeLines(5);
// Paragraph.setSpacingBetween(5);
Paragraph.setAlignment(ParagraphAlignment.CENTER);//对齐方式
//BarChart.setLineSpace(Paragraph,30);
BarChart.setLineSpace(Paragraph,25);
XWPFRun run = Paragraph.createRun();
// run.addCarriageReturn();
run.setText(date);
run.setBold(true);//加粗
run.setFontSize(10);
run.setFontFamily("Times New Roman");
// run.setFontFamily("Times New Roman");
}
//设置题目
public static void setTitle(XWPFDocument document,String date)