Reading Excel InterMixed DataType Without Modifying Registry Key

后端 未结 2 1140
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 06:16

I am trying to use C# to read excel file which has intermixed datatype. Below is my connection string

var path = //xls location
var MyConnection = new OleDbC         


        
相关标签:
2条回答
  • 2020-12-10 06:56

    What you can do is to require having header in first row of Excel and set connection string to

    var MyConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + path + "';Extended Properties='Excel 8.0;HDR=No;IMEX=1;'");
    

    The key here is to set HDR=No (NO HEADER), however since you have header now each column will be treated as string (text), and you can do parsing or validation on each cell value. Of course you will need to skip or remove first row, since it contains header information.

    0 讨论(0)
  • 2020-12-10 07:15

    Instead of using OleDb I know use Excel Data Reader. It works greatly! Highly recommended!

    0 讨论(0)
提交回复
热议问题