asp.net下将Excel转成XML档的实现代码
程序员文章站
2024-03-08 17:21:40
复制代码 代码如下: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();
}
上一篇: java web个人通讯录系统设计
下一篇: asp.net 产生随机颜色实现代码