如题: 
DataSet ptsHrDs=new DataSet(); 

#region 用数据库的方式打开EXCEL文件 string file=strFile.Substring(strFile.LastIndexOf(@"\")+1); OleDbConnection myConn=null;
OleDbDataAdapter myCommand=null; //把XLS文件读入到DATASET中

try
{
myConn = new OleDbConnection(" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + strFile + ";Extended Properties=Excel 8.0;") ;
myConn.Open() ;
//打开数据链接,得到一个数据集
myCommand = new OleDbDataAdapter("SELECT * FROM ["+strTableName +"$]",myConn);
//得到自己的DataSet对象
myCommand.Fill(ptsHrDs,strTableName) ;
}
catch(System.Data.OleDb.OleDbException ex)
{
CPublicFun.WriteLog(System.DateTime.Now.ToString(),ex.ToString());
MessageBox.Show(ex.Message,"信息提示");
return false ;
}

//关闭此数据链接
myConn.Close();
myConn=null;
myCommand=null; #endregion

#region 返回最后一列,最后一行的坐标// MaxCol=ptsHrDs.Tables[0].Columns.Count;
iEndCol = getExcelCol(ptsHrDs.Tables[0].Columns.Count);
iEndRow = Convert.ToString(ptsHrDs.Tables[0].Rows.Count+1);//这个行数包括空白的行

解决方案 »

  1.   

    SELECT * FROM ["+strTableName +"$]
    SQL上加个where条件,判断字段不为空
    试试
      

  2.   

    SELECT * FROM ["+strTableName +"$]"+"where field1 IS NULL"
    field1 为你关心的列名 
      

  3.   

    似乎要判断Excel文件中哪些行是空行有些难度,特别是你无法了解Excel文件的具体内容(格式)时。
    我可以想得到的办法似乎是一一去判断,但是很费时间。
      

  4.   

    多谢 是个好办法 我的Excel确实有必填的列 结贴了!