Click here to Skip to main content
15,888,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to convert an excel file into xml file, i want column names in excel file to be used as tags in xml file for e.g. <Building name>XYZ<Building name\> and so on. i am using C# asp.net web application

What I have tried:

public DataTable ExcelToDatatable(string filePath)
{
string excelfile = "select * from [Sheet1$]";
DataSet ds = new DataSet();
string constring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1;\"";
OleDbConnection con = new OleDbConnection(constring + "");
OleDbDataAdapter da = new OleDbDataAdapter(excelfile, con);
da.Fill(ds);
///dataset to xml
ds.WriteXml("F:\\BuildingDetails.xml");



///Binding data to gridview
DataTable dt = ds.Tables[0];
GridView1.DataSource = dt;
GridView1.DataBind();
return dt;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900