📄 exportexcel.jsp
字号:
<%-- Created by IntelliJ IDEA. User: jtgao Date: 2006-5-21 Time: 16:40:12 To change this template use File | Settings | File Templates.//--%><%@ page contentType="text/html; charset=GBK"%><%@ include file="/IncludeBegin.jsp" %><%@ page import="com.hexiesoft.are.sql.ASResultSet" %><%@ page import="com.hexiesoft.are.util.DataConvert" %><%@ page import="com.hexiesoft.utils.Consts" %><%@ page import="com.hexiesoft.utils.PrintAddPN" %><%@ page import="com.hexiesoft.utils.StringUtils" %><%@ page import="org.apache.poi.hssf.usermodel.HSSFCell" %><%@ page import="org.apache.poi.hssf.usermodel.HSSFRow" %><%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet" %><%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook" %><% //检索的LOT Code String sCode = DataConvert.toRealString(iPostChange, (String) CurPage.getParameter("Code")); //从 packnote 表检索 String sql = "SELECT a.[name],a.add1 , a.add2,a.custpo,a.pnno,a.custspec,a.caseno,rtrim(left(a.[desc],10)) , cast(a.mt_gauge as varchar) +'mm' ,cast(a.mt_width as varchar) +'mm',GETDATE(),a.coils,a.gross,'',a.worksno,b.geocode from packnote a,customer b where pnno ='" + sCode +"' AND a.account=b.account AND a.subacct=b.subacct"; response.reset(); response.setContentType("application/msexcel"); response.setContentType("charset=GBK"); response.setHeader("Content-disposition", "filename=lot.xls");//定义文件名 //存储检索 packnote 表的结果 ASResultSet packnoteRs; //检索 packnote packnoteRs = Sqlca.getASResultSet(sql); if (packnoteRs == null || packnoteRs.getRowCount() == 0) { //检索不到记录,给出提示%><script type="text/javascript"> alert("No records satisfy your request!"); sReturn_isEmpty = PopPage("/ShippingManager/PackingNote/printPackingNote/CheckCode.jsp?Code="+sCode+"&rand="+randomNumber(),"","");</script><% } else { packnoteRs.next(); //在内存中新建一个Excel文件 HSSFWorkbook book = new HSSFWorkbook(); //在Excel文件中新建一个sheet String SheetName = (String) Configure.getConfigure(sIe_Language, "Shipping_PrintPN").get("XLSNAME"); HSSFSheet sheet = book.createSheet(SheetName); //Excel中的一行 HSSFRow row; HSSFCell cell; //初始行号为0 int excelRow = PrintAddPN.REPORTER_COSTS_ROW; //获取报表的列数目,定义在Consts中 int ColNum = PrintAddPN.REPORTER_COSTS_COLNUM; //取得标题数组 String title[] = PrintAddPN.title; //创建标题行 第一列 标题 7行 // for (int i = 0; i < excelRow; i++) { //创建行 row = sheet.createRow(i); ColNum = PrintAddPN.REPORTER_COSTS_COLNUM; //第一列 cell = row.createCell((short) ColNum++); cell.setEncoding((short) 1); //编码格式设置 cell.setCellValue(title[i]); //标题赋值 //第二列 cell = row.createCell((short) ColNum++); cell.setEncoding((short) 1); cell.setCellValue(packnoteRs.getString(i + 1));//取得数据库数据 //第三列 cell = row.createCell((short) ColNum++); cell.setEncoding((short) 1); cell.setCellValue(title[i + excelRow]);//标题赋值 //第四列 cell = row.createCell((short) ColNum++); cell.setEncoding((short) 1); cell.setCellValue(packnoteRs.getString(i+1+excelRow));//取得数据库数据 } response.setContentType("application/msexcel"); response.setContentType("charset=GBK"); //从配置文件读取文件名 String FileName = new String(((String) Configure.getConfigure(sIe_Language, "Shipping_PrintPN").get("XLSNAME")).getBytes(), "GB2312"); //System.out.println(" FileName= " + FileName); response.setHeader("Content-disposition", "inline;filename=" + FileName);//定义Excel文件名 book.write(response.getOutputStream()); response.getOutputStream().flush(); response.getOutputStream().close(); }%><%@ include file="/IncludeEnd.jsp" %>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -