OpenFileDialog openFD = new OpenFileDialog();
            openFD.FileName = "";
            openFD.Filter = "xls|*.xls|xlsx|*.xlsx";
            openFD.Title = "选择更新文件";
            openFD.Multiselect = false;
            if (openFD.ShowDialog() == DialogResult.OK)
            {
                this.tbSelectFile.Text = openFD.FileName;
                //读取Excel
                pDataSet.Clear();
//成功的关键在于下面这句话,网上有很多不同版本,但这个是亲测可用的。
string strConn = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + openFD .FileName + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); string strExcel = ""; OleDbDataAdapter myCommand = null; strExcel = "select * from [sheet1$]"; myCommand = new OleDbDataAdapter(strExcel, strConn); myCommand.Fill(pDataSet , "table1"); conn.Close(); }

 

相关文章:

  • 2021-09-26
  • 2021-09-28
  • 2022-12-23
  • 2021-11-12
  • 2022-02-10
  • 2022-12-23
  • 2021-11-09
猜你喜欢
  • 2021-12-19
  • 2021-12-13
  • 2022-12-23
  • 2021-09-17
  • 2021-09-18
  • 2021-12-21
  • 2021-06-15
相关资源
相似解决方案