2013-08-06 21 views
5

Ho un <p:dataTable>:primefaces DataExporter in XLS per più colonne non funziona correttamente

<p:dataTable id="contracttblenone" var="contract" value="#{reportController.listcontract}" rowKey="#{contract.id}" paginator="true" rows="10" paginatorPosition="bottom"   paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   rowsPerPageTemplate="5,10,15" resizableColumns="true" emptyMessage=""> 
    <p:column> 
     <f:facet name="header"> 
      <h:outputText value="№"/> 
     </f:facet> 
     <h:outputText value="#{contract.id}"/> 
    </p:column> 
    <p:column> 
     <f:facet name="header"> 
      <h:outputText value="Firma Ad?"/> 
     </f:facet> 
     <h:outputText value="#{contract.name}"/> 
    </p:column> 
    <p:columns width="60" value="#{contract.liscolumn}" var="column"> 
     <f:facet name="header"> 
      <h:outputText value=" #{column.header} "/> 
     </f:facet> 
     <h:outputText value=" #{column.property} " /> 
    </p:columns> 
    <f:facet name="header"> 
     <h:outputText value="Sirket Sozlesmeler"/> 
    </f:facet> 

</p:dataTable> 

E questo è il mio commandLink:

<h:commandLink> 
     <p:graphicImage value="../img/xls.png" /> 
     <p:dataExporter type="xls" target=":formreport:contracttblenone" 
      fileName="report" /> 
</h:commandLink> 

Ecco come DataTable appare

enter image description here

Ma xls esportato è diverso ent. Si sta modificando tutti rowas come ultimo ecco lo snaphsot da Excel:

x

+0

Potresti postare il metodo 'postProcessXLS'? – dratewka

+0

@dratewka Non ha nulla. Posso rimuoverlo. Alcuni stili per le celle Excel. – user2634009

+0

Prova ad esportare in 'type =" cvs "' e vedi come appare il file generato in un editor di testo - forse c'è un bug in Primefaces. – dratewka

risposta

0

Bene anche io ho qualche problema nell'utilizzo del functioanality exporttoExcel di primefaces.I hanno cercato molto su StackOverflow e primefacesForums ma prendine per sapere che si tratta di un problema di versione relativo alle primefaces. In questo modo ho realizzato la mia funzione che ora funziona perfettamente e può anche essere modificata in base all'esportazione in altri formati.

<p:commandLink id="back" value="Export to Excel" action="#{agendaBean.exportToExl}" immediate="true" 
        ajax="false" style="color: #086A87;" ></p:commandLink> 

Dopo aver cliccato sul link il metodo exportToExl viene chiamato nel chicco che ha i seguenti contenuti.

public String exportToExl() { 

     ExportToExcel expExlBean = new ExportToExcel(); 

     List<String> columnNames = new ArrayList<String>(); 
     columnNames.add("Agenda ID"); 
     columnNames.add("Matter"); 
     columnNames.add("Item"); 
     columnNames.add("OrderNo"); 
     columnNames.add("AccessPrivilegeString"); 

     columnNames.add("DocumentNameDisplay"); 
     columnNames.add("DocumentFolderPath"); 

     List<String> columnType = new ArrayList<String>(); 
     columnType.add(FrameWorkConstants.DO_NOT_FORMAT); 
     columnType.add(FrameWorkConstants.DO_NOT_FORMAT); 
     columnType.add(FrameWorkConstants.DO_NOT_FORMAT); 
     columnType.add(FrameWorkConstants.DO_NOT_FORMAT); 
     columnType.add(FrameWorkConstants.DO_NOT_FORMAT); 
     columnType.add(FrameWorkConstants.DO_NOT_FORMAT); 
     columnType.add(FrameWorkConstants.DO_NOT_FORMAT); 

     String companyFolderPath = new AgendaIMPL() 
       .getCompanyFolderPath(meetingID); 
     if (agendaList != null) { 
      for (int i = 0; i < agendaList.size(); i++) { 
       agendaList.get(i).setDocumentFolderPath(companyFolderPath); 
      } 
     } 
     List expList = agendaList; 

     if (expList == null || expList.isEmpty()) { 
      ResourceBundle rb = ResourceBundle 
        .getBundle("resources.error1"); 
      if (rb != null) { 
       Utils.addMessage(rb.getString("34").trim(), 
         FacesMessage.SEVERITY_ERROR); 
       return null; 
      } 
     } 

     String strVOName = "com.ultimatix.boardAdmin.vo.AgendaVO"; 

     FacesContext fc = FacesContext.getCurrentInstance(); 
     HttpServletResponse response = (HttpServletResponse) fc 
       .getExternalContext().getResponse(); 

     String flagStart = FrameWorkConstants.SINGLE; 
     expExlBean.exportToExcel(columnNames, columnType, response, 
       expList, strVOName, flagStart); 

     fc.responseComplete(); 
    return null; 
} 

Qui AgendaList è la lista che si sta utilizzando nel DataTable per popolare rows.which si desidera stampare nel foglio Excel.

Fammi sapere in caso di problemi.

+0

Sono un nuovo bie nell'usare le esportazioni di primefaces, puoi dirmi cosa è "FrameworkConstants.DO_NOT_FOMRAT" perché eclipse è fuori dal campo per trovarlo. – 09Q71AO534

+0

penso che tu possa aiutare in questo: http://stackoverflow.com/questions/24889066/issue-with-primefaces-pdataexporter-which-exports-a-datatable-with-selectoneme/24893436#comment38744547_24893436 – 09Q71AO534

Problemi correlati