/**
* 按样式设置 并导出指定年月 表
*
* @return
* @throws Exception
*/
@Action(value = "outProductAction_print")
public String print() throws Exception {
String shipTime = inputDate;
// 2017-08 2012年8月份出货表
String titleStr = inputDate.replace("-0", "-").replace("-", "年") + "月份出货表";
String strPath = "make/xlsprint/tOUTPRODUCT.xlsx".replace("/", File.separator);
// 获取指定样式的表格地址
String path = ServletActionContext.getServletContext().getRealPath(strPath);
// 指定样式的工作簿
InputStream in = new FileInputStream(path);
// 1、创建工作簿
Workbook book = new XSSFWorkbook(in);
// 2、创建sheet
Sheet sheet = book.getSheetAt(0);
// 3、创建行对象
Integer index = 0;
Row row = sheet.getRow(index++);
// 4、创建列对象
Cell cell = row.getCell(1);
// 设置大标题
cell.setCellValue(titleStr);
// 小标题
index++;
// 设置内容 并且保存样式
CellStyle cs01 = sheet.getRow(index).getCell(1).getCellStyle();
CellStyle cs02 = sheet.getRow(index).getCell(2).getCellStyle();
CellStyle cs03 = sheet.getRow(index).getCell(3).getCellStyle();
CellStyle cs04 = sheet.getRow(index).getCell(4).getCellStyle();
CellStyle cs05 = sheet.getRow(index).getCell(5).getCellStyle();
CellStyle cs06 = sheet.getRow(index).getCell(6).getCellStyle();
CellStyle cs07 = sheet.getRow(index).getCell(7).getCellStyle();
CellStyle cs08 = sheet.getRow(index).getCell(8).getCellStyle();
// 获取所有指定的船期
List<ContractProduct> cpList = contractProductService.findCpByShipTime(inputDate);
for (ContractProduct contractProduct : cpList) {
// int index1 = 1;
row = sheet.createRow(index++);
row.setHeightInPoints(26);
// 客户
Cell cell01 = row.createCell(1);
cell01.setCellValue(contractProduct.getContract().getCustomName());
cell01.setCellStyle(cs01);
// 订单号
Cell cell02 = row.createCell(2);
cell02.setCellValue(contractProduct.getContract().getContractNo());
cell02.setCellStyle(cs02);
// 货号
Cell cell03 = row.createCell(3);
cell03.setCellValue(contractProduct.getProductNo());
cell03.setCellStyle(cs03);
// 数量
Cell cell04 = row.createCell(4);
cell04.setCellValue(contractProduct.getCnumber());
cell04.setCellStyle(cs04);
// 工厂
Cell cell05 = row.createCell(5);
cell05.setCellValue(contractProduct.getFactoryName());
cell05.setCellStyle(cs05);
// 工厂交期
Cell cell06 = row.createCell(6);
cell06.setCellValue(contractProduct.getContract().getDeliveryPeriod());
short format = book.createDataFormat().getFormat("yyyy-mm-dd");
cs06.setDataFormat(format);
cell06.setCellStyle(cs06);
// 船期
Cell cell07 = row.createCell(7);
cell07.setCellValue(contractProduct.getContract().getShipTime());
format = book.createDataFormat().getFormat("yyyy-mm-dd");
cs07.setDataFormat(format);
cell07.setCellStyle(cs07);
// 贸易条款
Cell cell08 = row.createCell(8);
cell08.setCellValue(contractProduct.getContract().getTradeTerms());
cell08.setCellStyle(cs08);
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
HttpServletResponse response = ServletActionContext.getResponse();
DownloadUtil util = new DownloadUtil();
book.write(os);
util.download(os, response, titleStr + ".xlsx");
book.close();
return NONE;
}
poi 按导入样式设置 并导出指定年月 表
最新推荐文章于 2023-04-16 10:15:31 发布