using System;
        using System.Data;
        using System.Data.OleDb;
        using System.Windows.Forms;


        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=D:\\723\\文档\\客户.xlsx;Extended Properties=Excel 8.0"; 
                //string strCon = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = D:\\0723\\文档\\客户.xlsx;Extended Properties=Excel 8.0";
                OleDbConnection myConn = new OleDbConnection(strCon);
                string strCom = "SELECT * FROM [Sheet1$] ";
                myConn.Open();
                OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);

DataSet myDataSet
= new DataSet(); myCommand.Fill(myDataSet, "[Sheet1$]"); myConn.Close(); for (int i = 0; i < myDataSet.Tables[0].Rows.Count; i++) { if (!string.IsNullOrEmpty(myDataSet.Tables[0].Rows[i]["CODE"].ToString())) { string code = ""; string name = ""; code = "0,'" + myDataSet.Tables[0].Rows[i]["CODE"] + "',"; name = "'" + myDataSet.Tables[0].Rows[i]["NAME"] + "') "; } } string ss = ""; } catch (Exception ex) {
} }

 

需要读取Excel:

C# 循环读取Excel

读取出的结果集:

C# 循环读取Excel

 

  

相关文章:

  • 2022-12-23
  • 2021-05-21
  • 2021-10-06
  • 2021-04-07
  • 2021-04-05
  • 2021-12-31
  • 2022-01-29
猜你喜欢
  • 2021-10-16
  • 2021-10-10
  • 2021-11-24
  • 2021-12-21
  • 2021-06-15
  • 2021-09-26
  • 2021-09-28
相关资源
相似解决方案