数据导出excel
Posted Dota_小川
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据导出excel相关的知识,希望对你有一定的参考价值。
发送请求到改页面,可将table下的内容导出到excel
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%> <%@ page import="com.dc.platform.ss.dbinfo.*"%> <%@ page import="com.dc.platform.ss.permission.*" %> <%@ page import="com.dc.platform.ss.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; SEntityList po_apply_goods = (SEntityList)request.getAttribute("po_apply_goods"); response.setContentType("APPLICATION/OCTET-STREAM"); String fileName = "申请物资"; fileName = new String(fileName.getBytes("GBK"),"ISO-8859-1" ); //解决打开文件标题乱码问题 response.setHeader("Content-Disposition", "attachment; filename="+ fileName +".xls"); %> <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=gb2312"> <style> @page {margin:0.5cm 0.5cm 0.5cm 0.5cm; mso-header-margin:.1in; mso-footer-margin:.1in; mso-page-orientation:landscape;} br {mso-data-placement:same-cell;} .td {mso-style-parent:style0; font-size:9.0pt; text-align:center; vertical-align:middle; border:.5pt solid windowtext; /* mso-number-format:"0\.00"; */ white-space:normal; } .stringFormatNumber {mso-style-parent:style0; height="30px"; width="20px"; font-size:9.0pt; text-align:center; vertical-align:middle; border:.5pt solid windowtext; mso-number-format:"\@"; white-space:normal;} </style> <xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name>Sheet1</x:Name> <x:WorksheetOptions> <x:Print> <x:FitHeight>1</x:FitHeight><!-- 工作簿调整为1页高 --> <x:FitWidth>1</x:FitWidth><!-- 工作簿调整为1页宽 --> <x:ValidPrinterInfo/><!--横向控制--> <x:PaperSizeIndex>27</x:PaperSizeIndex><!-- 纸张大小为A4 --> <x:Scale>100</x:Scale><!-- 缩放比例 --> <x:HorizontalResolution>600</x:HorizontalResolution><!-- 打印质量600点/英寸 --> <x:VerticalResolution>0</x:VerticalResolution> </x:Print> <x:Selected/> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> </x:ExcelWorkbook> </xml> </head> <body> <table border="1" cellpadding="0" cellspacing="0"> <tr> <td class="td"> <b>序号</b> </td> <td class="td"> <b>物资名称</b> </td> <td class="td"> <b>规格</b> </td> <td class="td"> <b>数量</b> </td> <td class="td"> <b>单位</b> </td> <td class="td"> <b>物资说明</b> </td> <td class="td"> <b>物资分类</b> </td> <td class="td"> <b>备件所用部位</b> </td> <td class="td"> <b>最近采购价格</b> </td> <td class="td"> <b>年内评价价格</b> </td> <td class="td"> <b>最高采购价格</b> </td> <td class="td"> <b>当前库存量</b> </td> <td class="td"> <b>正在使用厂家</b> </td> <td class="td"> <b>正在使用品牌</b> </td> <td class="td"> <b>推荐厂家</b> </td> <td class="td"> <b>推荐品牌</b> </td> <td class="td"> <b>申请理由</b> </td> </tr> <% for(int i=0; i<po_apply_goods.size(); i++){ SEntity sEntity = po_apply_goods.get(i); %> <tr> <td class="td"><%=i+1 %></td> <td class="td"><%=sEntity.getValueAsString("NAME") %></td> <td class="td"><%=sEntity.getValueAsString("MODLE") %></td> <td class="td"><%=sEntity.getValueAsString("APPLY_AMOUNT") %></td> <td class="td"><%=sEntity.getValueAsString("UNIT") %></td> <td class="td"><%=sEntity.getValueAsString("NOTE") %></td> <td class="td"><%=sEntity.getValueAsString("APPLY_PURPOSE") %></td> <td class="td"><%=sEntity.getValueAsString("USE_PLACE") %></td> <td class="td"><%=sEntity.getValueAsString("NEAR_PRICE") %></td> <td class="td"><%=sEntity.getValueAsString("AVG_PRICE") %></td> <td class="td"><%=sEntity.getValueAsString("MAX_PRICE") %></td> <td class="td"><%=sEntity.getValueAsString("CURRENT_INV") %></td> <td class="td"><%=sEntity.getValueAsString("NOW_SUPPLIER") %></td> <td class="td"><%=sEntity.getValueAsString("NOW_TRADEMARK") %></td> <td class="td"><%=sEntity.getValueAsString("PRE_SUPPLIER") %></td> <td class="td"><%=sEntity.getValueAsString("PRE_TRADEMARK") %></td> <td class="td"><%=sEntity.getValueAsString("REAMRK") %></td> </tr> <% } %> </table> </body> </html>
以上是关于数据导出excel的主要内容,如果未能解决你的问题,请参考以下文章