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

来源:互联网 发布:union软件 编辑:程序博客网 时间:2024/05/24 23:15
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