Click here to Skip to main content
6,291,124 members and growing! (15,977 online)
Email Password   helpLost your password?
Languages » XML » General     Intermediate

XSLT to transform Excel XML spreadsheet to CSV or HTML table

By jemodurn

XSLT to transform Excel XML spreadsheet to CSV or HTML table.
XML.NET 1.0, .NET 1.1, Win2K, WinXP, Win2003, PocketPC 2002, ASP.NET, Visual Studio, Dev
Posted:6 Jul 2003
Updated:15 Jul 2003
Views:110,901
Bookmarked:27 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
15 votes for this article.
Popularity: 3.45 Rating: 2.94 out of 5
5 votes, 33.3%
1

2
1 vote, 6.7%
3
1 vote, 6.7%
4
8 votes, 53.3%
5

Introduction

One day, I needed to create a conversion of MS Excel saved XML spreadsheet to CSV file. I believe the MS Office Web Component (OWC) ver. 10 spreadsheet component can also expose XML data.

Practical use

Here is an example web page showing how to use OWC spreadsheet with it.

The Script

<script language="JavaScript">

    function action()
    {
        //get the xmldata

        var strXML = Spreadsheet1.XMLData
    
        // create xml object

        var xml = new ActiveXObject("Microsoft.XMLDOM")
        xml.async = false
        xml.load(strXML)

        // Load XSL

        var xsl = new ActiveXObject("Microsoft.XMLDOM")
        xsl.async = false
        xsl.load("book.xsl")

        // Transform

        form1.csvValue.value = xml.transformNode(xsl)
    
        // csv submit to backend 

        // alert(form1.xmlValue.value) 

        form1.submit()

    }
</script>

The Body

<html><BODY>
  <h3> Payroll Input Form </h3>
  <P>
   <OBJECT id="Spreadsheet1" style="WIDTH: 100%; HEIGHT: 80%" 
           classid="clsid:0002E551-0000-0000-C000-000000000046" >
    <PARAM NAME="DataType" VALUE="XMLDATA">
    <PARAM NAME="xmlURL" VALUE="book_no_xsl.xml">
   </OBJECT>
  </P>
  <form id="form1" method="post" runat="server">
   <P>
    <input type="button" onclick="action()">
   </P>
   <input id="csvValue" type="hidden" name="csvValue">
  </form>
</BODY></html>

How to Use it

Simply unzip and look at book.xml.

ASP.NET

Here is a piece of code I use to transform Excel XML to CSV.

'Create a new XslTransform object.

Dim xslt As New XslTransform
'Load the stylesheet.

xslt.Load(Server.MapPath(".") & "excel2csv.xsl")

Dim doc As New XmlDocument
'xmldata is string, use doc.Load(fileName) for file.

doc.LoadXml(xmlData)

'Create an XmlTextWriter which outputs to a file.

Dim fileName As String
fileName = Server.MapPath(".") & "book.csv"

Dim writer As XmlWriter = New XmlTextWriter(fileName, Nothing)
'Transform the data and send the output to the console.


xslt.Transform(doc, Nothing, writer, Nothing)
writer.Close()

Reference

-- May the code be with you.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

jemodurn


Member
Frank is a Sr. UI Software Engineer specialized in MFC and Business Applications.

He has worked in BROADBASE, KANA, Macromeda and Siebel Systems.

Occupation: Web Developer
Location: United States United States

Other popular XML articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 11 of 11 (Total in Forum: 11) (Refresh)FirstPrevNext
GeneralTransformation Not Always Correct PinmemberCyberKnet7:45 28 Mar '05  
Generalxml to csv PinsussPablo Nuñez6:51 15 Dec '03  
GeneralNot a lot of credibility PinmemberDirk Vandenheuvel23:55 16 Jul '03  
GeneralRe: Not a lot of credibility PinmemberJohn M. Drescher4:38 17 Jul '03  
GeneralRe: Not a lot of credibility PinmemberfolderMonkey7:13 17 Jul '03  
GeneralRe: Not a lot of credibility Pinmemberjemodurn7:30 17 Jul '03  
GeneralRe: Not a lot of credibility PinmemberJohn M. Drescher11:54 17 Jul '03  
GeneralRe: Not a lot of credibility Pinmemberzakriah9:39 12 Mar '07  
GeneralCan not download the source zip file PinmemberChemutury9:26 16 Jul '03  
GeneralRe: Can not download the source zip file Pinmemberjemodurn16:33 16 Jul '03  
GeneralCannot download PinmemberJesterka0:32 10 Jul '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Jul 2003
Editor: Smitha Vijayan
Copyright 2003 by jemodurn
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project