poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 51492] New: HssfWorkBook don't export excel from oracle when exporting more then about 4000 rows data?
Date Sat, 09 Jul 2011 09:07:26 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=51492

             Bug #: 51492
           Summary: HssfWorkBook don't export excel from oracle when
                    exporting more then about 4000 rows data?
           Product: POI
           Version: unspecified
          Platform: PC
        OS/Version: Windows Server 2003
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: zhy36007@163.com
    Classification: Unclassified


hello,I use poi to export excel from oracle database,I find a problem.When I
export about 2000 rows data,it work fine,but when I export about 4000 rows
data,it don't alert the download dialog and it can restart to export and the
web page shows error page.my code is following:

            System.out.println("...........onPageLoad");
            this.getBzhAM().getDBTransaction().rollback();
            String voString = 
               
this.getHttpSession().getAttribute("ExportExcelList").toString();
            ViewObject vo = getBzhAM().findViewObject(voString);
            DataRowBean bean = 
               
(DataRowBean)this.getHttpSession().getAttribute("ExportExcelHeaderText");
            DataRowBean beanAttrCode = 
               
(DataRowBean)this.getHttpSession().getAttribute("ExportExcelAttrCode");
            String exportFileName = 
               
this.getHttpSession().getAttribute("ExportFileName").toString();

            this.getHttpSession().removeAttribute("ExportExcelList");
            this.getHttpSession().removeAttribute("ExportExcelHeaderText");
            this.getHttpSession().removeAttribute("ExportExcelAttrCode");
            this.getHttpSession().removeAttribute("ExportFileName");
            System.out.println("exportFileName--->" + exportFileName);
            if (this.getHttpRequest().getHeader("user-agent").indexOf("MSIE")
!=-1) {
                exportFileName = 
                        java.net.URLEncoder.encode(exportFileName, "utf-8") + 
                        ".xls";
            } else {
                exportFileName = 
                        new String(exportFileName.getBytes("utf-8"),
"iso-8859-1") + ".xls";
            }
            HttpServletResponse response = getResponse();
            response.setContentType("octets/stream");
            response.addHeader("Content-Disposition", 
                               "attachment;filename=" + exportFileName);

            ServletOutputStream out = response.getOutputStream();
            HSSFWorkbook workbook = new HSSFWorkbook();
            //HSSFSheet sheet;  = workbook.createSheet("标准化数据导出");
            
System.out.println("response.getBufferSize()="+response.getBufferSize());
             response.setBufferSize(4096);
            
System.out.println("response.getBufferSize()="+response.getBufferSize());
            int num = 0;
            if (vo.getRowCount() > Integer.MAX_VALUE) {
                num = Integer.MAX_VALUE;
            } else {
                num = vo.getRowCount();
            }
            int divNum = 1000;
            for (int i = 0; i < num / divNum + 1; i++) {
                int flagNum;
                if ((i + 1) * divNum > num) {
                    flagNum = num;
                } else {
                    flagNum = (i + 1) * divNum;
                }
                System.out.println("flagNum=" + flagNum);
                HSSFSheet sheet = workbook.createSheet("标准化数据导出" + "表" + i);
                System.out.println("createSheet:"+sheet.toString());
                System.out.println("一个sheet开始");
               
System.out.println("==========================================================================");
                sheet.setDefaultColumnWidth((short)25);
                    for (int m = i * divNum; m < flagNum + 1; m++) {
                        HSSFRow row;
                        if (m % divNum == 0 && m == flagNum) {
                            row = sheet.createRow(divNum);
                        } else {
                            row = sheet.createRow(m % divNum);
                        }
                        short n;
                        for (n = 0; n < bean.getAttributeCount(); n++) {
                            HSSFCell cell = row.createCell(n);
                            if (m % divNum == 0 && m != flagNum) {
                                cell.setCellValue(bean.getAttributeValue(n + 
                                                                         1));
                            } else {
                                String attrCode = 
                                    beanAttrCode.getAttributeValue(n + 1);
                                if ("OrderNo".equals(attrCode)) {
                                    cell.setCellValue(String.valueOf(m));
                                } else {
                                   
cell.setCellValue(Tools.notNull(vo.getRowAtRangeIndex(m -
1).getAttribute(beanAttrCode.getAttributeValue(n + 1))));
                                }
                            }

            workbook.write(out);
            System.out.println("==========下载完毕");
            out.close();
        } catch (Exception e) {
            System.out.println("==========下载出错");
            e.printStackTrace();
        } finally {

        }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message