POI做报表

反复查阅了jxl方式的文档,个别丢失格式问题,不能解决。只好切换到POI方式。
POI一直开源并升级更新着。
 
[align=center][b]根据模板导出excel[/b][/align]

XXXAction :

public ActionForward exportExcle(ActionMapping mapping,ActionForm form,
   HttpServletRequest request,HttpServletResponse response){
  DebtUtil rp = new DebtUtil();
  ActionErrors errors = new ActionErrors();
  String fileName = "";
  try{
   fileName = rp.getFileName();
  }catch(Exception e){
   errors.add("success", new ActionError("message.warn","未找到模板路径,请联系管理员!"));
   saveErrors(request, errors);
   return mapping.findForward("success");
  }
  //选择模板文件
  response.setContentType("application/x-msdownload");
  response.setHeader("Content-Disposition","attachment; filename=\"" +Utf8Util.toUtf8String(fileName) + "\"");
  // 定义输出类型
  response.setContentType("application/msexcel");
try {
   rp.export(response.getOutputStream(),form);
} catch (Exception e) {
   e.printStackTrace();
   logger.debug(e);
  }
  return null;
 }

 
======导出方法

public void export(OutputStream out, ActionForm aform) throws Exception {
  HSSFWorkbook workbook;
  HSSFSheet sheet;
  HSSFRow row;
  HSSFCell cell = null;
  FileInputStream fis=null;
  try {
   // 选择模板文件
 String filePath = getModelPath("/模板");
 fis=new FileInputStream(filePath);
   workbook = new HSSFWorkbook(fis);
   sheet = workbook.getSheetAt(0);
   log.debug(filePath);
。。。。。
row = sheet.getRow(7);
row.getCell(2).setCellValue(your value);

workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
   workbook.write(out);
    } finally {
    workbook.close();
   if (null != out) {
    out.flush();
    out.close();
   }
   if (null != fis) 
    fis.close();
  }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值