Accessing Excel Spreadsheet with C# occasionally returns blank value for some cells

后端 未结 10 2182
無奈伤痛
無奈伤痛 2020-12-11 02:43

I need to access an excel spreadsheet and insert the data from the spreadsheet into a SQL Database. However the Primary Keys are mixed, most are numeric and some are alpha-n

10条回答
  •  没有蜡笔的小新
    2020-12-11 02:50

    This isn't completely right! Apparently, Jet/ACE ALWAYS assumes a string type if the first 8 rows are blank, regardless of IMEX=1. Even when I made the rows read to 0 in the registry, I still had the same problem. This was the only sure fire way to get it to work:

    try
    {
        Console.Write(wsReader.GetDouble(j).ToString());
    }
    catch   //Lame unfixable bug
    {
        Console.Write(wsReader.GetString(j));
    }
    

提交回复
热议问题