poi 导出表格 这个问题怎么解决 急!!!!

ing_gni 2017-07-19 11:26:31
//创建数据行 //这些数据行下一步要从数据库中取。。。。。。。。。。。。。

List<Yyworders> list=hdm.selectYywordersByOrderstatus();
//对list集合进行遍历

for(int i =1;i<=list.size();i++) {

HSSFRow newrow = sheet.createRow(i);
newrow.createCell(0).setCellValue(i);
newrow.createCell(1).setCellValue(i);
newrow.createCell(2).setCellValue(i);
newrow.createCell(3).setCellValue(i);
newrow.createCell(4).setCellValue(i);
newrow.createCell(5).setCellValue(i);
newrow.createCell(6).setCellValue(i);
newrow.createCell(7).setCellValue(i);
newrow.createCell(8).setCellValue(i);
newrow.createCell(9).setCellValue(i);
newrow.createCell(10).setCellValue(i);
newrow.createCell(11).setCellValue(i);

}
我想把集合里的对象 的属性值 放到 setCellValue(i);怎么办。。。。。。。。。。
...全文
500 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanjinpeng 2017-07-21
  • 打赏
  • 举报
回复
查看poi的api文档
weixin_39577250 2017-07-21
  • 打赏
  • 举报
回复
给个积分吧
waxf523 2017-07-19
  • 打赏
  • 举报
回复
具体可以参考: http://blog.csdn.net/waxf523/article/details/75220884
110成成 2017-07-19
  • 打赏
  • 举报
回复
引用 19 楼 ing_gni 的回复:
[quote=引用 18 楼 zc881124 的回复:] 后台获取list通过 selectList试试
麻烦具体点 谢谢[/quote] resultType 实体类建议名称写全了,另也可以通过session.selectList获取。 网上具体写法有好几种,你参考下。
ing_gni 2017-07-19
  • 打赏
  • 举报
回复
引用 18 楼 zc881124 的回复:
后台获取list通过 selectList试试
麻烦具体点 谢谢
110成成 2017-07-19
  • 打赏
  • 举报
回复
后台获取list通过 selectList试试
ing_gni 2017-07-19
  • 打赏
  • 举报
回复
引用 16 楼 zc881124 的回复:
[quote=引用 15 楼 ing_gni 的回复:] [quote=引用 14 楼 zc881124 的回复:] resultType 换成Yyworders 试试。
不行[/quote] 报什么错[/quote] 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 网页都显示不了
110成成 2017-07-19
  • 打赏
  • 举报
回复
引用 15 楼 ing_gni 的回复:
[quote=引用 14 楼 zc881124 的回复:] resultType 换成Yyworders 试试。
不行[/quote] 报什么错
ing_gni 2017-07-19
  • 打赏
  • 举报
回复
引用 14 楼 zc881124 的回复:
resultType 换成Yyworders 试试。
不行
110成成 2017-07-19
  • 打赏
  • 举报
回复
resultType 换成Yyworders 试试。
ing_gni 2017-07-19
  • 打赏
  • 举报
