Serializing to Excel in Cocoon is simple. This example shows you how to edit the MinimalSitemapConfiguration to add XLS Serialization. For more information on the XLSSerializer see the Cocoon user guide. For more information on the Gnumeric file format see http://www.jfree.org/jworkbook/download/gnumeric-xml.pdf.

You will need to have an XSLT page that transforms your data into the correct tag language, but assuming you've gotten there, here are the changes you'd make to the sitemap:

<?xml version="1.0" encoding="iso-8859-1"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

    <!-- use the standard components -->
    <map:components>
        <map:generators default="file"/>
        <map:transformers default="xslt"/>
        <map:readers default="resource"/>
<!-- this is changed -->
        <map:serializers default="html"> 
              <map:serializer name="xls"                
                   src="org.apache.cocoon.serialization.HSSFSerializer" 
                   mime-type="application/vnd.ms-excel" locale="us"/>
        </map:serializers>               
<!-- this is changed -->
        <map:selectors default="browser"/>
        <map:matchers default="wildcard"/>
        <map:transformers default="xslt"/>
    </map:components>
      
    <!-- let cocoon know how to process requests -->
    <map:pipelines>
        <map:pipeline>
            <!-- respond to *.html requests with 
                 our docs processed by doc2html.xsl -->
            <map:match pattern="*.html">
                <map:generate src="{1}.xml"/>
                <map:transform src="doc2html.xsl"/>
                <map:serialize type="html"/>
            </map:match>

<!-- added XLS matcher here -->
            <!-- respond to *.xls requests with 
                 our docs processed by doc2xls.xsl -->
            <map:match pattern="*.xls">
                <map:generate src="{1}.xml"/>
                <map:transform src="doc2xls.xsl"/>
                <map:serialize type="xls"/>
            </map:match>             
<!-- end added XLS matcher here -->
            
        </map:pipeline>
    </map:pipelines>
</map:sitemap>

XLSSerializer (last edited 2009-09-20 23:42:57 by localhost)