• .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;
  • 相关阅读:
    MTK相关汇总
    Android TV 学习笔记
    进程限制_limit
    Linux TV 学习笔记
    Linux firmware子系统的实现机制学习笔记
    C++ STL deque
    C++ STL Vector
    C++ STL几种数据结构对比
    vector系列--creating vector of local structure、vector of structs initialization
    vector系列--vector<unique_ptr<>>赋值给vector<unique_ptr<>>
  • 原文地址:https://www.cnblogs.com/cang12138/p/6002944.html
Copyright © 2020-2023  润新知