Skip to Main Content

Java Development Tools

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!

problem exporting adf table to excell using POI

Tony007Jun 3 2014 — edited Jun 4 2014

Hi am in jdeveloper 11.1.1.7.0 am trying to export my adf table to excell using Apache POI

my problem is that when i export the table it only export that page i am into it only export 31 rows not all 200 000 rows

i use this sample http://www.techartifact.com/blogs/2013/08/generate-excel-file-in-oracle-adf-using-apache-poi.html#sthash.F25sUk5s.eo1IZ8V2.dpbs

this is my jspx page

<af:table value="#{bindings.CustomClientView1.collectionModel}"

                    var="row" rows="#{bindings.CustomClientView1.rangeSize}"

                    emptyText="#{bindings.CustomClientView1.viewable ? 'No data to display.' : 'Access Denied.'}"

                    fetchSize="#{bindings.CustomClientView1.rangeSize}"

                    rowBandingInterval="0"

                    selectedRowKeys="#{bindings.CustomClientView1.collectionModel.selectedRow}"

                    selectionListener="#{bindings.CustomClientView1.collectionModel.makeCurrent}"

                    rowSelection="single" id="t1" columnStretching="last"

                    autoHeightRows="0"

                    styleClass="AFStretchWidth" inlineStyle="height:640px;"

                    scrollPolicy="page">

            <af:column sortProperty="#{bindings.CustomClientView1.hints.CcnCode.name}"

                       sortable="true"

                       headerText="#{bindings.CustomClientView1.hints.CcnCode.label}"

                       id="c5">

              <af:outputText value="#{row.CcnCode}" id="ot1"/>

            </af:column>

            <af:column sortProperty="#{bindings.CustomClientView1.hints.CcnName.name}"

                       sortable="true"

                       headerText="#{bindings.CustomClientView1.hints.CcnName.label}"

                       id="c4">

              <af:outputText value="#{row.CcnName}" id="ot6"/>

            </af:column>

            <af:column sortProperty="#{bindings.CustomClientView1.hints.CcnRegDate.name}"

                       sortable="true"

                       headerText="#{bindings.CustomClientView1.hints.CcnRegDate.label}"

                       id="c6">

              <af:outputText value="#{row.CcnRegDate}" id="ot4">

                <af:convertDateTime pattern="#{bindings.CustomClientView1.hints.CcnRegDate.format}"/>

              </af:outputText>

            </af:column>

            <af:column sortProperty="#{bindings.CustomClientView1.hints.CcnCancelDate.name}"

                       sortable="true"

                       headerText="#{bindings.CustomClientView1.hints.CcnCancelDate.label}"

                       id="c2">

              <af:outputText value="#{row.CcnCancelDate}" id="ot3">

                <af:convertDateTime pattern="#{bindings.CustomClientView1.hints.CcnCancelDate.format}"/>

              </af:outputText>

            </af:column>

            <af:column sortProperty="#{bindings.CustomClientView1.hints.CcnUndertaking.name}"

                       sortable="true"

                       headerText="#{bindings.CustomClientView1.hints.CcnUndertaking.label}"

                       id="c3">

              <af:outputText value="#{row.CcnUndertaking}" id="ot2"/>

            </af:column>

            <af:column sortProperty="#{bindings.CustomClientView1.hints.CcnCode8.name}"

                       sortable="true"

                       headerText="#{bindings.CustomClientView1.hints.CcnCode8.label}"

                       id="c1">

              <af:outputText value="#{row.CcnCode8}" id="ot5"/>

            </af:column>

          </af:table>

and this is my bean code

package vinay.view;

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.Map;

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.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;

