using System;
using System.Data ;
using System.Data.OleDb ;
namespace ExcelHelp
{
public class ExcelHelper
{
//類的似有化 ,一般用於組件開發
internal ExcelHelper()
{
//nothing
}
/// <summary>
/// 創建與Excel的連接
/// </summary>
/// <param name="strFullPath">路徑名稱</param>
/// <param name="isTreatedHeader">是否添加表頭</param>
/// <param name="intIMEXMode"></param>
/// <returns></returns>
public static OleDbConnection GetConnection(string strFullPath, bool isTreatedHeader, int intIMEXMode)
{
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended PropertIEs=''Excel 8.0;HDR={1};IMEX={2};''";
string Treatedheader = string.Empty;
if (isTreatedHeader) Treatedheader = "YES";
else Treatedheader = "NO";
connectionString = string.Format(connectionString, strFullPath, isTreatedHeader, intIMEXMode);
return new OleDbConnection(connectionString);
}
/// <summary>