Bug 51492 - HssfWorkBook don't export excel from oracle when exporting more then about 4000 rows data?
Summary: HssfWorkBook don't export excel from oracle when exporting more then about 40...
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: PC Windows Server 2003
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-09 09:07 UTC by fengshuiyue
Modified: 2011-07-09 11:58 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description fengshuiyue 2011-07-09 09:07:26 UTC
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 {

        }
Comment 1 Nick Burch 2011-07-09 11:58:52 UTC
Bugzilla is for reporting bugs, please use the user list for questions on using POI