You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Tara Peltier <ta...@yahoo.com> on 2007/02/27 17:30:30 UTC

ExcelExport column headers in Excel file

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
tarapeltier@yahoo.com
-- 
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.


Re: [jira] ExcelExport column headers in Excel file

Posted by Tara Peltier <ta...@yahoo.com>.
Thank you for the reply.  I have submitted it to JIRA: 
https://issues.apache.org/jira/browse/TOMAHAWK-911

Sorry for posting to the wrong list.

--Tara


Cagatay Civici wrote:
> 
> Hi Tara,
> 
> Could you please file a jira issue for the points you mentioned and link
> it
> to the nabble link below;
> http://www.nabble.com/ExcelExport-column-headers-in-Excel-file-tf3302286.html#a9185916
> 
> Also next time we'd appreciate if you post these kind of stuff to the
> users
> mail instead.
> 
> Thanks a lot for your help.
> 
> Regards,
> 
> Cagatay
> 

-- 
View this message in context: http://www.nabble.com/ExcelExport-column-headers-in-Excel-file-tf3302286.html#a9193862
Sent from the My Faces - Dev mailing list archive at Nabble.com.


Re: ExcelExport column headers in Excel file

Posted by Cagatay Civici <ca...@gmail.com>.
Hi Tara,

Could you please file a jira issue for the points you mentioned and link it
to the nabble link below;
http://www.nabble.com/ExcelExport-column-headers-in-Excel-file-tf3302286.html#a9185916

Also next time we'd appreciate if you post these kind of stuff to the users
mail instead.

Thanks a lot for your help.

Regards,

Cagatay

On 2/27/07, Tara Peltier <ta...@yahoo.com> wrote:
>
>
> 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
> tarapeltier@yahoo.com
> --
> 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.
>
>