Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:46:38+00:00 2026-06-13T06:46:38+00:00

I wonder if there is an easy way to read Excel 2010 XML? This

  • 0

I wonder if there is an easy way to read Excel 2010 XML?
This XML has a different structure than I used to read.

Especially ss:index attribute (ss:Index**=”7″) makes things a bit more complicated

EDIT:
To explain better:

  • I have file with XML extension which can be easily opened in Excel
  • I’m looking a way to read this sheet programically (eg copy to DataTable)
  • Noticed this is not common XML I used to work
  • XML defines fields on the begining, than use ROW, CELL and DATA tags
  • What surprised me is when there are eg 3 fields (cells) but 2nd field doesn’t have value this field is ‘skipped’ in XML, but 3rd field has some additional ‘index’ attribute eg: ss:Index**=”3″ (which indicates that even it is on 2nd position right index should be “3”

fragment of example XML

      <Row ss:AutoFitHeight="0">
        <Cell><Data ss:Type="String">Johny</Data></Cell>
        <Cell ss:Index="3"><Data ss:Type="String">NY</Data></Cell>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:46:40+00:00Added an answer on June 13, 2026 at 6:46 am

    OK I’ve finally found solution from here: http://www.codeproject.com/Articles/32370/Import-Excel-File-to-DataSet#xx

    Below sample code little adopted to my needs.

    public static class XMLtoDataTable {
      private static ColumnType getDefaultType() {
        return new ColumnType(typeof(String));
    }
    
            struct ColumnType {
                public Type type;
                private string name;
                public ColumnType(Type type) { this.type = type; this.name = type.ToString().ToLower(); }
                public object ParseString(string input) {
                    if (String.IsNullOrEmpty(input))
                        return DBNull.Value;
                    switch (type.ToString()) {
                        case "system.datetime":
                            return DateTime.Parse(input);
                        case "system.decimal":
                            return decimal.Parse(input);
                        case "system.boolean":
                            return bool.Parse(input);
                        default:
                            return input;
                    }
                }
            }
    
    
        private static ColumnType getType(XmlNode data) {
        string type = null;
        if (data.Attributes["ss:Type"] == null || data.Attributes["ss:Type"].Value == null)
            type = "";
        else
            type = data.Attributes["ss:Type"].Value;
    
        switch (type) {
            case "DateTime":
                return new ColumnType(typeof(DateTime));
            case "Boolean":
                return new ColumnType(typeof(Boolean));
            case "Number":
                return new ColumnType(typeof(Decimal));
            case "":
                decimal test2;
                if (data == null || String.IsNullOrEmpty(data.InnerText) || decimal.TryParse(data.InnerText, out test2)) {
                    return new ColumnType(typeof(Decimal));
                } else {
                    return new ColumnType(typeof(String));
                }
            default://"String"
                return new ColumnType(typeof(String));
        }
    }
    
        public static DataSet ImportExcelXML (string fileName, bool hasHeaders, bool autoDetectColumnType) {
            StreamReader sr = new StreamReader( fileName);
            Stream st = (Stream) sr.BaseStream;
            return ImportExcelXML( st, hasHeaders, autoDetectColumnType);
        }
    
        private static DataSet ImportExcelXML(Stream inputFileStream, bool hasHeaders, bool autoDetectColumnType) {
            XmlDocument doc = new XmlDocument();
            doc.Load(new XmlTextReader(inputFileStream));
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
    
            nsmgr.AddNamespace("o", "urn:schemas-microsoft-com:office:office");
            nsmgr.AddNamespace("x", "urn:schemas-microsoft-com:office:excel");
            nsmgr.AddNamespace("ss", "urn:schemas-microsoft-com:office:spreadsheet");
    
            DataSet ds = new DataSet();
    
            foreach (XmlNode node in 
              doc.DocumentElement.SelectNodes("//ss:Worksheet", nsmgr)) {
                DataTable dt = new DataTable(node.Attributes["ss:Name"].Value);
                ds.Tables.Add(dt);
                XmlNodeList rows = node.SelectNodes("ss:Table/ss:Row", nsmgr);
                if (rows.Count > 0) {
    
                    //*************************
                    //Add Columns To Table from header row
                    //*************************
                    List<ColumnType> columns = new List<ColumnType>();
                    int startIndex = 0;
                    if (hasHeaders) {
                        foreach (XmlNode data in rows[0].SelectNodes("ss:Cell/ss:Data", nsmgr)) {
                            columns.Add(new ColumnType(typeof(string)));//default to text
                            dt.Columns.Add(data.InnerText, typeof(string));
                        }
                        startIndex++;
                    }
                    //*************************
                    //Update Data-Types of columns if Auto-Detecting
                    //*************************
                    if (autoDetectColumnType && rows.Count > 0) {
                        XmlNodeList cells = rows[startIndex].SelectNodes("ss:Cell", nsmgr);
                        int actualCellIndex = 0;
                        for (int cellIndex = 0; cellIndex < cells.Count; cellIndex++) {
                            XmlNode cell = cells[cellIndex];
                            if (cell.Attributes["ss:Index"] != null)
                                actualCellIndex = 
                                  int.Parse(cell.Attributes["ss:Index"].Value) - 1;
    
                            ColumnType autoDetectType = 
                              getType(cell.SelectSingleNode("ss:Data", nsmgr));
    
                            if (actualCellIndex >= dt.Columns.Count) {
                                dt.Columns.Add("Column" + 
                                  actualCellIndex.ToString(), autoDetectType.type);
                                columns.Add(autoDetectType);
                            } else {
                                dt.Columns[actualCellIndex].DataType = autoDetectType.type;
                                columns[actualCellIndex] = autoDetectType;
                            }
    
                            actualCellIndex++;
                        }
                    }
                    //*************************
                    //Load Data
                    //*************************
                    for (int i = startIndex; i < rows.Count; i++) {
                        DataRow row = dt.NewRow();
                        XmlNodeList cells = rows[i].SelectNodes("ss:Cell", nsmgr);
                        int actualCellIndex = 0;
                        for (int cellIndex = 0; cellIndex < cells.Count; cellIndex++) {
                            XmlNode cell = cells[cellIndex];
                            if (cell.Attributes["ss:Index"] != null)
                                actualCellIndex = int.Parse(cell.Attributes["ss:Index"].Value) - 1;
    
                            XmlNode data = cell.SelectSingleNode("ss:Data", nsmgr);
    
                            if (actualCellIndex >= dt.Columns.Count) {
                                for (int ii = dt.Columns.Count; ii < actualCellIndex; ii++) {
                                    dt.Columns.Add("Column" + actualCellIndex.ToString(), typeof(string));columns.Add(getDefaultType());
                                } // ii
                                ColumnType autoDetectType = 
                                   getType(cell.SelectSingleNode("ss:Data", nsmgr));
                                dt.Columns.Add("Column" + actualCellIndex.ToString(), 
                                               typeof(string));
                                columns.Add(autoDetectType);
                            }
                            if (data != null)
                                row[actualCellIndex] = data.InnerText;
    
                            actualCellIndex++;
                        }
    
                        dt.Rows.Add(row);
                    }
                }
            }
            return ds;
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if there is a reasonable easy way to allow for this code
This particular topic has always made me wonder is there a more efficient way
I have 2600 xml files with data, I wonder if there's a easy way
I wonder if there is an easy way to check if two strings match
I am wonder if there is an easy way to finish a test after
i wonder if there is a easy way to convert my float array image
I wonder if there is an easy way to see the SQL generated by
I wonder if there is an easy way to dump or load the content
I wonder if there's easy way to let apache2 support URL rewrite to special
I wonder if there's an easy way of switching between Tab pages of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.