4 Replies Latest reply: Aug 26, 2013 2:23 AM by 1012433 RSS

    How to achieve exporto excel format using managed bean class?

    1012433

      Hi,

      I am using jdev11.1.1.2.3

       

       

      My requirement is get excel sheet using bean class calling

       

      In first case i develop one user defined component which is named as global component is under component pallete in this component i have

      different image icons which for save,insert,excel.....for excel image i drag exportcollectionactionlistener drop on  excel image this is one projecet

      name as globalcomponent

       

      after that i have another project which isnamed as admin project add my global project to admin

       

      in this admin page i have one master top on this page i got icons excel,save like etc... in this case of excel i call actiolistener class to call method

      to get excel attachment in download way..

       

      My code is in action listener is like this

       

      public void exportToExcel(ActionEvent actionEvent) throws IOException
      {
      String filename = "CurrencyList.xls";
      FacesContext fc = FacesContext.getCurrentInstance();
      BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
      // get response object.
      HttpServletResponse response = (HttpServletResponse)fc.getExternalContext().getResponse();
      // Set the file name
      response.setHeader("Content-disposition", "attachment; filename=" + filename);
      // Set MIME type to excel
      response.setContentType("application/vnd.ms-excel");
      PrintWriter out = response.getWriter();

       

      DCIteratorBinding theateriter = (DCIteratorBinding)bc.get("pofAdminCurrencyViewIterator");   //pofAdminCurrencyViewIterator
      printtoexcel(theateriter,out);

       

      out.println();

       

      /*  DCIteratorBinding areaiter = (DCIteratorBinding)bc.get("MyVO2Iterator");
      printtoexcel(theateriter,out);*/
      out.close();
      }
      public void printtoexcel(DCIteratorBinding iter, PrintWriter out)
      {
      RowSetIterator rsi = iter.getRowSetIterator();
      String[] attNames = rsi.getRowAtRangeIndex(0).getAttributeNames();
      for (int i = 0; i < attNames.length-1; i++) {
      if (i > 0)
      out.print("\t"); // tab after each value
      out.print(attNames[i]);

      }

       

       

       

       

      my UI Code

       

       

       

      <pofGC:pofGlobalComp id="pgc1"

                             saveCall="#{POFAdminCurrencyBean.doCommit}" firstCall="#{bindings.First.execute}" currPage="Currency Page"

                             cancelCall="#{POFAdminCurrencyBean.doCancel}"

                             addNewCall="#{POFAdminCurrencyBean.doCreateInsert}"

       

       

       

                             lastCall="#{bindings.Last.execute}" nextCall="#{bindings.Next.execute}"

                             previousCall="#{bindings.Previous.execute}" excelCall="#{pofAdminMainActionBean.exportToExcel}">