doum
2025-09-08 55ba702c1df240929e68df3b42fa9cb0607378b8
server/services/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java
@@ -1,5 +1,6 @@
package com.doumee.core.annotation.excel;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.dao.business.model.Goodsorder;
@@ -168,6 +169,21 @@
            }
        }
    }
//    public void exportList (List<List<String>> data, String fileName, String sheetName, HttpServletResponse response) {
//        try {
//            String encodeFileName = URLEncoder.encode(fileName, Charset.forName("UTF-8").toString()) + ".xlsx";
//            response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
//            response.setContentType("application/octet-stream");
//            response.setHeader("eva-opera-type", "download");
//            response.setHeader("eva-download-filename", encodeFileName);
//            this.exportList(data, sheetName, response.getOutputStream());
//        } catch (IOException e) {
//            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
//        }
//    }
    /**
     * 导出到指定输出流
     * @param os 输出流
@@ -181,27 +197,47 @@
            sheet.createFreezePane(0, 1);
            Row header = sheet.createRow(0);
            CellStyle hstyle = configHeaderCellStatic(sxssfWorkbook);
            CellStyle cstyle = configCellStatic(sxssfWorkbook);
            List<String> headerList =dataList.get(0);
            for (int i = 0; i < headerList.size(); i++) {
            for (int i = 0; i < dataList.size(); i++) {
                Cell cell = header.createCell(i);
                cell.setCellValue(headerList.get(i));
                cell.setCellValue(dataList.get(i).get(Constants.ZERO));
                // 列宽设置
                sheet.setColumnWidth(i, headerList.get(i).length() * 2 * 256);
                sheet.setColumnWidth(i, dataList.get(i).get(Constants.ZERO).length() * 2 * 256);
                // 设置列头单元格
                cell.setCellStyle(hstyle);
            }
            // 创建数据记录
            for (int rowIndex = 1; rowIndex < dataList.size(); rowIndex++) {
                Row row = sheet.createRow(rowIndex );
                List<String> rowList = dataList.get(rowIndex);
                for (int i = 0; i < rowList.size(); i++) {
                    Cell cell = row.createCell(i);
                    cell.setCellValue(rowList.get(i));
                    // 列宽设置
                    cell.setCellStyle(cstyle);
            //总行数
            Integer rowSize = dataList.get(Constants.ZERO).size();
            //总列数
            Integer columnSize = dataList.size();
            for (int i = 1; i < rowSize; i++) {
                Row row = sheet.createRow(i);
                for (int j = 0; j < columnSize; j++) {
                    Cell cell = row.createCell(j);
                    cell.setCellValue(dataList.get(j).get(i));
                }
            }
//
//            List<String> headerList =dataList.get(0);
//            for (int i = 0; i < headerList.size(); i++) {
//                Cell cell = header.createCell(i);
//                cell.setCellValue(headerList.get(i));
//                // 列宽设置
//                sheet.setColumnWidth(i, headerList.get(i).length() * 2 * 256);
//                // 设置列头单元格
//                cell.setCellStyle(hstyle);
//            }
//            // 创建数据记录
//            for (int rowIndex = 1; rowIndex < dataList.size(); rowIndex++) {
//                Row row = sheet.createRow(rowIndex );
//                List<String> rowList = dataList.get(rowIndex);
//                for (int i = 0; i < rowList.size(); i++) {
//                    Cell cell = row.createCell(i);
//                    cell.setCellValue(rowList.get(i));
//                    // 列宽设置
//                    cell.setCellStyle(cstyle);
//                }
//            }
            sxssfWorkbook.write(os);
            os.close();
        } catch (Exception e) {