actually i am trying to convert excel file data to xml file. my requirement is i need to get required cell data from excel and i can edit the xml tags according to my requirement. is it possible?????
and is it write way to use OleDb for this????
this is my code:
private void button1_Click(object sender, EventArgs e)
{
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet ds;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\\Desktop\\xl2xml\\test_2003.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
//MyCommand.TableMappings.Add("Table", "Product");
MyCommand.TableMappings.Add("Table", "Myrequireddata from required cell");
ds = new System.Data.DataSet();
MyCommand.Fill(ds);
MyConnection.Close();
ds.WriteXml(@"C:\Desktop\xl2xml\Product.xml");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Yes of course. I have done the same thing before. Your concept is correct. Here I used Microsoft DAO 3.6 object library to read excel file.
However you can read the excel file into a Dataset and then you can go through the Dataset object to find required data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.