Apache POI非常慢

时间:2017-01-30 11:17:33

标签: java excel apache logging apache-poi

我正在尝试导出xls文件。但由于某种原因,apache poi非常缓慢。我看不到任何日志,所以似乎关闭了日志记录。这是我的代码。导出数据不是那么大(3000行)。 WebSphere Portal 7.0。帮助,请。

if (divideBySchool==null || (!sessionApplicationTypeId.equals(PROGRAM_DIRECT) && !sessionApplicationTypeId.equals(PROGRAM_FOUNDATION) && !sessionApplicationTypeId.equals(PROGRAM_TRANSFER))){

                        List<RField> formFields = sbLocal.getFieldsByApplicationType(sessionApplicationTypeId, fieldsToTake);
                        int colNum=2;
                        int rowNum=0;

                        org.apache.poi.ss.usermodel.Row headerRow = sheet.createRow(rowNum);
                        org.apache.poi.ss.usermodel.Cell cell = headerRow.createCell(1);
                        cell.setCellValue("Applicant ID");
                        cell.setCellStyle(styles.get("header"));
                        sheet.setColumnWidth(1, 256*25);

                        for (RField rField : formFields) {
                            cell = headerRow.createCell(colNum);
                            cell.setCellValue(rField.getName());
                            cell.setCellStyle(styles.get("header"));
                            sheet.setColumnWidth(colNum, 256*25);
                            colNum++;
                        }   

                        cell = headerRow.createCell(colNum);
                        cell.setCellValue("Applicant status");
                        cell.setCellStyle(styles.get("header"));
                        sheet.setColumnWidth(colNum, 256*25);

                        if (fieldsToTake.equals(IN_EXAM)){
                            cell = headerRow.createCell(colNum+1);
                            cell.setCellValue("Exam status");
                            cell.setCellStyle(styles.get("header"));
                            sheet.setColumnWidth(colNum, 256*25);

                            cell = headerRow.createCell(colNum+2);
                            cell.setCellValue("Note");
                            cell.setCellStyle(styles.get("header"));
                            sheet.setColumnWidth(colNum, 256*25);
                        }   

                        System.out.println("Time for label ==============>" + (System.currentTimeMillis() - start));
                        start = System.currentTimeMillis();

                        rowNum++;
                        int k=1;

                        for (int i = 0; i < applicants.length(); i++)  {
                            headerRow = sheet.createRow(rowNum);

                            cell = headerRow.createCell(0);
                            cell.setCellValue(String.valueOf(k));
                            //dataCell.setCellStyle(styles.get("cell_normal"));

                            cell = headerRow.createCell(1);
                            cell.setCellValue(applicants.getJSONObject(i).getString("APPLICANT_ID"));
                            //dataCell.setCellStyle(styles.get("cell_normal"));

                            colNum=2;
                            for (RField rField : formFields) {
                                if (applicants.getJSONObject(i).has(String.valueOf(rField.getFieldId()))){
                                    //rField.getRFieldType().getFieldTypeId()
                                    String value = applicants.getJSONObject(i).getString(String.valueOf(rField.getFieldId()));
                                    if(rField.getRFieldType().getFieldTypeId() == 3 && rField.getFieldId() != 797){
                                        value = value.split(" ")[0];
                                    }
                                    cell = headerRow.createCell(colNum);
                                    cell.setCellValue(value);
                                    //dataCell.setCellStyle(styles.get("cell_normal"));
                                } else{
                                    cell = headerRow.createCell(colNum);
                                    cell.setCellValue("");
                                    //dataCell.setCellStyle(styles.get("cell_normal"));
                                }
                                colNum++;
                            }
                            if (!applicants.getJSONObject(i).isNull("APPLICANT_STATUS")){
                                cell = headerRow.createCell(colNum);
                                cell.setCellValue(applicants.getJSONObject(i).getString("APPLICANT_STATUS"));
                                ////dataCell.setCellStyle(styles.get("cell_normal"));
                            }
                            else{
                                cell = headerRow.createCell(colNum);
                                cell.setCellValue("");
                                //dataCell.setCellStyle(styles.get("cell_normal"));
                            }

                            if (fieldsToTake.equals(IN_EXAM)){
                                if (applicants.getJSONObject(i).has("EXAM_STATUS_NAME")){
                                    cell = headerRow.createCell(colNum+1);
                                    cell.setCellValue(applicants.getJSONObject(i).getString("EXAM_STATUS_NAME"));
                                    //dataCell.setCellStyle(styles.get("cell_normal"));
                                    //sheet.addCell(new Label(colNum+1, rowNum, applicants.getJSONObject(i).getString("EXAM_STATUS_NAME"), cellFormat));
                                } else{
                                    cell = headerRow.createCell(colNum+1);
                                    cell.setCellValue("");
                                    //dataCell.setCellStyle(styles.get("cell_normal"));
                                    //sheet.addCell(new Label(colNum+1, rowNum, "", cellForm));
                                }
                                if (applicants.getJSONObject(i).has("NOTE")){
                                    colNum++;
                                    cell = headerRow.createCell(colNum+2);
                                    cell.setCellValue(applicants.getJSONObject(i).getString("NOTE"));
                                    //dataCell.setCellStyle(styles.get("cell_normal"));
                                    //sheet.addCell(new Label(colNum+2, rowNum, applicants.getJSONObject(i).getString("NOTE"), cellFormat));
                                }else{
                                    cell = headerRow.createCell(colNum+2);
                                    cell.setCellValue("");
                                    //dataCell.setCellStyle(styles.get("cell_normal"));
                                    //sheet.addCell(new Label(colNum+2, rowNum, "", cellForm));
                                }
                            }
                            rowNum++;
                            k++;
                        }
                        System.out.println("Time for filling ==============>" + (System.currentTimeMillis() - start));

0 个答案:

没有答案
相关问题