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 7783857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:57:53+00:00 2026-06-01T19:57:53+00:00

My overall problem is that I have a large Excel file(Column A-S, 85000 rows)

  • 0

My overall problem is that I have a large Excel file(Column A-S, 85000 rows) that I want to convert to XML. The data in the cells is all text.

The process I’m using now is to manually save the excel file as csv, then parse that in my own c# program to turn it into XML. If you have better recommendations, please recommend. I’ve searched SO and the only fast methods I found for converting straight to XML require my data to be all numeric.
(Tried reading cell by cell, would have taken 3 days to process)

So, unless you can recommend a different way for me to approach the problem, I want to be able to programmatically remove all commas, <, >, ‘, and ” from the excel sheet.

  • 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-01T19:57:54+00:00Added an answer on June 1, 2026 at 7:57 pm

    I would use a combination of Microsoft.Office.Interop.Excel and XmlSerializer to get the job done.

    This is in light of the fact that a) you’re using a console appilcation, and b) the interop assemblies are easy to integrate to the solution (just References->Add).

    I’m assuming that you have a copy of Excel installed in the machine runnning the process (you mentioned you manually open the workbook currently, hence the assumption).

    The code would look something like this:

    The serializable layer:

    public class TestClass
    {
        public List<TestLineItem> LineItems { get; set; }
    
        public TestClass()
        {
            LineItems = new List<TestLineItem>();
        }
    }
    
    public class TestLineItem
    {
        private string SanitizeText(string input)
        {
            return input.Replace(",", "")
                .Replace(".", "")
                .Replace("<", "")
                .Replace(">", "")
                .Replace("'", "")
                .Replace("\"", "");
        }
    
        private string m_field1;
        private string m_field2;
    
        public string Field1 
        {
            get { return m_field1; }
            set { m_field1 = SanitizeText(value); }
        }
    
        public string Field2 
        {
            get { return m_field2; }
            set { m_field2 = SanitizeText(value); }
        }
    
        public decimal Field3 { get; set; }
    
        public TestLineItem() { }
    
        public TestLineItem(object field1, object field2, object field3)
        {
            m_field1 = (field1 ?? "").ToString();
            m_field2 = (field2 ?? "").ToString();
    
            if (field3 == null || field3.ToString() == "")
                Field3 = 0m;
            else
                Field3 = Convert.ToDecimal(field3.ToString());
        }
    }
    

    Then open the worksheet and load into a 2D array:

    // using OExcel = Microsoft.Office.Interop.Excel;
    var app = new OEXcel.Application();
    var wbPath = Path.Combine(
        Environment.GetFolderPath(
            Environment.SpecialFolder.MyDocuments), "Book1.xls");
    
    var wb = app.Workbooks.Open(wbPath);
    var ws = (OEXcel.Worksheet)wb.ActiveSheet;
    
    // there are better ways to do this... 
    // this one's just off the top of my head
    var rngTopLine = ws.get_Range("A1", "C1");
    var rngEndLine = rngTopLine.get_End(OEXcel.XlDirection.xlDown);
    var rngData = ws.get_Range(rngTopLine, rngEndLine);
    var arrayData = (object[,])rngData.Value2;
    
    var tc = new TestClass();
    
    // since you're enumerating an array, the operation will run much faster
    // than reading the worksheet line by line.
    for (int i = arrayData.GetLowerBound(0); i <= arrayData.GetUpperBound(0); i++)
    {
        tc.LineItems.Add(
            new TestLineItem(arrayData[i, 1], arrayData[i, 2], arrayData[i, 3]));
    }
    
    var xs = new XmlSerializer(typeof(TestClass));
    var fs = File.Create(Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
        "Book1.xml"));
    xs.Serialize(fs, tc);
    
    wb.Close();
    app.Quit();
    

    The generated XML output will look something like this:

    <TestClass>
      <LineItems>
        <TestLineItem>
          <Field1>test1</Field1>
          <Field2>some&amp;lt;encoded&amp;gt; stuff here</Field2>
          <Field3>123456.789</Field3>
        </TestLineItem>
        <TestLineItem>
          <Field1>test2</Field1>
          <Field2>testing some commas, and periods.</Field2>
          <Field3>23456789.12</Field3>
        </TestLineItem>
        <TestLineItem>
          <Field1>test3</Field1>
          <Field2>text in &amp;quot;quotes&amp;quot; and &amp;#39;single quotes&amp;#39;</Field2>
          <Field3>0</Field3>
        </TestLineItem>
      </LineItems>
    </TestClass>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a problem that I can not figure out. I am writing
Basically, I have a large number of C structs to keep track of, that
I have a rather unique problem that I'm having trouble solving. I have a
So I have 3 sections with 3 rows in each section (9 rows overall),
Imagine that you have a large set of #m objects with properties A and
I'm working with a CSV file in python, which will have ~100,000 rows when
I have a large Excel sheet auto generated from C#, which outputs all columns
My overall goal is isolate tags that contain a certain word in the text
Are there overall rules/guidelines for what makes a method thread-safe? I understand that there
I'm going to assume that the overall structure of my code as it currently

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.