背景
業務為實現自定義樣式excel的導出,常規的做法就是根據數據在代碼中進行類似模版的配置;這樣的體驗不是很好,只要用戶改變下樣式的設置不用代碼改動就能實現自定義excel的導出更加靈活。
以下是具體實現
pom依賴
<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>5.2.3</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.3</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId><version>4.1.2</version></dependency><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.11.0</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-api</artifactId><version>2.17.2</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.17.2</version></dependency><!-- HTML解析 --><dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.8.1</version></dependency>
控制器代碼
package com.longshare.microservice.file.support.service.impl;import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.longshare.microservice.file.support.ProblemCode;
import com.longshare.microservice.file.support.config.FileUploadConfig;
import com.longshare.microservice.file.support.service.FileConvertService;
import com.longshare.microservice.file.support.service.FileInfoService;
import com.longshare.microservice.file.support.utils.FileUtils;
import com.longshare.rest.core.problem.ProblemSolver;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.io.*;
import java.util.*;
import java.util.stream.Collectors;import com.longshare.file.share.model.vo.FileInformation;
import org.springframework.web.multipart.MultipartFile;@Service
@Slf4j
public class FileConvertServiceImpl implements FileConvertService {private final String DEFAULT_SHEET_NAME = "Sheet1";private final String DEFAULT_FONT_NAME = "微軟雅黑";private final short DEFAULT_FONT_SIZE = 12;// 修復默認表頭背景色(原代碼"#"會導致解析錯誤)private final String DEFAULT_HEADER_BACKGROUND = "#F0F0F0";@Autowiredprivate FileInfoService fileInfoService;@Autowiredprivate FileUploadConfig fileUploadConfig;@Overridepublic FileInformation convertWithConfig(String configJson) throws Exception {log.info("字符串大小:{} 字符串KB:{} 字符串MB:{}",configJson.length(),configJson.length()/1024+"KB",configJson.length()/1024/1024+"");boolean addIndex = false;boolean sortAscending = true;String sortBy = "排序號";Config config = parseConfig(configJson);String filename = config.getFileName();String typeId = config.getTypeId();if (StringUtils.isBlank(typeId)) {throw ProblemSolver.client(ProblemCode.NOT_TYPE_ID).build();}String outputDir = "D:\\tmp\\microframe\\upload\\";
// String outputDir = fileUploadConfig.getBasePath();log.info("outputDir:{}", outputDir);if (Objects.isNull(filename)) {filename = "configured_export";}File outputDirFile = new File(outputDir);if (!outputDirFile.exists()) {outputDirFile.mkdirs();}String outputPath = outputDir + File.separator + filename + ".xlsx";JSONArray dataArray = config.getExcelData();FileInformation fileInformation = new FileInformation();if (sortBy != null && !sortBy.isEmpty()) {sortDataArray(dataArray, sortBy, sortAscending);}Workbook workbook = new XSSFWorkbook();FileOutputStream fos = null;File tempFile = new File(outputPath);try {fos = new FileOutputStream(tempFile);Sheet sheet = workbook.createSheet(filename != null ? filename : DEFAULT_SHEET_NAME);HeaderConfig headerConfig = parseHeaderConfig(config.getHeader());writeDataToSheet(sheet, dataArray, headerConfig, addIndex);applyStyles(sheet, dataArray, headerConfig, addIndex);workbook.write(fos);log.info("Excel文件已生成:{}", outputPath);MultipartFile multipartFile = FileUtils.fileToMultipartFile(tempFile);log.info("multipartFile完成:{}", multipartFile.getOriginalFilename());fileInformation = fileInfoService.upload(multipartFile, null, typeId);log.info("上傳到文件中心完成---->:{}", fileInformation);} catch (Exception e) {log.error("處理Excel文件時發生錯誤: " + e.getMessage(), e);throw e;} finally {
// if (fos != null) {
// try {
// fos.close();
// } catch (IOException e) {
// log.error("關閉文件流時發生錯誤: " + e.getMessage(), e);
// }
// }
// if (tempFile.delete()) {
// log.info("臨時文件已刪除: " + outputPath);
// } else {
// log.error("嘗試刪除臨時文件失敗");
// }}return fileInformation;}@Overridepublic FileInformation htmlToWorld(MultipartFile multipartFile) {return null;}private static Config parseConfig(String configJson) throws Exception {try {boolean validJson = isValidJson(configJson);if (!validJson) {throw ProblemSolver.client(ProblemCode.NOT_JSON).build();}JSONObject configObj = JSON.parseObject(configJson);if (!configObj.containsKey("header") || !configObj.containsKey("excelData") || !configObj.containsKey("typeId")) {throw ProblemSolver.client(ProblemCode.NOT_TYPE_ID).build();}Config config = new Config();config.setHeader(configObj.getJSONObject("header"));config.setExcelData(configObj.getJSONArray("excelData"));config.setFileName(String.valueOf(configObj.get("fileName")));config.setTypeId(String.valueOf(configObj.get("typeId")));return config;} catch (Exception e) {log.error("解析配置文件失敗", e);throw new Exception("解析配置文件失敗: " + e.getMessage(), e);}}/*** 校驗字符串是否是有效的json字符串** @param jsonStr* @return*/public static boolean isValidJson(String jsonStr) {if (jsonStr == null || jsonStr.trim().isEmpty()) {return false;}jsonStr = jsonStr.trim();if (!(jsonStr.startsWith("{") && jsonStr.endsWith("}")) &&!(jsonStr.startsWith("[") && jsonStr.endsWith("]"))) {return false;}try {if (jsonStr.startsWith("{")) {JSON.parseObject(jsonStr);} else {JSON.parseArray(jsonStr);}return true;} catch (JSONException e) {return false;} catch (Exception e) {return false;}}private HeaderConfig parseHeaderConfig(JSONObject headerObj) {HeaderConfig headerConfig = new HeaderConfig();JSONObject normalSetting = headerObj.getJSONObject("normal_setting");if (normalSetting == null) {normalSetting = new JSONObject();}headerConfig.setNormalSetting(normalSetting);JSONObject customSetting = headerObj.getJSONObject("custom_setting");if (customSetting == null) {customSetting = new JSONObject();}headerConfig.setCustomSetting(customSetting);List<Map.Entry<String, Object>> sortedColumns = customSetting.entrySet().stream().sorted((e1, e2) -> {JSONObject conf1 = (JSONObject) e1.getValue();JSONObject conf2 = (JSONObject) e2.getValue();int index1 = conf1.getIntValue("index");int index2 = conf2.getIntValue("index");return Integer.compare(index1, index2);}).collect(Collectors.toList());List<String> columnOrder = new ArrayList<>();for (Map.Entry<String, Object> entry : sortedColumns) {columnOrder.add(entry.getKey());}headerConfig.setColumnOrder(columnOrder);return headerConfig;}private void writeDataToSheet(Sheet sheet, JSONArray dataArray, HeaderConfig headerConfig, boolean addIndex) {List<String> columnOrder = headerConfig.getColumnOrder();Set<String> allColumns = getAllColumnNames(dataArray);List<String> finalColumnOrder = new ArrayList<>();for (String col : columnOrder) {if (allColumns.contains(col)) {finalColumnOrder.add(col);}}for (String col : allColumns) {if (!finalColumnOrder.contains(col)) {finalColumnOrder.add(col);}}Row headerRow = sheet.createRow(0);headerRow.setHeightInPoints((float) Double.parseDouble(headerConfig.getNormalSetting().getString("header-row-height")));int colIndex = addIndex ? 1 : 0;if (addIndex) {Cell indexCell = headerRow.createCell(0);indexCell.setCellValue("索引");}for (String column : finalColumnOrder) {Cell cell = headerRow.createCell(colIndex++);cell.setCellValue(column);}for (int rowIndex = 0; rowIndex < dataArray.size(); rowIndex++) {Row dataRow = sheet.createRow(rowIndex + 1);colIndex = addIndex ? 1 : 0;if (addIndex) {Cell indexCell = dataRow.createCell(0);indexCell.setCellValue(rowIndex + 1);}JSONObject dataObj = dataArray.getJSONObject(rowIndex);for (String column : finalColumnOrder) {Cell cell = dataRow.createCell(colIndex++);if (dataObj.containsKey(column)) {Object value = dataObj.get(column);if (value != null) {setCellValue(cell, value);}}}}}/*** 應用樣式設置** @param sheet* @param dataArray* @param headerConfig* @param addIndex*/private void applyStyles(Sheet sheet, JSONArray dataArray, HeaderConfig headerConfig, boolean addIndex) {JSONObject normalSetting = headerConfig.getNormalSetting();JSONObject customSetting = headerConfig.getCustomSetting();List<String> columnOrder = headerConfig.getColumnOrder();Set<String> allColumns = getAllColumnNames(dataArray);List<String> finalColumnOrder = new ArrayList<>();for (String col : columnOrder) {if (allColumns.contains(col)) {finalColumnOrder.add(col);}}for (String col : allColumns) {if (!finalColumnOrder.contains(col)) {finalColumnOrder.add(col);}}int colOffset = addIndex ? 1 : 0;for (int i = 0; i < finalColumnOrder.size(); i++) {String columnName = finalColumnOrder.get(i);int colIdx = i + colOffset;JSONObject colConfig = customSetting.getJSONObject(columnName);if (colConfig == null) {colConfig = new JSONObject();}if (colConfig.containsKey("column_width")) {int pixelWidth = colConfig.getIntValue("column_width");double excelWidth = pixelWidth / 7.0;sheet.setColumnWidth(colIdx, (int) (excelWidth * 256));} else if (normalSetting.containsKey("width")) {int pixelWidth = normalSetting.getIntValue("width");double excelWidth = pixelWidth / 7.0;sheet.setColumnWidth(colIdx, (int) (excelWidth * 256));}}Row headerRow = sheet.getRow(0);if (headerRow != null) {for (int colIdx = 0; colIdx < finalColumnOrder.size(); colIdx++) {Cell headerCell = headerRow.getCell(colIdx + colOffset);if (headerCell != null) {applyHeaderCellStyle(headerCell.getSheet().getWorkbook(), headerCell, normalSetting);}}}for (int rowIdx = 1; rowIdx <= dataArray.size(); rowIdx++) {Row dataRow = sheet.getRow(rowIdx);if (dataRow != null) {for (int colIdx = 0; colIdx < finalColumnOrder.size(); colIdx++) {Cell cell = dataRow.getCell(colIdx + colOffset);if (cell != null) {String columnName = finalColumnOrder.get(colIdx);JSONObject colConfig = customSetting.getJSONObject(columnName);if (colConfig == null) {colConfig = new JSONObject();}applyDataCellStyle(cell.getSheet().getWorkbook(), cell, normalSetting, colConfig);}}}}}/*** 數據單元格樣式設置** @param workbook* @param cell* @param normalSetting* @param colConfig*/private void applyDataCellStyle(Workbook workbook, Cell cell, JSONObject normalSetting, JSONObject colConfig) {try {String fontName = normalSetting.containsKey("font-name") ?normalSetting.getString("font-name") : DEFAULT_FONT_NAME;short fontSize = DEFAULT_FONT_SIZE;if (normalSetting.containsKey("font-size")) {fontSize = (short) normalSetting.getIntValue("font-size");}boolean fontBold = normalSetting.containsKey("font-weight") &&"bold".equals(normalSetting.getString("font-weight"));Font font = workbook.createFont();font.setFontName(fontName);font.setFontHeightInPoints(fontSize);// POI 5.2.3使用setBold(boolean)替代setBoldweightfont.setBold(fontBold);if (normalSetting.containsKey("font-color")) {String fontColor = normalSetting.getString("font-color");
// if (fontColor.startsWith("#")) {
// fontColor = fontColor.substring(1);
// }try {if (workbook instanceof XSSFWorkbook) {byte[] rgb = getRgb(fontColor);if (rgb == null) {rgb = new byte[]{(byte) 0, (byte) 0, (byte) 0};}// POI 5.2.3 XSSFColor構造兼容處理((XSSFFont) font).setColor(new XSSFColor(rgb, null));}} catch (Exception e) {log.error("解析數據字體顏色失敗: " + fontColor, e);}}// 使用HorizontalAlignment枚舉替代CellStyle常量HorizontalAlignment hAlign;String align = colConfig.containsKey("column_align") ?colConfig.getString("column_align") : normalSetting.getString("align");switch (align) {case "center":hAlign = HorizontalAlignment.CENTER;break;case "right":hAlign = HorizontalAlignment.RIGHT;break;default:hAlign = HorizontalAlignment.LEFT;}CellStyle style = workbook.createCellStyle();style.setFont(font);style.setAlignment(hAlign);// 使用VerticalAlignment枚舉替代CellStyle常量style.setVerticalAlignment(VerticalAlignment.CENTER);if (normalSetting.containsKey("background-color")) {String bgColor = normalSetting.getString("background-color");try {if (workbook instanceof XSSFWorkbook) {byte[] rgb = getRgb(bgColor);if (rgb != null) {XSSFColor color = new XSSFColor(rgb, null);((XSSFCellStyle) style).setFillForegroundColor(color);// 使用FillPatternType枚舉替代CellStyle常量style.setFillPattern(FillPatternType.SOLID_FOREGROUND);}}} catch (Exception e) {log.error("解析數據背景顏色失敗: " + bgColor, e);}}style.setWrapText(normalSetting.getBoolean("line-wrap"));cell.setCellStyle(style);} catch (Exception e) {log.error("應用數據單元格樣式錯誤: " + e.getMessage(), e);}}/*** 更靈活的安全解析HTML顏色值為RGB數組** @param colorStr 顏色字符串,如 "#RRGGBB" 或 "#RGB"* @return RGB值數組 [R, G, B],解析失敗時返回 null*/public static byte[] getRgb(String colorStr) {if (colorStr == null || !colorStr.startsWith("#")) {
// log.error("顏色值格式不正確: {}", colorStr);return null;}String hex = colorStr.substring(1); // 去掉 # 符號int length = hex.length();try {if (length == 6) {// 標準的情況 #RRGGBB 格式int r = Integer.parseInt(hex.substring(0, 2), 16);int g = Integer.parseInt(hex.substring(2, 4), 16);int b = Integer.parseInt(hex.substring(4, 6), 16);return new byte[]{(byte) r, (byte) g, (byte) b}; // 轉換為 byte 類型} else if (length == 3) {// 若存在簡寫 #RGB 格式,擴展為 #RRGGBBint r = Integer.parseInt(hex.substring(0, 1) + hex.substring(0, 1), 16);int g = Integer.parseInt(hex.substring(1, 2) + hex.substring(1, 2), 16);int b = Integer.parseInt(hex.substring(2, 3) + hex.substring(2, 3), 16);return new byte[]{(byte) r, (byte) g, (byte) b}; // 轉換為 byte 類型} else {log.error("不支持的顏色格式: {}", colorStr);return null;}} catch (NumberFormatException | StringIndexOutOfBoundsException e) {log.error("解析顏色值失敗: {}", colorStr, e);return null;}}private void applyHeaderCellStyle(Workbook workbook, Cell cell, JSONObject normalSetting) {try {String fontName = normalSetting.containsKey("header-font-name") ?normalSetting.getString("header-font-name") : DEFAULT_FONT_NAME;short fontSize = DEFAULT_FONT_SIZE;if (normalSetting.containsKey("header-font-size")) {fontSize = (short) normalSetting.getIntValue("header-font-size");}boolean fontBold = normalSetting.containsKey("header-font-weight") &&"bold".equals(normalSetting.getString("header-font-weight"));Font font = workbook.createFont();font.setFontName(fontName);font.setFontHeightInPoints(fontSize);// POI 5.2.3使用setBold(boolean)替代setBoldweightfont.setBold(fontBold);if (normalSetting.containsKey("header-font-color")) {String fontColor = normalSetting.getString("header-font-color");try {if (workbook instanceof XSSFWorkbook) {byte[] rgb = getRgb(fontColor);if (rgb == null) {//表頭字體黑色rgb = new byte[]{(byte) 0, (byte) 0, (byte) 0};}((XSSFFont) font).setColor(new XSSFColor(rgb, null));}} catch (Exception e) {log.error("解析表頭字體顏色失敗: " + fontColor, e);}}// 使用HorizontalAlignment枚舉替代CellStyle常量HorizontalAlignment hAlign;String align = normalSetting.getString("header-align");switch (align) {case "center":hAlign = HorizontalAlignment.CENTER;break;case "right":hAlign = HorizontalAlignment.RIGHT;break;default:hAlign = HorizontalAlignment.LEFT;}CellStyle style = workbook.createCellStyle();style.setFont(font);style.setAlignment(hAlign);// 使用VerticalAlignment枚舉替代CellStyle常量style.setVerticalAlignment(VerticalAlignment.CENTER);String bgColor = DEFAULT_HEADER_BACKGROUND;if (normalSetting.containsKey("header-background-color")) {bgColor = normalSetting.getString("header-background-color");}try {if (workbook instanceof XSSFWorkbook) {byte[] rgb = getRgb(bgColor);if (rgb == null) {//表頭白色背景rgb = new byte[]{(byte) 255, (byte) 255, (byte) 255};}XSSFColor color = new XSSFColor(rgb, null);((XSSFCellStyle) style).setFillForegroundColor(color);style.setFillPattern(FillPatternType.SOLID_FOREGROUND);} else {style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());style.setFillPattern(FillPatternType.SOLID_FOREGROUND);}} catch (Exception e) {style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());style.setFillPattern(FillPatternType.SOLID_FOREGROUND);}// POI 5.2.3使用BorderStyle枚舉替代short值BorderStyle borderStyle = BorderStyle.THIN; // 默認細邊框if (normalSetting.containsKey("header-border")) {int borderThick = normalSetting.getIntValue("header-border");// 根據數值映射邊框樣式(1=細,2=中,3=粗)switch (borderThick) {case 2:borderStyle = BorderStyle.MEDIUM;break;case 3:borderStyle = BorderStyle.THICK;break;default:borderStyle = BorderStyle.THIN;}}style.setBorderTop(borderStyle);style.setBorderBottom(borderStyle);style.setBorderLeft(borderStyle);style.setBorderRight(borderStyle);cell.setCellStyle(style);} catch (Exception e) {log.error("應用表頭單元格樣式錯誤: " + e.getMessage(), e);}}private void setCellValue(Cell cell, Object value) {if (value instanceof Number) {cell.setCellValue(((Number) value).doubleValue());} else if (value instanceof Boolean) {cell.setCellValue((Boolean) value);} else if (value instanceof Date) {cell.setCellValue((Date) value);} else {cell.setCellValue(value.toString());}}private Set<String> getAllColumnNames(JSONArray dataArray) {Set<String> columns = new LinkedHashSet<>();for (int i = 0; i < dataArray.size(); i++) {JSONObject obj = dataArray.getJSONObject(i);if (obj != null) {columns.addAll(obj.keySet());}}return columns;}private void sortDataArray(JSONArray dataArray, String sortBy, boolean sortAscending) {dataArray.sort((o1, o2) -> {JSONObject obj1 = (JSONObject) o1;JSONObject obj2 = (JSONObject) o2;Object val1 = obj1.get(sortBy);Object val2 = obj2.get(sortBy);if (val1 == null && val2 == null) {return 0;}if (val1 == null) {return sortAscending ? -1 : 1;}if (val2 == null) {return sortAscending ? 1 : -1;}if (val1 instanceof Comparable && val2 instanceof Comparable) {@SuppressWarnings("unchecked")int result = ((Comparable<Object>) val1).compareTo(val2);return sortAscending ? result : -result;}return sortAscending ? val1.toString().compareTo(val2.toString()) : val2.toString().compareTo(val1.toString());});}@Datapublic static class Config {private JSONObject header;private JSONArray excelData;private String fileName;private String typeId;}@Datapublic static class HeaderConfig {private JSONObject normalSetting;private JSONObject customSetting;private List<String> columnOrder;}public static void main(String[] args) throws Exception {/* ============ 1. 原始配置骨架(excelData 先留空數組) ============ */String baseJson = "{\n" +" \"typeId\":\"10801\",\n" +" \"fileName\":\"測試文件1\",\n" +" \"header\":{\n" +" \"normal_setting\":{\n" +" \"align\": \"center\",\n" +" \"font-name\":\"宋體\",\n" +" \"font-size\": 12,\n" +" \"font-weight\": \"\",\n" +" \"font-color\": \"#333333\",\n" +" \"background-color\": \"\",\n" +" \"width\": 510,\n" +" \"line-wrap\": true,\n" +" \"header-align\": \"\",\n" +" \"header-row-height\": 150,\n" +" \"header-font-size\": 121,\n" +" \"header-font-weight\": \"bold\",\n" +" \"header-font-color\": \"#0f0f0f\",\n" +" \"header-background-color\": \"#ADD8E6\"\n" +" },\n" +" \"custom_setting\":{\n" +" \"序號\":{\"index\":3,\"column_align\":\"center\",\"column_width\":500},\n" +" \"員工編號\":{\"index\":2,\"column_align\":\"left\",\"column_width\":50},\n" +" \"姓名\":{\"index\":1,\"column_align\":\"center\",\"column_width\":50},\n" +" \"年齡\":{\"index\":4,\"column_width\":50},\n" +" \"部門\":{\"index\":5,\"column_align\":\"center\",\"column_width\":200},\n" +" \"職位\":{\"index\":6,\"column_align\":\"center\",\"column_width\":100},\n" +" \"薪資\":{\"index\":7,\"column_width\":100},\n" +" \"績效評級\":{\"index\":8,\"column_width\":100},\n" +" \"工作年限\":{\"index\":9,\"column_width\":100},\n" +" \"入職日期\":{\"index\":10,\"column_width\":100},\n" +" \"聯系電話\":{\"index\":11,\"column_align\":\"left\",\"column_width\":100},\n" +" \"郵箱\":{\"index\":12,\"column_width\":100},\n" +" \"工作地點\":{\"index\":13,\"column_width\":100},\n" +" \"狀態\":{\"index\":14,\"column_align\":\"left\",\"column_width\":100}\n" +" }\n" +" },\n" +" \"excelData\": %s\n" +"}";/* ============ 2. 單條數據模板 ============ */String singleRecord = "{\n" +" \"排序號\": %d,\n" +" \"員工編號\": \"E%03d\",\n" +" \"姓名\": \"員工%d\",\n" +" \"年齡\": %d,\n" +" \"部門\": \"技術部\",\n" +" \"職位\": \"工程師\",\n" +" \"薪資\": %d,\n" +" \"績效評級\": \"A\",\n" +" \"工作年限\": %.1f,\n" +" \"入職日期\": \"2022-01-01\",\n" +" \"聯系電話\": \"138****%04d\",\n" +" \"郵箱\": \"emp%03d@company.com\",\n" +" \"工作地點\": \"北京\",\n" +" \"狀態\": \"在職\"\n" +"}";/* ============ 3. 循環生成 N 條 ============ */int N = 5000; // 想壓多大就改多大List<String> list = new ArrayList<>(N);for (int i = 1; i <= N; i++) {list.add(String.format(singleRecord,i, i, i,20 + (i % 20), // 年齡 20~398000 + (i * 10), // 隨薪資遞增1.0 + (i % 10), // 工作年限i % 10000, i));}/* ============ 4. 最終 JSON 字符串 ============ */String hugeJson = String.format(baseJson, list.toString());/* ============ 5. 調接口測試 ============ */FileConvertServiceImpl service = new FileConvertServiceImpl();FileInformation info = service.convertWithConfig(hugeJson);System.out.println("生成對象大小:" + hugeJson.length() / 1024 + " KB");}
}
postman測試
好了 至此 java之json轉excel生成 點點關注不迷路 老鐵們!!!!!