回复
引用 9 楼 zc881124 的回复:
(list.get(i).getId() 打印下,另id是什么类型,另控制台报什么错没
严重: Servlet.service() for servlet [PoiServlet] in context with path [/md] threw exception [java.lang.ClassCastException: java.util.HashMap cannot be cast to com.sxk.data.model.Yyworders] with root cause java.lang.ClassCastException: java.util.HashMap cannot be cast to com.sxk.data.model.Yyworders at com.sxk.web.UploadAndDownloadServlet.poi_down(UploadAndDownloadServlet.java:379) at com.sxk.web.UploadAndDownloadServlet.doGet(UploadAndDownloadServlet.java:78) at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) id long 类型的 (list.get(i).getId()打印不出来 报错和上面错误一样
引用 12 楼 zc881124 的回复:
[java.lang.ClassCastException: java.util.HashMap cannot be cast to com.sxk.data.model.Yyworders] 你这 session.getMapper 返回的map类型,强转出错了,你在MyBatis 配置文件中resultType 配置的有问题 你自己检查下
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.sxk.mapper.YywordersMapper"> <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.sxk.data.model.Yyworders"> <id column="id" property="id" /> <result column="orderid" property="orderid" /> <result column="productid" property="productid" /> <result column="wbspbm" property="wbspbm" /> <result column="xdcpm" property="xdcpm" /> <result column="brand" property="brand" /> <result column="ordernum" property="ordernum" /> <result column="productprice" property="productprice" /> <result column="marketprice" property="marketprice" /> <result column="orderprice" property="orderprice" /> <result column="ordertime" property="ordertime" /> <result column="buyerinfo" property="buyerinfo" /> <result column="customername" property="customername" /> <result column="customerphonenumber" property="customerphonenumber" /> <result column="customeraddress" property="customeraddress" /> <result column="paymode" property="paymode" /> <result column="expressname" property="expressname" /> <result column="expressno" property="expressno" /> <result column="orderstatus" property="orderstatus" /> <result column="processstatus" property="processstatus" /> <result column="expressprice" property="expressprice" /> <result column="salesprice" property="salesprice" /> <result column="voucherprice" property="voucherprice" /> <result column="totalprice" property="totalprice" /> </resultMap> <select id="selectYywordersByOrderstatus" resultType="Map"> SELECT * FROM yyworders y <where> y.orderstatus LIKE '待发货' </where> </select> 这是我的mapper.xml 有毛病不
110成成 2017-07-19
  • 打赏
  • 举报
回复
[java.lang.ClassCastException: java.util.HashMap cannot be cast to com.sxk.data.model.Yyworders] 你这 session.getMapper 返回的map类型,强转出错了,你在MyBatis 配置文件中resultType 配置的有问题 你自己检查下
lyn584238910 2017-07-19
  • 打赏
  • 举报
回复
有教程 的 百度搜一下,poi导出excle
ing_gni 2017-07-19
  • 打赏
  • 举报
回复
引用 9 楼 zc881124 的回复:
(list.get(i).getId() 打印下,另id是什么类型,另控制台报什么错没
严重: Servlet.service() for servlet [PoiServlet] in context with path [/md] threw exception [java.lang.ClassCastException: java.util.HashMap cannot be cast to com.sxk.data.model.Yyworders] with root cause java.lang.ClassCastException: java.util.HashMap cannot be cast to com.sxk.data.model.Yyworders at com.sxk.web.UploadAndDownloadServlet.poi_down(UploadAndDownloadServlet.java:379) at com.sxk.web.UploadAndDownloadServlet.doGet(UploadAndDownloadServlet.java:78) at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) id long 类型的 (list.get(i).getId()打印不出来 报错和上面错误一样
110成成 2017-07-19
  • 打赏
  • 举报
回复
(list.get(i).getId() 打印下,另id是什么类型,另控制台报什么错没
ing_gni 2017-07-19
  • 打赏
  • 举报
回复
引用 7 楼 ing_gni 的回复:
[quote=引用 6 楼 zc881124 的回复:] [quote=引用 5 楼 ing_gni 的回复:] [quote=引用 4 楼 zc881124 的回复:] [quote=引用 3 楼 ing_gni 的回复:] 我试过这样 他会报错 找不到页面
错误贴出来,以及错误对应具体的代码行贴出来[/quote] private void poi_down(HttpServletRequest request,HttpServletResponse response) { response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setHeader("Content-Disposition", "attachment;filename=data.xls"); //通过mybatis对数据进行入库和更新操作 DefaultSqlSessionFactory sqlSession = (DefaultSqlSessionFactory) SpringUtil.getObject("sqlSessionFactory"); SqlSession session = sqlSession.openSession(); // 获取Mapper YywordersMapper hdm = session.getMapper(YywordersMapper.class); // hdm.selectList(); // List<Yyworders> l = .getNeedExpressOrders(); // Hydata hd = new Hydata(); // hd.setId(32640); // hd =hdm.selectById(hd); ServletOutputStream stream = null; try { stream = response.getOutputStream(); } catch (IOException e1) { e1.printStackTrace(); } HSSFWorkbook workbook = new HSSFWorkbook(); HSSFCellStyle style = workbook.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//左右居中样式 HSSFSheet sheet = workbook.createSheet("我的联系人"); //sheet页的名称叫“我的联系人” sheet.setColumnWidth(0, 2000); sheet.setColumnWidth(1, 5000); //创建表头(第一行) HSSFRow row = sheet.createRow(0); //列 HSSFCell cell = row.createCell(0); cell.setCellValue("编号"); cell.setCellStyle(style); HSSFCell cell2 = row.createCell(1); cell2.setCellValue("订单id"); cell2.setCellStyle(style); HSSFCell cell3 = row.createCell(2); cell3.setCellValue("订单数量"); cell3.setCellStyle(style); HSSFCell cell4 = row.createCell(3); cell4.setCellValue("订购时间"); cell4.setCellStyle(style); HSSFCell cell5 = row.createCell(4); cell5.setCellValue("客户姓名"); cell5.setCellStyle(style); HSSFCell cell6 = row.createCell(5); cell6.setCellValue("客户手机号"); cell6.setCellStyle(style); HSSFCell cell7 = row.createCell(6); cell7.setCellValue("客户收货地址"); cell7.setCellStyle(style); HSSFCell cell8 = row.createCell(7); cell8.setCellValue("运费"); cell8.setCellStyle(style); HSSFCell cell9 = row.createCell(8); cell9.setCellValue("优惠价格"); cell9.setCellStyle(style); HSSFCell cell10 = row.createCell(9); cell10.setCellValue("快递单号"); cell10.setCellStyle(style); HSSFCell cell11 = row.createCell(10); cell11.setCellValue("快递名称"); cell11.setCellStyle(style); HSSFCell cell12 = row.createCell(11); cell12.setCellValue("总价格"); cell12.setCellStyle(style); //创建数据行 //这些数据行下一步要从数据库中取。。。。。。。。。。。。。 List<Yyworders> list=hdm.selectYywordersByOrderstatus(); //对list集合进行遍历 for(int i =1;i<=list.size();i++) { HSSFRow newrow = sheet.createRow(i); newrow.createCell(0).setCellValue(list.get(i).getId()); newrow.createCell(1).setCellValue(i); newrow.createCell(2).setCellValue(i); newrow.createCell(3).setCellValue(i); newrow.createCell(4).setCellValue(i); newrow.createCell(5).setCellValue(i); newrow.createCell(6).setCellValue(i); newrow.createCell(7).setCellValue(i); newrow.createCell(8).setCellValue(i); newrow.createCell(9).setCellValue(i); newrow.createCell(10).setCellValue(i); newrow.createCell(11).setCellValue(i); } try { workbook.write(stream); System.out.println("下载成功"); stream.flush(); stream.close(); } catch (Exception e) { e.printStackTrace(); } }[/quote] 你在poi_down中加打印信息,看执行到哪一步了[/quote] 进入for循环了[/quote] newrow.createCell(0).setCellValue(list.get(i).getId());到这就不走了
ing_gni 2017-07-19
  • 打赏
  • 举报
回复
引用 6 楼 zc881124 的回复:
[quote=引用 5 楼 ing_gni 的回复:] [quote=引用 4 楼 zc881124 的回复:] [quote=引用 3 楼 ing_gni 的回复:] 我试过这样 他会报错 找不到页面
错误贴出来,以及错误对应具体的代码行贴出来[/quote] private void poi_down(HttpServletRequest request,HttpServletResponse response) { response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setHeader("Content-Disposition", "attachment;filename=data.xls"); //通过mybatis对数据进行入库和更新操作 DefaultSqlSessionFactory sqlSession = (DefaultSqlSessionFactory) SpringUtil.getObject("sqlSessionFactory"); SqlSession session = sqlSession.openSession(); // 获取Mapper YywordersMapper hdm = session.getMapper(YywordersMapper.class); // hdm.selectList(); // List<Yyworders> l = .getNeedExpressOrders(); // Hydata hd = new Hydata(); // hd.setId(32640); // hd =hdm.selectById(hd); ServletOutputStream stream = null; try { stream = response.getOutputStream(); } catch (IOException e1) { e1.printStackTrace(); } HSSFWorkbook workbook = new HSSFWorkbook(); HSSFCellStyle style = workbook.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//左右居中样式 HSSFSheet sheet = workbook.createSheet("我的联系人"); //sheet页的名称叫“我的联系人” sheet.setColumnWidth(0, 2000); sheet.setColumnWidth(1, 5000); //创建表头(第一行) HSSFRow row = sheet.createRow(0); //列 HSSFCell cell = row.createCell(0); cell.setCellValue("编号"); cell.setCellStyle(style); HSSFCell cell2 = row.createCell(1); cell2.setCellValue("订单id"); cell2.setCellStyle(style); HSSFCell cell3 = row.createCell(2); cell3.setCellValue("订单数量"); cell3.setCellStyle(style); HSSFCell cell4 = row.createCell(3); cell4.setCellValue("订购时间"); cell4.setCellStyle(style); HSSFCell cell5 = row.createCell(4); cell5.setCellValue("客户姓名"); cell5.setCellStyle(style); HSSFCell cell6 = row.createCell(5); cell6.setCellValue("客户手机号"); cell6.setCellStyle(style); HSSFCell cell7 = row.createCell(6); cell7.setCellValue("客户收货地址"); cell7.setCellStyle(style); HSSFCell cell8 = row.createCell(7); cell8.setCellValue("运费"); cell8.setCellStyle(style); HSSFCell cell9 = row.createCell(8); cell9.setCellValue("优惠价格"); cell9.setCellStyle(style); HSSFCell cell10 = row.createCell(9); cell10.setCellValue("快递单号"); cell10.setCellStyle(style); HSSFCell cell11 = row.createCell(10); cell11.setCellValue("快递名称"); cell11.setCellStyle(style); HSSFCell cell12 = row.createCell(11); cell12.setCellValue("总价格"); cell12.setCellStyle(style); //创建数据行 //这些数据行下一步要从数据库中取。。。。。。。。。。。。。 List<Yyworders> list=hdm.selectYywordersByOrderstatus(); //对list集合进行遍历 for(int i =1;i<=list.size();i++) { HSSFRow newrow = sheet.createRow(i); newrow.createCell(0).setCellValue(list.get(i).getId()); newrow.createCell(1).setCellValue(i); newrow.createCell(2).setCellValue(i); newrow.createCell(3).setCellValue(i); newrow.createCell(4).setCellValue(i); newrow.createCell(5).setCellValue(i); newrow.createCell(6).setCellValue(i); newrow.createCell(7).setCellValue(i); newrow.createCell(8).setCellValue(i); newrow.createCell(9).setCellValue(i); newrow.createCell(10).setCellValue(i); newrow.createCell(11).setCellValue(i); } try { workbook.write(stream); System.out.println("下载成功"); stream.flush(); stream.close(); } catch (Exception e) { e.printStackTrace(); } }[/quote] 你在poi_down中加打印信息,看执行到哪一步了[/quote] 进入for循环了
110成成 2017-07-19
  • 打赏
  • 举报
回复
引用 5 楼 ing_gni 的回复:
[quote=引用 4 楼 zc881124 的回复:] [quote=引用 3 楼 ing_gni 的回复:] 我试过这样 他会报错 找不到页面
错误贴出来,以及错误对应具体的代码行贴出来[/quote] private void poi_down(HttpServletRequest request,HttpServletResponse response) { response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setHeader("Content-Disposition", "attachment;filename=data.xls"); //通过mybatis对数据进行入库和更新操作 DefaultSqlSessionFactory sqlSession = (DefaultSqlSessionFactory) SpringUtil.getObject("sqlSessionFactory"); SqlSession session = sqlSession.openSession(); // 获取Mapper YywordersMapper hdm = session.getMapper(YywordersMapper.class); // hdm.selectList(); // List<Yyworders> l = .getNeedExpressOrders(); // Hydata hd = new Hydata(); // hd.setId(32640); // hd =hdm.selectById(hd); ServletOutputStream stream = null; try { stream = response.getOutputStream(); } catch (IOException e1) { e1.printStackTrace(); } HSSFWorkbook workbook = new HSSFWorkbook(); HSSFCellStyle style = workbook.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//左右居中样式 HSSFSheet sheet = workbook.createSheet("我的联系人"); //sheet页的名称叫“我的联系人” sheet.setColumnWidth(0, 2000); sheet.setColumnWidth(1, 5000); //创建表头(第一行) HSSFRow row = sheet.createRow(0); //列 HSSFCell cell = row.createCell(0); cell.setCellValue("编号"); cell.setCellStyle(style); HSSFCell cell2 = row.createCell(1); cell2.setCellValue("订单id"); cell2.setCellStyle(style); HSSFCell cell3 = row.createCell(2); cell3.setCellValue("订单数量"); cell3.setCellStyle(style); HSSFCell cell4 = row.createCell(3); cell4.setCellValue("订购时间"); cell4.setCellStyle(style); HSSFCell cell5 = row.createCell(4); cell5.setCellValue("客户姓名"); cell5.setCellStyle(style); HSSFCell cell6 = row.createCell(5); cell6.setCellValue("客户手机号"); cell6.setCellStyle(style); HSSFCell cell7 = row.createCell(6); cell7.setCellValue("客户收货地址"); cell7.setCellStyle(style); HSSFCell cell8 = row.createCell(7); cell8.setCellValue("运费"); cell8.setCellStyle(style); HSSFCell cell9 = row.createCell(8); cell9.setCellValue("优惠价格"); cell9.setCellStyle(style); HSSFCell cell10 = row.createCell(9); cell10.setCellValue("快递单号"); cell10.setCellStyle(style); HSSFCell cell11 = row.createCell(10); cell11.setCellValue("快递名称"); cell11.setCellStyle(style); HSSFCell cell12 = row.createCell(11); cell12.setCellValue("总价格"); cell12.setCellStyle(style); //创建数据行 //这些数据行下一步要从数据库中取。。。。。。。。。。。。。 List<Yyworders> list=hdm.selectYywordersByOrderstatus(); //对list集合进行遍历 for(int i =1;i<=list.size();i++) { HSSFRow newrow = sheet.createRow(i); newrow.createCell(0).setCellValue(list.get(i).getId()); newrow.createCell(1).setCellValue(i); newrow.createCell(2).setCellValue(i); newrow.createCell(3).setCellValue(i); newrow.createCell(4).setCellValue(i); newrow.createCell(5).setCellValue(i); newrow.createCell(6).setCellValue(i); newrow.createCell(7).setCellValue(i); newrow.createCell(8).setCellValue(i); newrow.createCell(9).setCellValue(i); newrow.createCell(10).setCellValue(i); newrow.createCell(11).setCellValue(i); } try { workbook.write(stream); System.out.println("下载成功"); stream.flush(); stream.close(); } catch (Exception e) { e.printStackTrace(); } }[/quote] 你在poi_down中加打印信息,看执行到哪一步了
ing_gni 2017-07-19
  • 打赏
  • 举报
回复
引用 4 楼 zc881124 的回复:
[quote=引用 3 楼 ing_gni 的回复:]
我试过这样 他会报错 找不到页面


错误贴出来,以及错误对应具体的代码行贴出来[/quote]



private void poi_down(HttpServletRequest request,HttpServletResponse response) {
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=data.xls");
//通过mybatis对数据进行入库和更新操作
DefaultSqlSessionFactory sqlSession = (DefaultSqlSessionFactory) SpringUtil.getObject("sqlSessionFactory");
SqlSession session = sqlSession.openSession();

// 获取Mapper
YywordersMapper hdm = session.getMapper(YywordersMapper.class);
// hdm.selectList();

// List<Yyworders> l = .getNeedExpressOrders();

// Hydata hd = new Hydata();
// hd.setId(32640);
// hd =hdm.selectById(hd);
ServletOutputStream stream = null;
try {
stream = response.getOutputStream();
} catch (IOException e1) {
e1.printStackTrace();
}
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//左右居中样式

HSSFSheet sheet = workbook.createSheet("我的联系人"); //sheet页的名称叫“我的联系人”
sheet.setColumnWidth(0, 2000);
sheet.setColumnWidth(1, 5000);


//创建表头(第一行)
HSSFRow row = sheet.createRow(0);
//列
HSSFCell cell = row.createCell(0);
cell.setCellValue("编号");
cell.setCellStyle(style);
HSSFCell cell2 = row.createCell(1);
cell2.setCellValue("订单id");
cell2.setCellStyle(style);
HSSFCell cell3 = row.createCell(2);
cell3.setCellValue("订单数量");
cell3.setCellStyle(style);
HSSFCell cell4 = row.createCell(3);
cell4.setCellValue("订购时间");
cell4.setCellStyle(style);
HSSFCell cell5 = row.createCell(4);
cell5.setCellValue("客户姓名");
cell5.setCellStyle(style);
HSSFCell cell6 = row.createCell(5);
cell6.setCellValue("客户手机号");
cell6.setCellStyle(style);
HSSFCell cell7 = row.createCell(6);
cell7.setCellValue("客户收货地址");
cell7.setCellStyle(style);
HSSFCell cell8 = row.createCell(7);
cell8.setCellValue("运费");
cell8.setCellStyle(style);
HSSFCell cell9 = row.createCell(8);
cell9.setCellValue("优惠价格");
cell9.setCellStyle(style);
HSSFCell cell10 = row.createCell(9);
cell10.setCellValue("快递单号");
cell10.setCellStyle(style);
HSSFCell cell11 = row.createCell(10);
cell11.setCellValue("快递名称");
cell11.setCellStyle(style);
HSSFCell cell12 = row.createCell(11);
cell12.setCellValue("总价格");
cell12.setCellStyle(style);

//创建数据行 //这些数据行下一步要从数据库中取。。。。。。。。。。。。。

List<Yyworders> list=hdm.selectYywordersByOrderstatus();
//对list集合进行遍历

for(int i =1;i<=list.size();i++) {

HSSFRow newrow = sheet.createRow(i);
newrow.createCell(0).setCellValue(list.get(i).getId());
newrow.createCell(1).setCellValue(i);
newrow.createCell(2).setCellValue(i);
newrow.createCell(3).setCellValue(i);
newrow.createCell(4).setCellValue(i);
newrow.createCell(5).setCellValue(i);
newrow.createCell(6).setCellValue(i);
newrow.createCell(7).setCellValue(i);
newrow.createCell(8).setCellValue(i);
newrow.createCell(9).setCellValue(i);
newrow.createCell(10).setCellValue(i);
newrow.createCell(11).setCellValue(i);

}
try {
workbook.write(stream);
System.out.println("下载成功");
stream.flush();
stream.close();
} catch (Exception e) {
e.printStackTrace();
}

}
110成成 2017-07-19
  • 打赏
  • 举报
回复
引用 3 楼 ing_gni 的回复:
我试过这样 他会报错 找不到页面
错误贴出来,以及错误对应具体的代码行贴出来
加载更多回复(2)

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