C#操作Excel(读取)
一.使用OleDb,这个法子好像不大好使.容易读错.
引用System.Data.OleDb;
/**//// <summary>
/// 返回Excel数据源
/// </summary>
/// <param name="filename">文件路径</param>
/// <returns></returns>
static public DataSet ExcelToDataSet(string filename)
{
DataSet ds;
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Extended Properties=Excel 8.0;" +
"data source=" + filename;
OleDbConnection myConn = new OleDbConnection(strCon);
string strCom = " SELECT * FROM [Sheet1$]";
myConn.Open();
OleDbDataAdapter myCommand =
/// 返回Excel数据源
/// </summary>
/// <param name="filename">文件路径</param>
/// <returns></returns>
static public DataSet ExcelToDataSet(string filename)
{
DataSet ds;
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Extended Properties=Excel 8.0;" +
"data source=" + filename;
OleDbConnection myConn = new OleDbConnection(strCon);
string strCom = " SELECT * FROM [Sheet1$]";
myConn.Open();
OleDbDataAdapter myCommand =
补充:软件开发 , C# ,
上一个:C#利用msscript.ocx控件执行JS脚本
下一个:C# 删除文件夹