java導出excel 經典例子與先關包下载

weixin_39820835 weixin_39820835 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
:下载时如果出现文件下载 安全警告原因在于生成的文件名带有中文需转码
将action中fileName处如下转码(和一般转码不同特别注意顺序)
fileName = new String( fileName.getBytes("gbk"),"ISO-8859-1");
2:此例子是根据返回的Vector填充数据的,
该方法若一个结果集包含的数据过多时会出现溢出异常( the exceptino: java heap space)
若采用返回list集合来填充,需变动2处
相关下载链接://download.csdn.net/download/chengfeng129/2810599?utm_source=bbsseo
...全文

相关推荐

JAVA Excel模板POI导出并下载

POI模板导出并下载、并提供下载Utils

75888丶

java導出excel 經典例子與先關包

:下载时如果出现文件下载 安全警告原因在于生成的文件名带有中文需转码 将action中fileName处如下转码(和一般转码不同特别注意顺序) fileName = new String( fileName.getBytes("gbk"),"ISO-8859-1"); 2:此例子是根据返回的Vector填充数据的, 该方法若一个结果集包含的数据过多时会出现溢出异常( the exceptino: java heap space) 若采用返回list集合来填充,需变动2处

p疯子

java通过Excel模板导出各种Excel

java通过Excel模板导出各种Excel , 支持所有的动态数据,列表,图片, 好用的请给好评! 解压导入到eclipse就可以运行看到效果,里面有简单的例子 , 有很复杂的模板,通过模板导出数据。

感动呀

java excel导入导出和模板下载

内容主要为service业务代码,分三个模块(导入导出和模板下载),可自定义,注释比较全

没有那么多嘻嘻哈哈

java编写根据模板导出excel

根据excel模板动态导出数据库数据 package text; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import javax.servlet.ServletContext; import net.sf.jxls.transformer.XLSTransformer; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class TextAction extends ActionSupport { /** */ private static final long serialVersionUID = 1L; private String filename; @SuppressWarnings("rawtypes") public String export() throws Exception { String templateFile = "18.xls"; // String sql = "select * from t_ry order by rybm"; // exportAndDownload(templateFile, DataBase.retrieve(sql)); List datas = new ArrayList(); @SuppressWarnings("unchecked") HashMap map = new HashMap(); map.put("name", "1111"); datas.add(map); exportAndDownload(templateFile, datas); return SUCCESS; } @SuppressWarnings({ "rawtypes", "unchecked" }) public void exportAndDownload(String templateFile, List datas) { try { filename = UUID.randomUUID() + templateFile; // FacesContext context = FacesContext.getCurrentInstance(); // ServletContext servletContext = (ServletContext) // context.getExternalContext().getContext(); ServletContext servletContext = ServletActionContext .getServletContext(); String path = servletContext.getRealPath("\\ExcelFile"); String srcFilePath = path + "\\template\\" + templateFile; String destFilePath = path + "\\download\\" + filename; Map beanParams = new HashMap(); beanParams.put("results", datas); XLSTransformer transfer = new XLSTransformer(); transfer.transformXLS(srcFilePath, beanParams, destFilePath); // Browser.execClientScript("window.location.href='../ExcelFile/downloadfile.jsp?filename=" // + destFile + "';"); } catch (Exception e) { e.printStackTrace(); } } public String getFilename() { return filename; } public void setFilename(String filename) { this.filename = filename; } }

mrgodric
评论
收藏 已收藏
分享
返回顶部