String accident_id = request.getParameter(\); String OnputimagePath = null;
/**************使用poi实现excel模版 导出excel********************/
try {
POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream(\设备异常分析报告.xls\)); HSSFWorkbook wb = new HSSFWorkbook(fs);
}
// 输出文件
OnputimagePath = \; FileOutputStream fileOut = new wb.write(fileOut); fileOut.close(); e.printStackTrace();
patri.createPicture(anchor ,wb.addPicture(byteArrayOut.toByteArra
HSSFSheet sheet = wb.getSheet(\设备异常分析报告\); HSSFRow row = sheet.getRow(2);
HSSFCell cell = row.getCell((short) 2); if (cell == null)
cell = row.createCell((short) 2);
cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(\);
ByteArrayOutputStream byteArrayOut = new String InputimagePath =
BufferedImage bufferImg = ImageIO.read(new ImageIO.write(bufferImg,\,byteArrayOut); //设置图片大小,位置
HSSFClientAnchor anchor = new
//创建
HSSFPatriarch patri = sheet.createDrawingPatriarch();
ByteArrayOutputStream();
\; File(InputimagePath));
HSSFClientAnchor(5,0,500,122,(short) 0, 5,(short)10,15);
y(), HSSFWorkbook.PICTURE_TYPE_PNG));
FileOutputStream(OnputimagePath);
} catch (Exception e) {
// 检查文件是否存在
File obj = new File(OnputimagePath); if (!obj.exists()) {
response.setContentType(\); response.getWriter().print(\指定文件不存在!\); return; }
// 读取文件名:用于设置客户端保存时指定默认文件名
int index = OnputimagePath.lastIndexOf(\); // 前提:传入的path
字符串以“\\”表示目录分隔符 String fileName = OnputimagePath.substring(index + 1);
// 写流文件到前端浏览器
ServletOutputStream out = response.getOutputStream(); response.setHeader(\, BufferedInputStream bis = null; BufferedOutputStream bos = null; try {
bis = new BufferedInputStream(new bos = new BufferedOutputStream(out); byte[] buff = new byte[2048]; int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff, 0, bytesRead); }
} catch (IOException e) { throw e; } finally {
if (bis != null) bis.close(); if (bos != null) bos.close(); }
\ + fileName);
FileInputStream(OnputimagePath));