exceltransfer.cs
来自「该服务平台解决了计算机网络与移动网络之间信息交换问题」· CS 代码 · 共 42 行
CS
42 行
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace DataAccess
{
public class ExcelTransfer
{
private String ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;";
private String ExcelTableName = "";
public ExcelTransfer(String excelPath,String tableName)
{
this.ConnectionString = String.Format(this.ConnectionString, excelPath);
this.ExcelTableName = tableName;
}
public DataTable GetExcelFileData()
{
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection(this.ConnectionString);
String selectCommand = String.Format("SELECT * FROM [{0}]",this.ExcelTableName);
try
{
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand, conn);
adapter.Fill(dt);
}
catch { }
return dt;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?