This commit is contained in:
sungsu
2024-01-19 09:54:32 +09:00
parent 2b61691f65
commit 98de984f58
9 changed files with 125 additions and 10 deletions

View File

@@ -8,6 +8,7 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
@@ -186,10 +187,68 @@ public class ExcelDownlodeUtils {
}
public void downloadStockExcelFile(String excelFileName, HttpServletResponse response,
String sheetName, String[] columnName, List<Map<String, Object>> dto) {
String fileName = "";
try {
fileName = new String((excelFileName + ".xlsx").getBytes("utf-8"), "iso-8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
response.setContentType("ms-vnd/excel");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\";");
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet(sheetName);
Row row = null;
Cell cell = null;
int rowNum = 0;
row = sheet.createRow(rowNum);
for( int i = 0; i <= columnName.length -1; i++ ) {
cell = row.createCell(i);
cell.setCellValue(columnName[i]);
}
rowNum += 1;
//수정부분
makeStockBody(dto,row,sheet,cell,rowNum);
try {
workbook.write(response.getOutputStream());
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void makeStockBody(List<Map<String, Object>> listdto, Row row, Sheet sheet,
Cell cell, int rowNum) {
//
for (int i = 0; i < listdto.size(); i++) {
row = sheet.createRow(rowNum++);
Map<String, Object> dto = listdto.get(i);
cell = row.createCell(0);
cell.setCellValue((String) dto.get("productName"));
cell = row.createCell(1);
cell.setCellValue((String) dto.get("cls_nm_4"));
cell = row.createCell(2);
cell.setCellValue((String) dto.get("warehouseName"));
cell = row.createCell(3);
cell.setCellValue((String) dto.get("quantity"));
}
}
}