我使用OleDb导入具有2000列的Excel文件。因此,通过使用这段代码,我的DataTable中只能有255列。我想要一些其他方式,或者如果可能的话,这样就可以将2000列添加到我的DataTable中。
DataTable dtExcelRecords = new DataTable();
using (OleDbConnection con = new OleDbConnection(connectionString))
{
con.Open();
DataTable dtSheet = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
List<string> listSheet = new List<string>();
foreach (DataRow drSheet in dtSheet.Rows)
{
if (drSheet["TABLE_NAME"].ToString().Contains("$"))
{
listSheet.Add(drSheet["TABLE_NAME"].ToString());
}
}
string workSheetName = listSheet.FirstOrDefault(x => x.Contains(cCommon.sFDDetailsWorkSheetName));
OleDbCommand cmd = new OleDbCommand(string.Format("SELECT * FROM [{0}]", workSheetName.Trim()), con);
cmd.CommandType = System.Data.CommandType.Text;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
}