public class PoiBean {

    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 {

       

                          

                                HSSFWorkbook workbook = new HSSFWorkbook();

                                    HSSFSheet worksheet = workbook.createSheet("POI Worksheet");

            

                                DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();

                                DCIteratorBinding dcIteratorBindings = bindings.findIteratorBinding("CustomClientView1Iterator");

                                HSSFRow  excelrow = null;

            

                                        // Get all the rows of a iterator

                                        oracle.jbo.Row[] rows = dcIteratorBindings.getAllRowsInRange();

                                    int i = 0;

                           

                                            for (oracle.jbo.Row row : rows) {

                                                //print header on first row in excel

                                                if (i == 0) {

                                                    excelrow = (HSSFRow)worksheet.createRow((short)i);

                                                    short j = 0;

                                                    for (String colName : row.getAttributeNames()) {

                                                    

                                                            HSSFCell cellA1 = excelrow.createCell((short) j);

                                                            cellA1.setCellValue(colName);

                                                            j++;

                                                      

                                                    }

                                                }

                                                //print data from second row in excel

                                                ++i;

                                                short j = 0;

                                                excelrow = worksheet.createRow((short)i);

                                                for (String colName : row.getAttributeNames()) {

                                                    System.out.println("hello "+row.getAttribute(colName));

                                                    System.out.println("hello "+colName);

                                                        HSSFCell  cell = excelrow.createCell(j);

                                                    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

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

                                                        j++;

                                                    

                                                    }

                                              

                                                   worksheet.createFreezePane(0, 1, 0, 1);

                                               }

              workbook.write(outputStream);

              outputStream.flush();

            

          }

                                            catch (Exception e) {

                                          e.printStackTrace();

                                            }

                                      

      }

      }

this is my view

<ViewObject

  xmlns="http://xmlns.oracle.com/bc4j"

  Name="CustomClientView"

  Version="11.1.1.64.93"

  InheritPersonalization="true"

  SelectList="CustomClient.CCN_CODE,

       CustomClient.CCN_NAME,

       CustomClient.CCN_REG_DATE,

       CustomClient.CCN_CANCEL_DATE,

       CustomClient.CCN_UNDERTAKING,

       CustomClient.CCN_CODE_8"

  FromList="CUSTOM_CLIENT CustomClient"

  BindingStyle="OracleName"

  CustomQuery="false"

  FetchMode="FETCH_AS_NEEDED"

  PageIterMode="Full"

  UseGlueCode="false">

  <DesignTime>

    <Attr Name="_codeGenFlag2" Value="Access|VarAccess"/>

  </DesignTime>

  <EntityUsage

    Name="CustomClient"

    Entity="model.CustomClient"/>

  <ViewAttribute

    Name="CcnCode"

    IsNotNull="true"

    PrecisionRule="true"

    EntityAttrName="CcnCode"

    EntityUsage="CustomClient"

    AliasName="CCN_CODE"/>

  <ViewAttribute

    Name="CcnName"

    PrecisionRule="true"

    EntityAttrName="CcnName"

    EntityUsage="CustomClient"

    AliasName="CCN_NAME"/>

  <ViewAttribute

    Name="CcnRegDate"

    PrecisionRule="true"

    EntityAttrName="CcnRegDate"

    EntityUsage="CustomClient"

    AliasName="CCN_REG_DATE"/>

  <ViewAttribute

    Name="CcnCancelDate"

    PrecisionRule="true"

    EntityAttrName="CcnCancelDate"

    EntityUsage="CustomClient"

    AliasName="CCN_CANCEL_DATE"/>

  <ViewAttribute

    Name="CcnUndertaking"

    PrecisionRule="true"

    EntityAttrName="CcnUndertaking"

    EntityUsage="CustomClient"

    AliasName="CCN_UNDERTAKING"/>

  <ViewAttribute

    Name="CcnCode8"

    PrecisionRule="true"

    EntityAttrName="CcnCode8"

    EntityUsage="CustomClient"

    AliasName="CCN_CODE_8"/>

</ViewObject>

//Read more: http://www.techartifact.com/blogs/2013/08/generate-excel-file-in-oracle-adf-using-apache-poi.html#ixzz33UPy51KL

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 2 2014
Added on Jun 3 2014
15 comments
7,472 views