Excel文件中的内容如下:
我的读取代码:public DataTable ReadExcel(string sExcelFile)
{
DataSet ds = new DataSet(); OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sExcelFile + ";" + "Extended Properties=Excel 8.0;HDR=NO;IMEX=1");
objConn.Open();
DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
string tableName = schemaTable.Rows[0][2].ToString().Trim();
string strSql = "select * from [" + tableName + "]";
OleDbCommand objCmd = new OleDbCommand(strSql, objConn);
OleDbDataAdapter myData = new OleDbDataAdapter(strSql, objConn);
myData.Fill(ds, tableName);
objConn.Close(); return ds.Tables[0];
} 可是我在调试代码的时候,监测到的数据如下:
就是其中的两列没 有了表头,不知道要怎么做,请各位指教……
我的读取代码:public DataTable ReadExcel(string sExcelFile)
{
DataSet ds = new DataSet(); OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sExcelFile + ";" + "Extended Properties=Excel 8.0;HDR=NO;IMEX=1");
objConn.Open();
DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
string tableName = schemaTable.Rows[0][2].ToString().Trim();
string strSql = "select * from [" + tableName + "]";
OleDbCommand objCmd = new OleDbCommand(strSql, objConn);
OleDbDataAdapter myData = new OleDbDataAdapter(strSql, objConn);
myData.Fill(ds, tableName);
objConn.Close(); return ds.Tables[0];
} 可是我在调试代码的时候,监测到的数据如下:
就是其中的两列没 有了表头,不知道要怎么做,请各位指教……
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货