我正在使用一些旧代码将 Excel 工作表作为数据集返回。但是,当我遍历结果数据集时,似乎并非所有单元格都在那里。正在读取的 Excel 表有一些合并的单元格,我想知道这是否是问题所在。这是代码:
private DataSet Get_Spreadsheet_Data(string strFileName, string strSheetName)
{
DataSet ds = new DataSet();
string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strFileName + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(strConnectionString);
try
{
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + strSheetName + "$]", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
objAdapter1.Fill(ds);
}
catch (Exception Ex)
{
//litOutput.Text = "<span style=\"color:red;\">Exception Occurred pulling data from the spreadsheet.</span><br>Details: " + Ex.Message;
}
finally
{
objConn.Close();
objConn.Dispose();
}
return ds;
}
这段代码有问题吗?任何建议表示赞赏。