JAVA的poi实现模版导出excel

2020-02-21 01:38

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));


JAVA的poi实现模版导出excel.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:江苏省南京市金陵中学河西分校八年级政治下册 第二课 忠实履行义

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: