Results 1 to 4 of 4
  1. #1
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default exporting data to excell using XSSFWorkbook class

    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



    org.apache.poi.xssf.usermodel.examples: BigGridDemo.java
    POI - User - HSSF and XSSF memory usage, some numbers


    how can i modify my code to BigGridDemo.java
    Java 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();
    
                    }          
    
                    }
    currently am geting this error with above code
    <FileDownloadActionListener> <processAction>
    javax.el.ELException: java.lang.OutOfMemoryError: Java heap space
    at com.sun.el.parser.AstValue.invoke(Unknown Source)
    at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
    at org.apache.myfaces.trinidadinternal.taglib.listene r.FileDownloadActionListener.processAction(FileDow nloadActionListener.java:121)
    at oracle.adfinternal.view.faces.event.rich.FileDownl oadActionListener.processAction(FileDownloadAction Listener.java:88)
    at javax.faces.event.ActionEvent.processListener(Acti onEvent.java:88)
    at org.apache.myfaces.trinidad.component.UIXComponent Base.broadcast(UIXComponentBase.java:748)
    at org.apache.myfaces.trinidad.component.UIXCommand.b roadcast(UIXCommand.java:179)
    at oracle.adfinternal.view.faces.lifecycle.LifecycleI mpl.broadcastEvents(LifecycleImpl.java:1086)
    at oracle.adfinternal.view.faces.lifecycle.LifecycleI mpl._executePhase(LifecycleImpl.java:434)
    at oracle.adfinternal.view.faces.lifecycle.LifecycleI mpl.execute(LifecycleImpl.java:207)
    at javax.faces.webapp.FacesServlet.service(FacesServl et.java:265)
    at weblogic.servlet.internal.StubSecurityHelper$Servl etServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invok eServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute( ServletStubImpl.java:300)
    at weblogic.servlet.internal.TailFilter.doFilter(Tail Filter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:56)
    at oracle.adf.model.servlet.ADFBindingFilter.doFilter (ADFBindingFilter.java:205)
    at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:56)
    at oracle.adfinternal.view.faces.webapp.rich.Registra tionFilter.doFilter(RegistrationFilter.java:128)
    at org.apache.myfaces.trinidadinternal.webapp.Trinida dFilterImpl$FilterListChain.doFilter(TrinidadFilte rImpl.java:446)
    at oracle.adfinternal.view.faces.activedata.AdsFilter .doFilter(AdsFilter.java:60)
    at org.apache.myfaces.trinidadinternal.webapp.Trinida dFilterImpl$FilterListChain.doFilter(TrinidadFilte rImpl.java:446)
    at org.apache.myfaces.trinidadinternal.webapp.Trinida dFilterImpl._doFilterImpl(TrinidadFilterImpl.java: 271)
    at org.apache.myfaces.trinidadinternal.webapp.Trinida dFilterImpl.doFilter(TrinidadFilterImpl.java:177)
    at org.apache.myfaces.trinidad.webapp.TrinidadFilter. doFilter(TrinidadFilter.java:92)
    at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:56)
    at oracle.adf.library.webapp.LibraryFilter.doFilter(L ibraryFilter.java:180)
    at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:56)
    at oracle.security.jps.ee.http.JpsAbsFilter$1.run(Jps AbsFilter.java:119)
    at java.security.AccessController.doPrivileged(Native Method)
    at oracle.security.jps.util.JpsSubject.doAsPrivileged (JpsSubject.java:324)
    at oracle.security.jps.ee.util.JpsPlatformUtil.runJaa sMode(JpsPlatformUtil.java:460)
    at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMo de(JpsAbsFilter.java:103)
    at oracle.security.jps.ee.http.JpsAbsFilter.doFilter( JpsAbsFilter.java:171)
    at oracle.security.jps.ee.http.JpsFilter.doFilter(Jps Filter.java:71)
    at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:56)
    at oracle.dms.servlet.DMSServletFilter.doFilter(DMSSe rvletFilter.java:163)
    at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:56)
    at weblogic.servlet.internal.RequestEventsFilter.doFi lter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$Ser vletInvocationAction.wrapRun(WebAppServletContext. java:3715)
    at weblogic.servlet.internal.WebAppServletContext$Ser vletInvocationAction.run(WebAppServletContext.java :3681)
    at weblogic.security.acl.internal.AuthenticatedSubjec t.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(Se curityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.sec uredExecute(WebAppServletContext.java:2277)
    at weblogic.servlet.internal.WebAppServletContext.exe cute(WebAppServletContext.java:2183)
    at weblogic.servlet.internal.ServletRequestImpl.run(S ervletRequestImpl.java:1454)
    at weblogic.work.ExecuteThread.execute(ExecuteThread. java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java :178)
    Caused by: java.lang.OutOfMemoryError: Java heap space
    Last edited by 009; 06-09-2014 at 11:05 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: exporting data to excell using XSSFWorkbook class

    You're running out of memory.
    How big is the file you're trying to work with?

    Also, use code tags, not quote tags, when posting code.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: exporting data to excell using XSSFWorkbook class

    am having 297052 rows and 6 columns ,yes am running out of memory.i think the size is 14.5 MB
    Last edited by 009; 06-09-2014 at 11:08 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: exporting data to excell using XSSFWorkbook class

    See my comments in the other thread.
    Don't spam the forum.

    I'll lock this one and we can continue in the other one.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 04-27-2013, 11:54 PM
  2. way to upload data from Excell
    By raj.mscking@gmail.com in forum Android
    Replies: 0
    Last Post: 12-13-2012, 11:49 AM
  3. How to copy cell styles in an XSSFWorkbook?
    By laredotornado in forum Apache POI
    Replies: 2
    Last Post: 04-03-2012, 05:36 PM
  4. exporting data from .xml file to mysql
    By nitish0401 in forum JDBC
    Replies: 5
    Last Post: 12-06-2011, 11:17 AM
  5. Replies: 0
    Last Post: 03-18-2011, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •