Hello, I was thrilled to find the excelExport component, as I have a business need to export a datatable to excel. And on the whole, it works great! Thank you!
However, I have found two areas where the behavior is unexpected, perhaps bugs? 1) If the dataTable has sortable=true, then none of the column headers get exported at all. 2) If the column header uses a value-binding, it does not get exported to the Excel worksheet in the first row. If the column header doesn't use a value-binding, then the column header does get exported to the Excel worksheet. ----------------------------------------------------------- Here's more details, as I downloaded the source for ExcelExport and debugged into it, and I believe I have identified the problem area(s). Problem 1) In ExcelExportPhaseListener, the following method is used to convert each "cell" in the datatable into a value for the Excel spreadsheet. private void addColumnValue(HSSFRow rowHeader, UIComponent component, int index) { HSSFCell cell = rowHeader.createCell((short)index); cell.setEncoding(HSSFCell.ENCODING_UTF_16); if(component instanceof ValueHolder) { String stringValue = RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component); cell.setCellValue(stringValue); } } When sortable=false on the datatable, the component passed to addColumnValue is of type HtmlOutputText. However, when sortable=true on the datatable, Tomahawk automatically wraps each column with a sortable header and so the component presented to ExcelExport is of type org.apache.myfaces.custom.sortheader.HtmlCommandSortHeader. This fails the "if(component instanceof ValueHolder)" check and so doesn't even try to get the value from the column. Problem 2) The problem revolves around the following line from the method pasted above (ExcelExportPhaseListener.addColumnValue): String stringValue = RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component); If the column header is defined without using a value binding then the following line in ExcelExportPhaseListener.addColumnValue is evaluated correctly and returns the expected value. E.g., for a column header like this <t:column> <f:facet name="header"><h:outputText value="TEST COLUMN NAME" /></f:facet> <h:outputText value="#{trans.id}" /> </t:column> the value evaluted by String stringValue = RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component); is "TEST COLUMN NAME" and the generated Excel file contains TEST COLUMN NAME in the first row. However, if the column header is defined with a value binding (to a messages file for example) then the following line in ExcelExportPhaseListener.addColumnValue is evaluated incorrectly and returns an empty string. E.g., for a column header like this <t:column> <f:facet name="header"><h:outputText value="#{messages.trans_id}" /></f:facet> <h:outputText value="#{trans.id}" /> </t:column> the value evaluted by String stringValue = RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component); is "" and the generated Excel file contains an empty string in the first row. I hope this helps, and again THANK YOU for the terrific component!!! Regards, Tara Peltier [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/ExcelExport-column-headers-in-Excel-file-tf3302286.html#a9185916 Sent from the My Faces - Dev mailing list archive at Nabble.com.