Skip to content

Contains XSLT transformations used for transforming the XML files into .xlsx or .xlsm files (excel 2007 format)

License

Notifications You must be signed in to change notification settings

foglcz/xsl-excel-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XSLT Excel engine

This project is dedicated to changing the world, together. There's a lot of Microsoft Office documents generated by the ERP / CRM / whatever systems around the world, but most of those exports are done in SpreadsheetML. This project is specifically aimed at any kind of Excel generation, that uses XSLT transformation.

Using SpreadsheetML is bad. More than bad. You generate the xml file, save it as .xsl and when it's opened, the user has to repair the file - forcing himself into three clicks per file. When he tries to save it, Excel tries to save it in XML format and therefore, the user is forced into further clicking.

Let's generate VALID 2007+ formats!

All you need to do is following:

<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:include href="2012.engine.xsl" />

    <xsl:template match="/">
        <xsl:call-template name="generate_excel"></xsl:call-template>
    </xsl:template>
</xsl:stylesheet>

That will produce empty, valid xlsx file structure. You want to replace assets (if you're using free version of Saxon) and mainly - zip it & rename the .zip into .xlsx . No questions asked, excel will open the file and it will be perfectly valid.

Documentation

Documentation is available within Wiki of this project as walkthrough.

tl;dr

Here's your template.xsl file:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:include href="engine/2012.engine.xsl" />
    <xsl:include href="static.xsl" />
    
    <!-- put your data-preprocessing in here -->
    
    <xsl:variable name="images">
        <!-- generate <image> structure in here based on data -->
    </xsl:variable>
    
    <xsl:variable name="contents">
        <!-- put your worksheet generation in here -->
    </xsl:variable>

    <xsl:template match="/">
        <xsl:call-template name="generate_excel">
            <xsl:with-param name="author">ACME Corp.</xsl:with-param>
            <xsl:with-param name="themes"><xsl:copy-of select="$themes" /></xsl:with-param>
            <xsl:with-param name="styles"><xsl:copy-of select="$styles" /></xsl:with-param>
            <xsl:with-param name="images"><xsl:copy-of select="$images" /></xsl:with-param>
            <xsl:with-param name="sheetContents"><xsl:copy-of select="$contents" /></xsl:with-param>
        </xsl:call-template>
    </xsl:template>
</xsl:stylesheet>

Run it as follows:

  1. cd tmp/output
  2. transform -xsl:../template.xslt -s:../data.xml
  3. cd tmp/output && zip * report.zip && mv report.zip report.xslx

Done!

Implementing into current systems

See under the hood chapter of documentation.

License

Licensed under MIT license. Full text of license available in LICENSE.md file.

Authors

Author of the engine is Pavel Ptacek and contributors | @foglcz | in/foglcz | [email protected]

This project has been created with love, in spare time. The main reason was to teach the ERP systems new & valid formats of excel - while in 2007 it was not suitable to generate xlsx formats, it's 2013 now. I think it's time we abandoned the SpredsheetML and started using OpenXML instead.

Feel free to fork, update and pull-request the shit out of this! We need this to grow.

About

Contains XSLT transformations used for transforming the XML files into .xlsx or .xlsm files (excel 2007 format)

Resources

License

Stars

Watchers

Forks

Packages

No packages published