Reading Excel-file using Oledb - treating content of excel file as Text only

两盒软妹~` 提交于 2019-12-03 20:54:20

Could you try oledb provider connection string as follow.

HDR=NO means oledb will read all rows as data [NO HEADER]. So as your header columns are all text, it will treat all row data in all columns as text. After filling data into DataSet, you have to remove first row as it is not data.

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties=\"Excel 12.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedTypes=Text\"";

One fix we found, is to ensure that the first row contains a header. i.e. make sure that your column names are in the first row. If that's possible.

Then in your code, you have to programmatically ignore the first row, while at the same time scarfing your column names from it, if need be.

Use this in your connection string.

     IMEX=1;HDR=NO;

I'm not sure of this

     TypeGuessRows=0;ImportMixedTypes=Text

I had similar issue.. i resolved it by splitting the connectionstring as mentioned in following string. Please note that after extended properties.. there is (char)34 to surround IMEX=1 addition to the string. without surrounding with (char)34, it will give error "cant find ISAM". Hope this resolves your issue for ACE provider also

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                        "Data Source=" + Server.MapPath("UploadedExcel/" + FileName + ".xls") +
                        ";Extended Properties=" +
                        (char)34 + "Excel 8.0;IMEX=1;" + (char)34;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!