当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net下将Excel转成XML档的实现代码

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下: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();
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网