Question

So I wanted to add some styles in my excel XSLT. The logics are working fine but when I am trying to add style its giving error like

Excel error: Problem came up in the following areas during load: Table

Errors listed in: c:\Users\uname\appdat\microsoft\windows\temporaryInternetFiles\content.MSO\xxxxxxxx.log

My code is:

<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<xsl:stylesheet 
    xmlns:ns="urn:control.services........" 
    xmlns:m="urn:messages........." 
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
     xmlns:html="http://www.w3.org/TR/REC-html40"
        xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <Styles>
                  <Style ss:ID="Default" ss:Name="Normal">
                   <Alignment ss:Vertical="Bottom"/>
                   <Borders/>
                   <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
                   <Interior/>
                   <NumberFormat/>
                   <Protection/>
                  </Style>
                  <Style ss:ID="s62">
                   <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="12" ss:Color="#000000"   ss:Bold="1"/>
                   <Interior ss:Color="#79DCFF"/>
                  </Style>
    </Styles>
    <xsl:output indent="yes"/>
    <xsl:variable name="header" select="distinct-values(/ns:ServiceRequest/m:ItemRequest/ns:ServiceRequest/m:*/m:*/local-name())"/>
    <xsl:variable name="fields" select="distinct-values(/ns:ServiceRequest/m:ItemRequest/ns:ServiceRequest/m:*/m:*/name())"/>
    <xsl:template match="/">
        <ss:Workbook>
            <ss:Worksheet ss:Name="SomeData">
                    <ss:Table>
                    <xsl:for-each select="($header)">
                    <ss:Column ss:Width="160"/> 
                    </xsl:for-each>
                    <ss:Row>
                        <xsl:for-each select="($header)">
                            <ss:Cell ss:ID="s62">
                                <ss:Data ss:Type="String">
                                    <xsl:value-of select="."/>
                                </ss:Data>
                                </ss:Cell>
                        </xsl:for-each>
                    </ss:Row>
                    <xsl:apply-templates select="ns:ServiceRequest/m:ItemRequest/ns:ServiceRequest/m:*"/>
                    </ss:Table>
                </ss:Worksheet>
            </ss:Workbook>
    </xsl:template>

    <xsl:template match="m:*">
        <xsl:variable name="data" select="."/>
        <ss:Row>
            <xsl:for-each select="$fields"> 
                <ss:Cell>
                    <ss:Data ss:Type="String">
                        <xsl:value-of select="$data/*[name()=current()]/text()"/>
                    </ss:Data>
                </ss:Cell>
             </xsl:for-each>
        </ss:Row>
    </xsl:template>
</xsl:stylesheet>

I actually wanted to bold the fonts of header, keep the border and give background color to header.

Was it helpful?

Solution

There's 2 errors in your XSLT:

  1. Your <Styles>are outside of any template, they will not appear in your output document at all. They need to be inside Workbook.

  2. Cell does not have an ss:ID attribute only Style has ss:ID, to reference the Style use ss:StyleID="s62" instead.

Take a look inside c:\Users\uname\appdat\microsoft\windows\temporaryInternetFiles\content.MSO\xxxxxxxx.log (you cannot browse to that location, the folder is hidden, so copy that path into your explorer Adressbar or in a "Run" window) it would have given you some more information like:

XML ERROR in Table
REASON: Illegal Tag
FILE:   C:\temp\Untitled15.xls
GROUP:  Row
TAG:    Cell
ATTRIB: ID
VALUE:  s62

Office throws notoriously bad error messages but that and looking in you result document should usually give you some clue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top