Converting an excel file to XML

Hi,

I have an Excel file with 5 sheets. I want to convert that to XML so that it can be embedded as a resource file in my project. The XML file should have five tables (the five sheets) with all the values. Basically,

A database - XLS file name
Tables - XLS sheet names
Rows - Column headers
Columns - values

I made an extensive search in this forum and many others but I m afraid that was not very useful.

Any pointers on this would be appreciated

Thanks !!


Answer this question

Converting an excel file to XML

  • Wira Santos

    Thank you guys. I will check on 2007 Office sometime.

    And boban, So am I gonna create an XSD from the .Net IDE And how do I fill the dataset after reading the Excel file Using the OleDBAdapter But what will my select command be Imagining I dont even know the sheet names. And how will I map the sheets to the tables in the XSD Am really confused, I know it would be something easy but I am out of my mind now :(

    Thanks again !!

  • Thumper1

    Create an xsd schema with five elements (tables), add to each element all child elements (columns). Schema is a Dataset but with big control on xml format when you write to xml file. So you will have a Dataset that will have already a definitions of tables with columns, so all you have to do is to read excel file and fill tables in dataset.
    At the end just execute WriteXml to create xml file.

    You can find on web many articles of how to read excel file from C#.



  • Anton__

    Yes you must use OleDbConnection. Check this site for reading excel file:
    http://www.codeproject.com/csharp/Excel_using_OLEDB.asp
    Filling dataset tables must be done manualy by code. That is for every table you should create row, then fill the row and then add that row to table. And that for all tables.

    Importing data from different sources including excel files can be done also with help of SQL Server. If you use SQL 2000 then you can create that tables in database.  Then create a Data Transformation Package that will connect to file, read and fill tables, and you will then read sql server tables. Executing such packages can be invoked programmatically.



  • SQL New

  • Mark Gilbert

    This is never going to work, you'll never get the schema down to the point where you'll be able to properly encode all of Excel's features into a XML file. Most of all, it is going to last, maybe, a year. Office 2007 has built-in support for encoding its files into XML. It is in Beta now, you can download it to get prepared...


  • Converting an excel file to XML