zoukankan      html  css  js  c++  java
  • 读取excel

    public DataTable GetData(string strpath, string strSql,string ExcelEdition)
            {

                DataTable dtgc = null;
                OleDbConnection con = null;
                try
                {
                    string strCon;
                    switch(ExcelEdition)
                    {
                        case "2003":
                            strCon= "provider=microsoft.jet.oledb.4.0;data source=" + strpath + ";extended properties='Excel8.0;HDR=Yes;IMEX=1'";
                            break;
                        case "2007":
                            strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strpath + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\"";
                            break;
                        case "2010":
                            strCon=@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strpath+ ";" +"Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\"";
                            break;
                        case "userdefined":
                            strCon = strconExcel;
                            break;
                            default:
                            strCon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strpath + ";" + "Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\"";
                            break;
                    }
                     if (strCon=="")
                     {
                         MessageBox.Show("没有设置自定义的连接字符串");
                         return null;
                     }
                      
                


                    con = new OleDbConnection(strCon);

                    OleDbCommand cmd = new OleDbCommand(strSql, con);
                    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                    DataSet ds = new DataSet();

                    da.Fill(ds);
                    dtgc = ds.Tables[0];

                    return dtgc;
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return null;
                }
                finally
                {
                    con.Close();
                }


            }

  • 相关阅读:
    Apache并发相关的几个配置
    MPM:Multi-Processing Modules
    regsvr32是干什么的
    第一个子容器设置margin-top后和父容器发生外边距合并,解决办法是给父容器设置非0 padding-top或overflow:hidden
    li或dd 浮动后增加图片时高度多出3-5px的问题
    [Error: No platforms added to this project. Please use `cordova platform add <platform>`.]
    单链表的实现(python)
    python的顺序表(list,tuple)
    python装饰器
    梯度下降算法
  • 原文地址:https://www.cnblogs.com/jinyuttt/p/2213679.html
Copyright © 2011-2022 走看看