Announcement

Collapse
No announcement yet.

xhtml nach excel spreadsheetml

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • xhtml nach excel spreadsheetml

    hallo,

    ich versuche schon seit geraumer Zeit eine (generierte) xhtml per xslt auf dem server in eine excel spreadsheetml umzuwandeln.

    Zu jedem div in der xhtml Source soll ein Worksheet erstellt werden.

    Die xhtml Source sieht folgendermaßen aus:
    Code:
    <?xml version="1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
    <head>
    <title>Aufbau einer Tabelle</title>
    </head>
    <body>
    <div title="Sheet1">
    <table border="1">
      <tr>
        <td>header1</td>
        <td>header2</td>
        <td>header1&uuml;withUmlaut</td>
      </tr>
      <tr>
        <td>datacell with Umlaut&ouml;</td>
        <td>22</td>
        <td>33</td>
      </tr>
      <tr>
        <td>datacell row2</td>
        <td>44</td>
        <td>55</td>
      </tr>
    </table>
      </div>
    <div title="Sheet2">
        <table border="0">
          <tr>
            <td>header4</td>
            <td>header5</td>
          </tr>
          <tr>
            <td>datacell</td>
            <td>55</td>
          </tr>
        </table>
    </div>
    </body>
    </html>
    Meine klägliche Versuchs-XSLT sieht folgendermaßen aus...(und tut schon in den Anfängen nicht was sie soll):

    Code:
    <xsl:stylesheet version="1.0"
      xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns="urn:schemas-microsoft-com:office:spreadsheet"
      exclude-result-prefixes="xhtml xsl xs xml">
    
      <xsl:output method="xml" version="1.0" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" indent="no"/>
    
            <xsl:template match="/">
    
              <xsl:processing-instruction name="mso-application">
                  <xsl:text>progid="Excel.Sheet"</xsl:text>
              </xsl:processing-instruction>
    
                  <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
                     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">
                    <WindowHeight>9120</WindowHeight>
                    <WindowWidth>10005</WindowWidth>
                    <WindowTopX>120</WindowTopX>
                    <WindowTopY>135</WindowTopY>
    
                    <xsl:apply-templates select="@*|node()"/>
    
                  </Workbook>
    
            </xsl:template>
    
              <xsl:template match="xhtml:div">
                <xsl:copy>
                  <xsl:apply-templates select="@*|node()"/>
                </xsl:copy>
              </xsl:template>
    
               <xsl:template match="@xhtml:title">
                   <xsl:attribute name="Name"><xsl:value-of select="."/></xsl:attribute>
              </xsl:template>
    
              <xsl:template match="xhtml:div">
                <Worksheet>
                   <xsl:apply-templates select="@*|node()"/>
                </Worksheet>
              </xsl:template>
    
    
        </xsl:stylesheet>
    Kann mir jemand bitte bei der Erstellung der XSLT helfen?
    Als Ergebniss soll eine gültige Excel SpreadsheetML rauskommen, die im wesentlichen jede in divs eingeschlossene Html-Tabelle in entsprechend benannte Sheets abbildet.

    Für jegliche Tips und Beispiele bin ich sehr dankbar.

    Bye

  • #2
    Studiere mal dieses Beispiel und passe es auf die XHTML-Eingabestruktur an.

    Comment


    • #3
      Das Beispiel ist gut, jedoch ist das Ziel des Autors eine einfachere XML Syntax für SpreadsheetML bereitzustellen.
      Ich bin verwundert, dass es im Netz nahezu keine Beispiele gibt um per XSLT aus HTML-Tabellen Excel-Tabellen zu erzeugen.
      Meine bisher besten Quellen sind:

      http://www.xmlplease.com/xhtmlxhtml

      http://www.brainbell.com/tutorials/m...eadsheetML.htm

      Interessant finde ich, dass man eine normale Html-Tabelle in einer Datei mit einer xls Endung speichern und diese dann mit Excel aufmachen kann. Leider kann man auf diese Weise nicht mehrere Tabellen auf mehrerer Sheets abbilden.

      Leider komme ich weiterhin nicht besonders gut vorran...

      Comment


      • #4
        Originally posted by pddd View Post
        Interessant finde ich, dass man eine normale Html-Tabelle in einer Datei mit einer xls Endung speichern und diese dann mit Excel aufmachen kann.
        Funktioniert nur bis Excel 2003 "geschmeidig" Ab Excel 2007 kommt eine Warnmeldung das die Extension (XLS) nicht mit dem Dateiinhalt (HTML) übereinstimmt und ob man das trotzdem öffnen will. Vorsichtige Zeitgenossen werden solche "komischen" XLS-Dateien nicht mehr öffnen.

        Comment


        • #5
          Dieses XSLT-Stylesheet erzeugt aus Deinen XHTML-Testdaten eine XML-Ausgabe, welche sich wiederum zumindest in Excel 2003 laden lässt und dort eine Arbeitsmappe mit zwei Tabellen ergibt:

          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
            xmlns:x="urn:schemas-microsoft-com:office:excel"
            xmlns="urn:schemas-microsoft-com:office:spreadsheet"
            exclude-result-prefixes="#default xhtml ss x">
          
            <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
          
            <xsl:template match="/">
              <xsl:processing-instruction name="mso-application">
                <xsl:text>progid="Excel.Sheet"</xsl:text>
              </xsl:processing-instruction>
          
              <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">
          
                <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
                  <Author/>
                  <LastAuthor/>
                  <Created/>
                  <LastSaved/>
                  <Company/>
                  <Version/>
                </DocumentProperties>
          
                <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
                  <WindowHeight>12555</WindowHeight>
                  <WindowWidth>15315</WindowWidth>
                  <WindowTopX>360</WindowTopX>
                  <WindowTopY>135</WindowTopY>
                  <ProtectStructure>False</ProtectStructure>
                  <ProtectWindows>False</ProtectWindows>
                </ExcelWorkbook>
          
                <Styles>
                  <Style ss:ID="Default" ss:Name="Normal">
                    <Alignment ss:Vertical="Bottom"/>
                    <Borders/>
                    <Font/>
                    <Interior/>
                    <NumberFormat/>
                    <Protection/>
                  </Style>
                </Styles>
          
                <xsl:apply-templates select="//xhtml:div"/>
          
              </Workbook>
          
            </xsl:template>
          
            <xsl:template match="xhtml:div">
              <Worksheet ss:Name="{@title}">
                <xsl:apply-templates select="xhtml:table"/>
              </Worksheet>
          
              <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
                <PageSetup>
                  <Header x:Margin="0.5"/>
                  <Footer x:Margin="0.5"/>
                  <PageMargins x:Bottom="1" x:Left="1" x:Right="1" x:Top="1"/>
                </PageSetup>
                <Selected/>
                <ProtectObjects>False</ProtectObjects>
                <ProtectScenarios>False</ProtectScenarios>
              </WorksheetOptions>    
            </xsl:template>
          
            <xsl:template match="xhtml:table">
              <Table ss:ExpandedColumnCount="{count(xhtml:tr[1]/xhtml:td)}"
                ss:ExpandedRowCount="{count(xhtml:tr)}" ss:DefaultColumnWidth="60"
                x:FullColumns="1" x:FullRows="1">
          
                <Row>
                  <xsl:for-each select="xhtml:tr[1]/xhtml:td">
                    <Cell>
                      <Data>
                        <xsl:attribute name="ss:Type">
                          <xsl:choose><xsl:when test="number(.)">
                            <xsl:text>Number</xsl:text></xsl:when>
                            <xsl:otherwise><xsl:text>String</xsl:text></xsl:otherwise>
                          </xsl:choose>
                        </xsl:attribute>
                        <xsl:value-of select="."/>
                      </Data>
                    </Cell>
                  </xsl:for-each>
                </Row>
          
                <xsl:for-each select="xhtml:tr[position()>1]">
                  <Row>
                    <xsl:for-each select="xhtml:td">
                      <Cell>
                        <Data>
                          <xsl:attribute name="ss:Type">
                            <xsl:choose><xsl:when test="number(.)">
                              <xsl:text>Number</xsl:text></xsl:when>
                              <xsl:otherwise><xsl:text>String</xsl:text></xsl:otherwise>
                            </xsl:choose>
                          </xsl:attribute>
                          <xsl:value-of select="."/>
                        </Data>
                      </Cell>
                    </xsl:for-each>
                  </Row>
                </xsl:for-each>
          
              </Table>
            </xsl:template>
          
          </xsl:stylesheet>
          Hinweis: Das leicht angepasste Basis-XML stammt von der testweisen Excel-Ausgabe einer "XML-Kalkulationstabelle". An den Stellen mit xhtml-Prefix wird auf die relevanten XHTML-Inhalte zugegriffen.
          Zuletzt editiert von Thomas Meinike; 22.03.2009, 18:55.

          Comment


          • #6
            Ein riesiger und herzlicher Dank an Thomas Meinike, das ist genau das was ich suche und brauche.
            Die erzeugte Excel-Datei läßt sich übrigens auch prima in Excel 2007 öffnen.
            Einfach gut.

            Comment

            Working...
            X