你是用c#代码写吧!
如果是的话就要 检查表头,数据格式,还有就是防止中间有空行等
MenuHelper.ExceclType exceclType;
string path = string.Empty;
string excelConnect = string.Empty;
if (Global.ExcelVersion == "2007")
{
exceclType = MenuHelper.ExceclType.Excecl2007;
}
else
{
exceclType = MenuHelper.ExceclType.Excecl2003;
}
if (exceclType == MenuHelper.ExceclType.Excecl2003)
{
path = string.Format(@"{0}\{1}.{2}", Global.ExcelToPath, tableName, "xls");
excelConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + "Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'";
}
else if (exceclType == MenuHelper.ExceclType.Excecl2007)
{
path = string.Format(@"{0}\{1}.{2}", Global.ExcelToPath, tableName, "xlsx");
excelConnect = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + path + ";Extended Properties='Excel 12.0; HDR=YES; IMEX=1'";
}
string excelCom = string.Empty;
OleDbConnection excelConn = new OleDbConnection(excelConnect);
excelConn.Open();
DataTable excelDT = null;
excelDT = excelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
OleDbDataAdapter oad = new OleDbDataAdapter("select * from [" + excelDT.Rows[0]["TABLE_NAME"].ToString() + "]", excelConn);
DataSet ds = new DataSet();
oad.Fill(ds);
return ds.Tables[0];