我看别人之前写的代码,发现仔细比对后一样的,而且与我自己的代码能替换部分进行了替换,发现还是不行。本地有Excel生成,并且数据正常,就是浏览器没反应。
大家先看我代码struts2的配置文件
在看我的代码部分:
`
public InputStream getDownloadFile() throws Exception {
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("数据表");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow rowTitle = sheet.createRow((int) 0);
HSSFRow rowTime = sheet.createRow((int) 1);
HSSFRow rowEmpty = sheet.createRow((int) 2);
HSSFRow row = sheet.createRow((int) 3);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle styleTitle = wb.createCellStyle();
styleTitle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
// 标题字体
HSSFFont fontTitle = wb.createFont();
// fontTitle.setColor(HSSFColor.VIOLET.index);
fontTitle.setFontHeightInPoints((short) 15);
fontTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
styleTitle.setFont(fontTitle);
HSSFCellStyle style = wb.createCellStyle();
// 表头字体
HSSFFont font = wb.createFont();
font.setFontHeightInPoints((short) 10);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);// 白色头文字
style.setFont(font);
// 设置这些样式
style.setFillForegroundColor(HSSFColor.DARK_TEAL.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// 内容字体
HSSFCellStyle styleContent = wb.createCellStyle();
styleContent.setAlignment(HSSFCellStyle.ALIGN_LEFT);
HSSFFont fontContent = wb.createFont();
fontContent.setFontHeightInPoints((short) 9);
styleContent.setFont(fontContent);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String tsStartTime = df.format(datestart);
String tsEndTime = df.format(dateend);
HSSFCell cellTilte = rowTitle.createCell((short) 0);
cellTilte.setCellValue("易宝数据报表");
cellTilte.setCellStyle(styleTitle);
HSSFCell cellTime = rowTime.createCell((short) 0);
cellTime.setCellValue("查询日期: " + tsStartTime + " - "+ tsEndTime);
cellTime.setCellStyle(styleTitle);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("序号");
cell.setCellStyle(style);
cell = row.createCell((short) 1);
cell.setCellValue("下单时间");
cell.setCellStyle(style);
cell = row.createCell((short) 2);
cell.setCellValue("支付时间");
cell.setCellStyle(style);
cell = row.createCell((short) 3);
cell.setCellValue("商户订单号");
cell.setCellStyle(style);
cell = row.createCell((short) 4);
cell.setCellValue("订单金额");
cell.setCellStyle(style);
cell = row.createCell((short) 5);
cell.setCellValue("收款方名称");
cell.setCellStyle(style);
cell = row.createCell((short) 6);
cell.setCellValue("订单状态");
cell.setCellStyle(style);
cell = row.createCell((short) 7);
cell.setCellValue("支付类型");
cell.setCellStyle(style);
cell = row.createCell((short) 8);
cell.setCellValue("大客户编码");
cell.setCellStyle(style);
cell = row.createCell((short) 9);
cell.setCellValue("PNR");
cell.setCellStyle(style);
cell = row.createCell((short) 10);
cell.setCellValue("起始票号");
cell.setCellStyle(style);
cell = row.createCell((short) 11);
cell.setCellValue("终止票号");
cell.setCellStyle(style);
List
`
求大神给出解决问题的思路或指教下错误的地方,谢谢!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Content-Type不能配成 text/plain 要配成 application/octet-stream