liaomin416100569
public static int GetExcelTableCount(string filename) { DataTable dt = new DataTable(); OleDbConnection cnnxls = new OleDbConnection(); try { string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ;Extended Properties=Excel 8.0;Data Source =" + filename; cnnxls.ConnectionString = mystring; cnnxls.Open(); dt = cnnxls.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); return dt.Rows.Count; } finally { cnnxls.Close(); } return 0; } public static string[] GetExcelTableNames(string filename) { DataTable dt = new DataTable(); OleDbConnection cnnxls = new OleDbConnection(); try { string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ;Extended Properties=Excel 8.0;Data Source =" + filename; cnnxls.ConnectionString = mystring; cnnxls.Open(); dt = cnnxls.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); } finally { cnnxls.Close(); } List names = new List(); foreach (DataRow row in dt.Rows) { names.Add(row["TABLE_NAME"].ToString().Trim(\'/\'\', \'$\').Replace("\'\'", "\'").Replace("$$", "$")); } return names.ToArray(); }

分类:

技术点:

相关文章:

  • 2021-10-17
  • 2021-10-26
  • 2021-10-17
  • 2021-11-09
  • 2021-10-17
  • 2021-10-17
  • 2021-10-17
  • 2021-11-27
猜你喜欢
  • 2021-10-17
  • 2021-10-17
  • 2021-10-17
  • 2021-10-17
  • 2021-12-15
  • 2021-10-17
相关资源
相似解决方案