Google Chrome游览器导出文件弹出空白页并显示页面下面

if (result.success) {
var newTab = window.open('about:blank');

newTab.location.href = sy.contextPath+ '/download?filename='+ result.msg;


/**
* 导出图表的信息
*/
public void createChatExcel() {
List<Map> list1 = getLampRealInfolist();
try {
String path = "/sy/template/LampchartTemplate.xls";
InputStream stream = LampRealInfoAction.class.getResourceAsStream(path);
POIFSFileSystem fs = new POIFSFileSystem(stream);// 得到Excel工作簿对象
HSSFWorkbook wb = new HSSFWorkbook(fs);// 得到Excel工作表对象
HSSFSheet sheet = wb.getSheetAt(0);// 得到Excel工作表的行 根据index取得sheet对象
HSSFCellStyle centerStyle = wb.createCellStyle();// 设置为水平居中
centerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
centerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
HSSFRow dateRow = sheet.getRow(1);// 得到Excel工作表指定行的单元格 取得有效的行数

String energySaverSeq = getRequest().getParameter("energySaverSeq");
String lampNo=getRequest().getParameter("lampNo");
Integer id= Integer.parseInt(energySaverSeq);
EnergySaverInfo energySaverInfo= energySaverInfoService.getById(id);

for (int i = 0; i < list1.size(); i++) {
HSSFRow row;
row = sheet.createRow(i + 2);
try {
Map info = list1.get(i);


if (info != null) {
row.createCell(0).setCellValue(i + 1);
row.createCell(1).setCellValue(lampNo);
row.createCell(2).setCellValue(
energySaverInfo.getSaverName());
String dataTime =info.get("dataTime").toString();
String datavalue = info.get("datavalue").toString();
row.createCell(5).setCellValue(datavalue);
row.createCell(4).setCellValue(
dataTime.substring(0, 4) + "-"
+ dataTime.substring(4, 6) + "-"
+ dataTime.substring(6, 8) + " "
+ dataTime.substring(8, 10) + ":"
+ dataTime.substring(10, 12) + ":"
+ dataTime.substring(12, 14));


switch (operateType) {
case "input_voltage":
row.createCell(3).setCellValue("输入电压");
continue;
case "output_voltage":
row.createCell(3).setCellValue("输出电压");
continue;
case "output_current":
row.createCell(3).setCellValue("输出电流");
continue;
case "kwh":
row.createCell(3).setCellValue("有功功率");
continue;
case "kwhFactor":
row.createCell(3).setCellValue("功率因数");
continue;
case "electric":
row.createCell(3).setCellValue("电量");
continue;
default:
logger.info("名称错误");
}
}


} catch (Exception e) {
logger.error("" , e);
json.setSuccess(false);
json.setMsg(e.getMessage());
continue;
}


}
ServletRequest request = ServletActionContext.getRequest();
@SuppressWarnings("deprecation")
String uploadFilePath = new File(request.getRealPath("/"))
.getPath();
String savePdfPath = uploadFilePath + "/uploadExcel";
File up = new File(savePdfPath);
if (!up.exists()) {
up.mkdirs();
}

String sysdate = IsvCom.getSystemDate(IsvCom.DATE_TYPE3);

FileOutputStream exportFile = new FileOutputStream(savePdfPath + "/" + sysdate + ".xls");
wb.write(exportFile);
exportFile.close();


json.setSuccess(true);
json.setMsg(sysdate + ".xls");
// json.setMsg("路灯图表_" + operateType + ".xls");
} catch (Exception e) {
json.setSuccess(false);
logger.error("" , e);
json.setMsg(e.toString());
} finally {
writeJson(json);
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值