前8行不读取
dart
public static Sheet convertDataListToSheetRemoveNineAndOne(List<Map<String, Object>> dataList) {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
for (int i = 0; i < 8; i++) {
sheet.createRow(i);
}
int rowIndex = 8;
for (Map<String, Object> data : dataList) {
Row row = sheet.createRow(rowIndex++);
int cellIndex = 0;
for (Map.Entry<String, Object> entry : data.entrySet()) {
Cell cell = row.createCell(cellIndex++);
setCellValue(cell, entry.getValue());
}
}
if (sheet.getRow(8) != null && sheet.getRow(8).getCell(0) != null) {
sheet.getRow(8).removeCell(sheet.getRow(8).getCell(0));
}
return sheet;
}
保存到本地工具类
dart
private static void saveSheetToFile(Sheet sheet, String fileName) {
// 获取工作簿对象
Workbook workbook = sheet.getWorkbook();
try (FileOutputStream fileOut = new FileOutputStream(fileName)) {
// 将工作簿写入文件输出流
workbook.write(fileOut);
System.out.println("Excel file has been generated successfully.");
} catch (IOException e) {
e.printStackTrace();
}
}
调用代码
dart
Sheet sheet = convertDataListToSheetRemoveNineAndOne(chartDateTto.getDataList());
// 保存 Sheet 到本地文件
saveSheetToFile(sheet, "C:/Users/Administrator/Desktop/老代码/output.xlsx");
List<List<String>> getdata = ExcelDataUtils.getData(sheet);
if (CollectionUtils.isEmpty(getdata)) {
return AjaxResult.error("请填充数据");
}
if (ObjectUtils.isEmpty(getdata.get(0).get(1))) {
return AjaxResult.error("请输入最小值");
}
if (ObjectUtils.isEmpty(getdata.get(1).get(1))) {
return AjaxResult.error("请输入最大值");
}
//3d折线图
ChartSmartVo chartV32 = getChartV32(ExcelDataUtils.getData(sheet), chartDateTto.getChartValue());
List<ChartSmartVo> newList = new ArrayList<>();
newList.add(chartV32);
return AjaxResult.success(newList);