Welcome to AspAdvice Sign in | Join | Help

How Can You Make The Column Headers Bold?

The article Convert XML To an Excel Spreadsheet Using XSL explains how to transform an XML file into an Excel spreadsheet using XSL. The question is, how can you make the column headers bold? To view the original XSL file visit the article link above.

The answer is to add a Style to the XSL file and then set the ss:Style property for the Cells in the first row equal to the ss:ID property of the Style. See the XSL listed below. The bold font indicates the changes to the original XSL.

<xsl:stylesheet version="1.0"
  xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:user="urn:my-scripts"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" >
 
<xsl:template match="/">
  <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40">
    <xsl:apply-templates/>
  </Workbook>
  <Styles>
    <Style ss:ID="s21">
      <Font x:Family="Swiss" ss:Bold="1"/>
    </Style>
  </Styles>

</xsl:template>


<xsl:template match="/*">
  <Worksheet>
  <xsl:attribute name="ss:Name">
  <xsl:value-of select="local-name(/*/*)"/>
  </xsl:attribute>
    <Table x:FullColumns="1" x:FullRows="1">
      <Row>
        <xsl:for-each select="*[position() = 1]/*">
          <Cell ss:StyleID="s21"><Data ss:Type="String">
          <xsl:value-of select="local-name()"/>
          </Data></Cell>
        </xsl:for-each>
      </Row>
      <xsl:apply-templates/>
    </Table>
  </Worksheet>
</xsl:template>


<xsl:template match="/*/*">
  <Row>
    <xsl:apply-templates/>
  </Row>
</xsl:template>


<xsl:template match="/*/*/*">
  <Cell><Data ss:Type="String">
    <xsl:value-of select="."/>
  </Data></Cell>
</xsl:template>


</xsl:stylesheet>

Sponsor
Published Saturday, August 18, 2007 10:21 PM by andrewmooney
Filed under:

Comments

No Comments

Anonymous comments are disabled