style(自定义对比): 导出xls
This commit is contained in:
+15
-12
@@ -37,10 +37,10 @@ import com.jero.modules.system.entity.SysDictItem;
|
||||
import com.jero.modules.system.service.ISysDictItemService;
|
||||
import com.jero.modules.system.service.ISysDictService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -78,6 +78,7 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
private final IOSSFileService iossFileService;
|
||||
public static final String STANDARD_NUMBER = "standard_number";
|
||||
public static final String IS_SHOW = "is_show";
|
||||
public static final String EXPORT_EXCEL_TEMP = "exportExcelTemp";
|
||||
|
||||
public LawsCustomCompareInfoServiceImpl(LawsCustomCompareInfoMapper lawsCustomCompareInfoMapper,
|
||||
ILawsCustomCompareInfoStandardService lawsCustomCompareInfoStandardService,
|
||||
@@ -367,10 +368,12 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
// 获取单元格内容
|
||||
List<LawsCustomCompareCell> list = tableDetailVO.getList();
|
||||
|
||||
try (Workbook workbook = new XSSFWorkbook()){
|
||||
String fileName = "清单详情.xlsx";
|
||||
|
||||
// Workbook workbook = new XSSFWorkbook()
|
||||
try (Workbook workbook = new HSSFWorkbook()){
|
||||
String fileName = "清单详情.xls";
|
||||
// sheet页
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("清单详情");
|
||||
HSSFSheet sheet = (HSSFSheet) workbook.createSheet("清单详情");
|
||||
// 列宽
|
||||
sheet.setDefaultColumnWidth(20);
|
||||
|
||||
@@ -386,7 +389,7 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
createTableSecondRow(sheet, standardVOS, featureList, cellStyle);
|
||||
// 创建单元格内容
|
||||
createTableCellContent(sheet, standardVOS, featureList, compareList, list, cellStyle);
|
||||
String exportPath = exportExcelTempPath.replace("exportExcelTemp", "清单详情");
|
||||
String exportPath = exportExcelTempPath.replace(EXPORT_EXCEL_TEMP, "清单详情");
|
||||
// excel临时保存到本地并在同级创建文件夹
|
||||
generateExcel(workbook, fileName, exportPath);
|
||||
// 生成zip文件返回文件流
|
||||
@@ -446,7 +449,7 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
.set(LawsCustomCompareInfo::getCreateTime, new Date()));
|
||||
}
|
||||
|
||||
private void createTableCellContent(XSSFSheet sheet, List<StandardVO> standardVOS, List<LawsCustomCompareInventory> featureList, List<LawsCustomCompareInventory> compareList, List<LawsCustomCompareCell> list, CellStyle cellStyle) {
|
||||
private void createTableCellContent(HSSFSheet sheet, List<StandardVO> standardVOS, List<LawsCustomCompareInventory> featureList, List<LawsCustomCompareInventory> compareList, List<LawsCustomCompareCell> list, CellStyle cellStyle) {
|
||||
for (int i = 2; i <= compareList.size() + 2; i++) {
|
||||
// 创建行
|
||||
Row indexRow = sheet.createRow(i);
|
||||
@@ -506,7 +509,7 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
|
||||
private void writeFile(LawsCustomCompareCell v) {
|
||||
if (StringUtils.isNotBlank(v.getFileId())){
|
||||
String exportPath = exportExcelTempPath.replace("exportExcelTemp", "清单详情");
|
||||
String exportPath = exportExcelTempPath.replace(EXPORT_EXCEL_TEMP, "清单详情");
|
||||
OSSFile ossFile = iossFileService.getById(v.getFileId());
|
||||
InputStream download = MinioUtil.download(ossFile.getUrl());
|
||||
inputStreamToFile(download, exportPath + File.separator + ossFile.getFileName());
|
||||
@@ -514,7 +517,7 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
}
|
||||
|
||||
public void inputStreamToFile (InputStream inputStream, String filePath) {
|
||||
String replacePath = exportExcelTempPath.replace("exportExcelTemp", "清单详情");
|
||||
String replacePath = exportExcelTempPath.replace(EXPORT_EXCEL_TEMP, "清单详情");
|
||||
File saveFile = new File(replacePath);
|
||||
// 导出路径 没有则创建
|
||||
if (!saveFile.exists()) {
|
||||
@@ -556,7 +559,7 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
* }
|
||||
*/
|
||||
|
||||
private static void createFeatureColumn(List<StandardVO> standardVOS, List<LawsCustomCompareInventory> featureList, Row indexRow, Cell indexCell, CellStyle cellStyle, XSSFSheet sheet) {
|
||||
private static void createFeatureColumn(List<StandardVO> standardVOS, List<LawsCustomCompareInventory> featureList, Row indexRow, Cell indexCell, CellStyle cellStyle, HSSFSheet sheet) {
|
||||
indexCell.setCellValue("特点/对比项");
|
||||
// 计算列数量
|
||||
int index = 0;
|
||||
@@ -582,7 +585,7 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
}
|
||||
}
|
||||
|
||||
private void createTableSecondRow(XSSFSheet sheet, List<StandardVO> standardVOS, List<LawsCustomCompareInventory> featureList, CellStyle cellStyle) {
|
||||
private void createTableSecondRow(HSSFSheet sheet, List<StandardVO> standardVOS, List<LawsCustomCompareInventory> featureList, CellStyle cellStyle) {
|
||||
// 创建第二行
|
||||
Row row = sheet.createRow(1);
|
||||
// 创建列
|
||||
@@ -613,7 +616,7 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
||||
}
|
||||
}
|
||||
|
||||
private void createTableHeader(XSSFSheet sheet, Map<String, List<StandardVO>> countryMap, List<LawsCustomCompareInventory> featureList, CellStyle cellStyle) {
|
||||
private void createTableHeader(HSSFSheet sheet, Map<String, List<StandardVO>> countryMap, List<LawsCustomCompareInventory> featureList, CellStyle cellStyle) {
|
||||
// 创建第一行
|
||||
Row headerRow = sheet.createRow(0);
|
||||
// 创建列
|
||||
|
||||
Reference in New Issue
Block a user