欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net下将Excel转成XML档的实现代码

程序员文章站 2024-03-09 13:18:17
复制代码 代码如下:if (this.fileupload1.postedfile != null) { string filename = this.fileupload...
复制代码 代码如下:

if (this.fileupload1.postedfile != null)
{
string filename = this.fileupload1.filename.tostring();
string path = @server.mappath("../file/") + filename;
this.fileupload1.postedfile.saveas(path);
//读取用户上传的excle文件
string conn="provider = microsoft.jet.oledb.4.0 ;data source ='"+path+"';extended properties=excel 8.0";
oledbconnection olecon = new oledbconnection(conn);
olecon.open();
//注意表名,打开excel文件后,最底部分页的excle名字,
//默认是$sheet1,$sheet2,$sheet3
string sql = "select * from [$sheet1]";
oledbdataadapter oleda = new oledbdataadapter(sql,conn);
oleda.fill(ds);
olecon.close();

this.gridview1.datasource = ds;
this.gridview1.databind();

string file_name = "20091126002.xml";
string xml_path = @server.mappath("../reports/xml/") + file_name;

ds.writexml(xml_path);
ds.dispose();
}