zoukankan      html  css  js  c++  java
  • .NET读取Excel

    1、代码

    string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path + ";Extended Properties="Excel 12.0;HDR=Yes;"";
    //string strConn = "Provider=Microsoft.ACE.OLEDB.14.0;Data Source=" + Path + ";Extended Properties="Excel 14.0;HDR=Yes;""; // Office 07及以上版本 不能出现多余的空格 而且分号注意
    //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
    //string strConn = "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=" + Path + ";Extended Properties="Excel 16.0;HDR=Yes;IMEX=1;""; // Office 07及以上版本 不能出现多余的空格 而且分号注意
    OleDbConnection conn = new OleDbConnection(strConn);
    OleDbConnection cnnxls = new OleDbConnection(strConn);
    //读取Excel里面有 表Sheet1
    OleDbDataAdapter oda = new OleDbDataAdapter(string.Format("select * from [{0}$]", "Sheet1"), cnnxls);
    //OleDbDataAdapter oda = new OleDbDataAdapter("select [所在组] as [班级名称],count([所在组]) as [学员数],sum(case [登陆次数] when [登陆次数] > 0 then 1 else 0 end) as [登陆率],0 as [合格率],sum([日志]) as [日志数] from [Sheet1$] where [用户角色] <> '教研组长' group by [所在组]", cnnxls);
    DataSet ds = new DataSet();
    //将Excel里面有表内容装载到内存表中!
    DataTable tbContainer = new DataTable();
    oda.Fill(tbContainer);
    return tbContainer;
  • 相关阅读:
    BASE64Encoder/BASE64Decoder(转)
    对象转化为json
    Intent
    RecyclerView的单击和长按事件(转)
    selector的例子
    修改app工程名 Android Studio
    The number of method references in a .dex file cannot exceed 64K.(转)
    $(function() {})
    jQuery插件开发的两种方法及$.fn.extend的详解(转)
    myeclipse2014安装aptana3.4.0插件(转)
  • 原文地址:https://www.cnblogs.com/cang12138/p/6002944.html
Copyright © 2011-2022 走看看