/// 獲取EXCEL的表 表名字列
///
/// Excel文件 ///
public static DataTable GetExcelTableName(string p_ExcelFile)
{
try
{
if (System.IO.File.Exists(p_ExcelFile))
{
OleDbConnection _ExcelConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"Excel 8.0\";Data Source=" + p_ExcelFile);
_ExcelConn.Open();
DataTable _Table = _ExcelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
_ExcelConn.Close();
return _Table;
}
return null;
}
catch
{
return null;
}
}
///
/// 獲取Excel的列名
///
/// 文件 /// 表名 ///
public static DataTable GetExcelColumnName(string p_ExcelFile, string p_Table)
{
try
{
if (System.IO.File.Exists(p_ExcelFile))
{
OleDbConnection _ExcelConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"Excel 8.0\";Data Source=" + p_ExcelFile);
_ExcelConn.Open();
DataTable _ValueColumn = _ExcelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new Object[] { null, null, p_Table, null });
_ExcelConn.Close();
return _ValueColumn;
}
return null;
}
catch
{
return null;
}
}
獲取表名和列名...
沒有留言:
張貼留言