Quantcast
Channel: Java Programming Forum - Learn Java Programming - Apache POI
Viewing all articles
Browse latest Browse all 120

how to tune and optimize POI Code

$
0
0
hi am exporting adf table to excell i what to optimize my code using BigGridDemo.java

how can i do the same using below code

[code]
Code:

public void generateExcel(FacesContext facesContext, OutputStream outputStream) throws IOException {

 
        try {

 
       

 
       
       
       
       
       
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet worksheet = workbook.createSheet("Big Grid");
       
       
       

 
        // Get all the rows of a iterator
        /////////////////////////////////////////////////////////////////////////////////////////////////////

 
        DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dcIteratorBindings = bindings.findIteratorBinding("CustomClientView1Iterator");
       
        Row rowss = worksheet.createRow(0);
        ViewObject yourVO= dcIteratorBindings.getViewObject();
        // Get all the rows of a ViewObject
        RowSetIterator iter = yourVO.createRowSetIterator("CustomClient");
        iter.reset();
        int rowCounter = 0;
        while (iter.hasNext()){
        Cell cell = null;
        oracle.jbo.Row row = iter.next();

 
        //print header on first row in excel
        if (rowCounter == 0) {
        rowss = worksheet.createRow(rowCounter);
        int cellCounter = 0;

 
        for (String colName : row.getAttributeNames()) {
        cell = rowss.createCell(cellCounter);
        cell.setCellValue(colName);

 
        // cellA1.setCellValue(colName);

 
        cellCounter++;
        }
        }
        //print data from second row in excel

 
        rowCounter++;
        //////////////////////////////////////////////////////////////
       

 
        int cellCounter = 0;

 
       

 

 
        rowss = worksheet.createRow(rowCounter);
        for (String colName : row.getAttributeNames()) {
        System.out.println("hello "+row.getAttribute(colName));
        System.out.println("hello "+colName);
       
        cell = rowss.createCell(cellCounter);
        rowCounter++;

 
        /// cell.setCellValue(new HSSFRichTextString(rs.getS));
        if(!isBlank(colName)){
        if (colName.equalsIgnoreCase("CcnCode")) {
        cell.setCellValue(row.getAttribute(colName).toString());
        System.out.println("colName "+colName+"row.getAttribute(colName).toString()"+row.getAttribute(colName).toString());
        }
        }
        //logic for cell formatting
       
        else if (colName.equalsIgnoreCase("CcnName")) {
        cell.setCellValue(row.getAttribute(colName).toString());
        }
       

 
        //make it double if you want and convert accordingly
        else if (colName.equalsIgnoreCase("CcnRegDate")){
        cell.setCellValue(row.getAttribute(colName).toString());
        }

 
        else if (colName.equalsIgnoreCase("CcnCancelDate")){

 
        if(null!=row.getAttribute(colName)){

 
        cell.setCellValue(row.getAttribute(colName).toString());

 
        }

 
        } else if (colName.equalsIgnoreCase("CcnUndertaking")){

 
        if(null!=row.getAttribute(colName)){
        cell.setCellValue(row.getAttribute(colName).toString());
        }
        }

 
        else if (colName.equalsIgnoreCase("CcnCode8")){

 
        if(null!=row.getAttribute(colName)){

 
        cell.setCellValue(row.getAttribute(colName).toString());

 
        }                                                                                                            }

 
        else
        cell.setCellValue(row.getAttribute(colName).toString());
        cellCounter++;
        }

 
        worksheet.createFreezePane(0, 1, 0, 1);
        }
        workbook.write(outputStream);
        outputStream.flush();
        }
       
       
        catch (Exception e) {
        e.printStackTrace();
        }         
        }

[code]
AM running out of memory

Viewing all articles
Browse latest Browse all 120

Trending Articles