Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

exporting data to excell using XSSFWorkbook

Tony007Jun 6 2014 — edited Jun 13 2014

hi have anyone export data to excell using  XSSFWorkbook

am having error javax.el.ELException: java.lang.OutOfMemoryError: Java heap space now i what to modify my code to BigGridDemo.java

http://www.docjar.org/html/api/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java.html

http://apache-poi.1045710.n5.nabble.com/HSSF-and-XSSF-memory-usage-some-numbers-td4312784.html

how can i modify my code to BigGridDemo.java

this is my code

import com.bea.common.security.xacml.context.Result;

import com.sun.jmx.snmp.Timestamp;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.OutputStream;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import org.apache.poi.ss.usermodel.*;

import javax.faces.context.FacesContext;

//import org.apache.poi.hssf.usermodel.HSSFCell;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;

import org.apache.poi.hssf.usermodel.HSSFDataFormat;

//import org.apache.poi.hssf.usermodel.HSSFRow;

//import org.apache.poi.hssf.usermodel.HSSFSheet;

//import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.*;

import org.apache.poi.hssf.util.HSSFColor;

import oracle.adf.model.BindingContainer;

import oracle.adf.model.BindingContext;

import oracle.adf.model.binding.DCBindingContainer;

import oracle.adf.model.binding.DCIteratorBinding;

import oracle.adf.view.rich.component.rich.data.RichTable;

import org.apache.poi.POIDocument;

//import org.apache.poi

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

//import org.apache.poi.hssf.usermodel.*;

//import oracle.jbo.Row;

import oracle.jbo.RowSetIterator;

import oracle.jbo.ViewObject;

import org.apache.myfaces.trinidad.model.CollectionModel;

import org.apache.myfaces.trinidad.model.RowKeySet;

import org.apache.myfaces.trinidad.model.RowKeySetImpl;

import org.apache.poi.hssf.usermodel.HSSFRichTextString;

import org.apache.poi.ss.usermodel.Workbook;

import org.apache.poi.POIXMLDocumentPart;

import org.apache.poi.POIXMLDocument;

import org.apache.poi.hssf.usermodel.HSSFRow;

import org.apache.poi.hssf.usermodel.HSSFSheet;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiBean {

  

         RichTable CustomTable;

       

    public PoiBean() {

    }

        public static BindingContainer getBindingContainer() {

            //return (BindingContainer)JSFUtils.resolveExpression("#{bindings}");

            return (BindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();

        }

        public static DCBindingContainer getDCBindingContainer() {

            return (DCBindingContainer)getBindingContainer();

        }

      

      

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

        try {

     

        Workbook workbook = new XSSFWorkbook();  //or new HSSFWorkbook();

        Sheet worksheet = workbook.createSheet("Fonts");  

        // 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);

       // cellA1.setCellValue(colName);

        cellCounter++;

        }

        }

        //print data from second row in excel

        rowCounter++;

        //////////////////////////////////////////////////////////////

        //short j = 0;

        int cellCounter = 0;

      

    //excelrow = (HSSFRow)worksheet.createRow((int)i);

            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();

            }         

            }

This post has been answered by Alex Geller on Jun 10 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2014
Added on Jun 6 2014
12 comments
7,413 views