John John John

Why is my xml file having these after convert from excel?

478 Views Asked by At

My xml file has these "x0020" after the first word and last word of a column in my excel file, any clue?

<root>
    <first_x0020_Name>John<first_x0020_Name>
    <last_x0020_Name>Doe<first_x0020_Name>
    <Age_x0020_Range>28<first_x0020_Name>
</root>

Here's my code to convert from excel to xml:

string PATH = @"C:file.xlsx";
        string connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + PATH + ";Extended Properties=Excel 12.0";
        OleDbConnection objConn = new OleDbConnection(connection);
        OleDbCommand objCmd = new OleDbCommand(string.Format(@"Select * From [Sheet1$]"), objConn);

        OleDbDataAdapter objDatAdap = new OleDbDataAdapter();
        objDatAdap.SelectCommand = objCmd;
        DataSet ds = new DataSet();
        objDatAdap.Fill(ds);
        string result;
        using (StringWriter sw = new StringWriter())
        {
            ds.DataSetName = "samples";
            DataTable ok = ds.Tables[0];
            ok.TableName = "sample";
            ds.WriteXml(sw);
            ds.WriteXml("C:/File.xml");
        }
0

There are 0 best solutions below