2013-08-06 22 views
5

我有一個<p:dataTable>PrimeFaces DataExporter以XLS多列工作不正常

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

這是我commandLink:

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

下面是數據表的外觀

enter image description here

但是導出的xls是不同的ENT。它是從Excel修改所有rowas這裏最後一個是snaphsot:

x

+0

你可以發佈'postProcessXLS'方法嗎? – dratewka

+0

@dratewka它沒有任何東西。我可以刪除它。一些excel單元格的樣式。 – user2634009

+0

嘗試導出到'type =「cvs」'並查看生成的文件在文本編輯器中的樣子 - 可能在Primefaces中存在一個錯誤。 – dratewka

回答

0

嗯,我也有使用primefaces.I的exporttoExcel functioanality一些問題已經搜查計算器和primefacesForums只是得到了很多知道這是一個primefaces相關的版本issue.By方式我已經做了我自己的功能,現在是完美的工作,也可以修改爲導出到其他格式。

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

點擊鏈接後,在具有以下內容的bean中調用exportToExl方法。

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

這裏AgendaList是你在數據表中使用的列表來填充rows.which你想打印在Excel工作表。

請讓我知道你感到更加關心的問題。

+0

我是使用primefaces導出的新bie,你能說我什麼是「FrameworkConstants.DO_NOT_FOMRAT」,因爲我的eclipse超出了查找範圍。 – 09Q71AO534

+0

我認爲你可以在這幫助:http://stackoverflow.com/questions/24889066/issue-with-primefaces-pdataexporter-which-exports-a-datatable-with-selectoneme/24893436#comment38744547_24893436 – 09Q71AO534