Hi,

I have two minor changes made to the Excelexport to make it work with facelets (or more exacly to work with other suffixes as .jsf) and to avoid hints in new Excel-Versions if you have Numbers in Text-Cells.

This is my first try to contribute, I hope everything is okay. Don't hesitate to correct me.

best regards

Marco

Index: /myfaces-current/tomahawk/sandbox/core/src/main/java/org/apache/myfaces/custom/excelexport/ExcelExportRenderer.java
===================================================================
--- /myfaces-current/tomahawk/sandbox/core/src/main/java/org/apache/myfaces/custom/excelexport/ExcelExportRenderer.java (revision 522807) +++ /myfaces-current/tomahawk/sandbox/core/src/main/java/org/apache/myfaces/custom/excelexport/ExcelExportRenderer.java (working copy)
@@ -67,8 +67,10 @@
private String getJSCall(FacesContext facesContext, String tableId) { String viewId = StringUtils.split( facesContext.getViewRoot().getViewId() , "\\.")[0]; - String contextPath = facesContext.getExternalContext().getRequestContextPath(); - return "window.open('" + contextPath + viewId + ".jsf?excelExportTableId=" + tableId + "');return false;";
+        return "window.open('"
+ + facesContext.getApplication().getViewHandler().getActionURL(
+                        facesContext, viewId) + "?excelExportTableId="
+                + tableId + "');return false;";
    }


Index: /myfaces-current/tomahawk/sandbox/core/src/main/java/org/apache/myfaces/custom/excelexport/ExcelExportPhaseListener.java
===================================================================
--- /myfaces-current/tomahawk/sandbox/core/src/main/java/org/apache/myfaces/custom/excelexport/ExcelExportPhaseListener.java (revision 522807) +++ /myfaces-current/tomahawk/sandbox/core/src/main/java/org/apache/myfaces/custom/excelexport/ExcelExportPhaseListener.java (working copy)
@@ -117,6 +117,18 @@
        cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        if(component instanceof ValueHolder) {
String stringValue = RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component);
+            // try some parsings
+            try {
+                cell.setCellValue(Double.parseDouble(stringValue));
+                return;
+            } catch (NumberFormatException nfe) {
+            }
+            try {
+                cell.setCellNum(Short.parseShort(stringValue));
+                return;
+            } catch (NumberFormatException nfe) {
+            }
+            // default to string value
            cell.setCellValue(stringValue);
        }
    }



Reply via email to