POI做报表

反复查阅了jxl方式的文档,个别丢失格式问题,不能解决。只好切换到POI方式。

                   根据模板导出excel

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

workbook.close();

} finally {

if (null != out) {

out.flush();

out.close();

}

if (null != fis)

fis.close();

}
















1



1

1










1































































000000000000000000000000000000000000000000000000000000000000000000000

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,778评论 18 399
  • 使用首先需要了解他的工作原理 1.POI结构与常用类 (1)创建Workbook和Sheet (2)创建单元格 (...
    长城ol阅读 8,553评论 2 25
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,991评论 19 139
  • 项目中使用POI生成excle报表 maven: <groupId>org.apache.poi poi <ve...
    大大大浣熊阅读 4,694评论 0 6
  • apache下的httpclient工具可大大简化开发过程中的点对点通信,本人将以微信多媒体接口为例,展示http...
    划破的天空阅读 5,348评论 0 32