zoukankan      html  css  js  c++  java
  • C#读取Excel设置(亲测可用)

     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(); }
  • 相关阅读:
    第五周总结
    第四周总结
    第三周总结
    第二周总结
    第一周总结
    暑假学习进度八
    使用nmtui文本框方式修改IP
    Linux 忘记密码配置
    关于公网IP和内网IP
    常见API编写方式(三种)
  • 原文地址:https://www.cnblogs.com/pengdage110/p/4244777.html
Copyright © 2011-2022 走看看