110,571
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.OleDb;
using System.Runtime;
using System.IO;
namespace TXRECE
{
/// <summary>
/// 获取Excel中表的名称
/// </summary>
/// <param name="p_ExcelFile">Excel的路径</param>
/// <returns></returns>
class sheet
{
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;
}
}
}
}