jxls导出excel
来源:互联网 发布:淘宝机构招聘信息 编辑:程序博客网 时间:2024/04/28 21:48
JxlsUtils.java:
/** * */package com.linewell.common;import java.io.FileInputStream;import java.io.InputStream;import java.io.OutputStream;import java.util.Map;import javax.servlet.ServletContext;import net.sf.jxls.transformer.XLSTransformer;import org.apache.poi.ss.usermodel.Workbook;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionContext;/** * jxls 生成excel并的导出的工具类 * @author cjianquan * 2015-1-29 */public class JxlsUtils {public static void exportExcel(String templateFile,Map<String,Object> beans,String destFileName){XLSTransformer xlsTransformer = new XLSTransformer();ServletContext sc = (ServletContext) ActionContext.getContext().get(ServletActionContext.SERVLET_CONTEXT);String path = sc.getRealPath("/");templateFile = path+"\\"+templateFile;destFileName = path+"\\"+destFileName;try{xlsTransformer.transformXLS(templateFile, beans,destFileName);}catch(Exception e){e.printStackTrace();throw new RuntimeException("导出excel错误");}}}
调用上面的方法进行生成excel:
/** * 导出所选记录(装备) * @param request * @param response * @author cjianquan * 2015-1-29 */@RequestMapping(params = "exportZbxx")public void exportZbxx (HttpServletRequest request,HttpServletResponse response){String[] ids = request.getParameterValues("ids[]");String conIds = "";for(String s:ids){conIds+="'"+s+"',";}conIds = conIds.substring(0,conIds.length()-1);StringBuilder querySql = new StringBuilder("select ZHUANGBEI_ZBMC,");querySql.append("ZHUANGBEI_ZBBH,(select zblx_mc from TBL_BASE_ZBLX a where a.zblx_unid=t.ZHUANGBEI_ZBLX) ZHUANGBEI_ZBLX,").append("ZHUANGBEI_SSDWMC,").append("ZHUANGBEI_ZBSJ,").append("(select typename from t_s_type where typegroupid =(select id from t_s_typegroup where typegroupcode='xxcg_jczb_zwzt') and typecode=t.ZHUANGBEI_ZBZT) ZHUANGBEI_ZWZT,").append("ZHUANGBEI_SCCJ,").append("(select typename from t_s_type where typegroupid =(select id from t_s_typegroup where typegroupcode='xxcg_jczb_zlzk') and typecode=t.ZHUANGBEI_ZBZT) ZHUANGBEI_ZLZK,").append("(select typename from t_s_type where typegroupid =(select id from t_s_typegroup where typegroupcode='xxlb_zbgl_zbzt') and typecode=t.ZHUANGBEI_ZBZT) ZHUANGBEI_ZBZT").append(" from TBL_BASE_ZHUANGBEI t where ZHUANGBEI_UNID in ("+conIds+")");List<Map<String,Object>> zbxxList = this.systemService.findForJdbc(querySql.toString());Map<String,Object> exportBeans = new HashMap<String, Object>();String templateFile = "export/xlsTemplates/zbxxExportTemplate.xls";String destFileName = "export/output/zbxx.xls";exportBeans.put("resultList", zbxxList);JxlsUtils.exportExcel(templateFile, exportBeans, destFileName);}
js导出Excel:
//导出所选记录//add by cjianquan on 2015-1-29 function exportXls(){var ids = [];var rows = $('#zbxxList').datagrid('getSelections');if(rows.length<=0){alert("请选择要导出的记录!");return false;}for(var i=0; i<rows.length; i++){ids.push(rows[i].id);}//ids.join(',');$.ajax({type:'POST',async:false,data:{"ids":ids},url:'./zbxxController.do?exportZbxx',success:function(data){window.location.href='export/output/zbxx.xls';},error:function(XMLHttpRequest,textStatus,errorThrown){alert("导出Excel失败!");}});}
zbxxExportTemplate.xls模板文件内容如下:
0 0
- JXLS-----JXLS导出Excel
- JXLS-----JXLS导出Excel实例
- Jxls 导出excel
- jxls模板导出excel
- Jxls 导出excel
- jxls模板导出excel
- jxls导出excel
- Excel 模板导出---JXLS
- JXLS模板导出EXCEL
- jxls导出excel
- zk中用jxls导出excel
- 使用jxls分页导出excel
- jxls 使用模板文件导出生成excel
- POI+JXLS测试Excel报表导出
- 利用JXLS根据模板导出Excel实例教程
- 使用jxls按模板导出excel数据
- java使用jxls导出excel功能
- Jxls+Spring MVC实现Excel导出
- Shopping cart analysis with R(-1) – Multi-layer pie chart
- ECSHOP插件大全 ecshop模板2014集合包
- Android技术——数据库(一):基本概念
- ARP欺骗:先认识再防御
- 一些常用的UTIL工具
- jxls导出excel
- kmp字符串的匹配
- 跟老紫竹学Java-计数器-新建项目
- CImg应用-输出中文字符(CentOS 6.5)
- POJ 1041 John's trip(无向图欧拉回路 && 路径)
- 模板声明与定义要放在同一文件中?
- springmvc 中controller与jsp传值
- 更改button里面的Image和Title的位置
- 08-0. 查找整数(10)