如何使用C#在ASP.NET中使用xmlmaps将excel文件导出到XML? [英] How to export excel files to XML using xmlmaps in ASP.NET with C#?

查看:62
本文介绍了如何使用C#在ASP.NET中使用xmlmaps将excel文件导出到XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用带有c#的asp.net中的xmlMaps将Excel文件导出到XML?

我能够为具有单个标题和多个子元素的Xml导出。但是我需要将excel文件转换为使用单个标头标签映射多个子标头标签的Xml。



How to export Excel files to XML using xmlMaps in asp.net with c#?
I am able to do the exporting for a Xml with single header and multiple child elements. But i need to convert excel file to Xml mapped with multiple child header tags with a single header tag.

My code to convert excel to XML with single header and multiple child elements in ASP.NET with C#
is as below:
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='D:\\xl2xml.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "Product");
ds = new System.Data.DataSet();
MyCommand.Fill(ds);
MyConnection.Close();
// ds.WriteXml("Product.xml");
ds.WriteXml("D:\\Product.xml");
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
}





我尝试过:



我在ASP中使用单个标题和多个子元素将Excel转换为XML的代码使用C#的.NET如下:



What I have tried:

My code to convert excel to XML with single header and multiple child elements in ASP.NET with C# is as below:

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='D:\\xl2xml.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "Product");
ds = new System.Data.DataSet();
MyCommand.Fill(ds);
MyConnection.Close();
// ds.WriteXml("Product.xml");
ds.WriteXml("D:\\Product.xml");
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
}

推荐答案

,MyConnection);
MyCommand.TableMappings.Add( 产品);
ds = new System.Data.DataSet();
MyCommand.Fill(ds);
MyConnection.Close();
// ds.WriteXml(Product.xml);
ds.WriteXml( D:\\Product.xml);
}
catch (Exception ex)
{
// MessageBox。显示(ex.ToString());
}
", MyConnection); MyCommand.TableMappings.Add("Table", "Product"); ds = new System.Data.DataSet(); MyCommand.Fill(ds); MyConnection.Close(); // ds.WriteXml("Product.xml"); ds.WriteXml("D:\\Product.xml"); } catch (Exception ex) { //MessageBox.Show(ex.ToString()); }





我尝试过:



我的代码将excel转换为带有单头和多头的XML ASP.NET中使用C#的子元素如下:



What I have tried:

My code to convert excel to XML with single header and multiple child elements in ASP.NET with C# is as below:

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='D:\\xl2xml.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1


,MyConnection);
MyCommand.TableMappings.Add( 产品);
ds = new System.Data.DataSet();
MyCommand.Fill(ds);
MyConnection.Close();
// ds.WriteXml(Product.xml);
ds .WriteXml( D:\\Product.xml);
}
catch (例外情况)
{
// MessageBox.Show(ex.ToString());
}
", MyConnection); MyCommand.TableMappings.Add("Table", "Product"); ds = new System.Data.DataSet(); MyCommand.Fill(ds); MyConnection.Close(); // ds.WriteXml("Product.xml"); ds.WriteXml("D:\\Product.xml"); } catch (Exception ex) { //MessageBox.Show(ex.ToString()); }


这篇关于如何使用C#在ASP.NET中使用xmlmaps将excel文件导出到XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