有时候经常用到,做个记录
判断上传文件为Excel:
if ((this.FileUpload1.PostedFile.ContentType == "application/vnd.ms-excel") || (this.FileUpload1.PostedFile.ContentType == "application/ms-excel") || (this.FileUpload1.PostedFile.ContentType== "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {}
03版Excel链接字符串:
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(savePath) + ";Extended Properties='Excel 8.0;HDR=No;IMEX=1'";
07以上版Excel链接字符串:
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(savePath) + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';";
本文介绍了如何在代码中判断上传文件是否为Excel,并提供了针对不同版本Excel(03版和07版以上)的链接字符串配置方法,以便在应用程序中读取Excel数据。
972

被折叠的 条评论
为什么被折叠?



