zoukankan      html  css  js  c++  java
  • C#读取Excel中的数据的类

    using System;
    using System.Collections.Generic;
    using System.Data.OleDb;
    using System.IO;
    using System.Text;

    using WirelessPlatform.Models;

    namespace WirelessPlatform.Utility
    {
        public class ExcelExtension
        {
            //private static readonly string _Conn = "Provider=Microsoft.ACE.OleDb.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=YES'";   //Office 2007
            private static readonly string _Conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'";    //Office 2003
            private static readonly string _Sql_Select_SaleInfo = "Select * From [接收短信记录$]";

            public static IList<XlsEntitySaleInfo> GetSaleInfoEntitys(string xlsFile)
            {
                IList<XlsEntitySaleInfo> list = new List<XlsEntitySaleInfo>();
                using (OleDbConnection conn = new OleDbConnection(string.Format(_Conn, Path.GetFullPath(xlsFile))))
                {
                    OleDbCommand cmd = new OleDbCommand(_Sql_Select_SaleInfo, conn);
                    conn.Open();
                    OleDbDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                         //将rdr中的数据写入数据库或显示出来

                    }
                }
                return list;
            }
        }
    }

  • 相关阅读:
    七周七语言——Prolog(二)
    centos中使用python遇到的几个问题
    use SWF / Flash in cocos2d-x; cocos2d(cocos2d-x) 直接播放flash / SWF文件
    【C++自我精讲】基础系列二 const
    Find发帖水王哥
    JAVA从零单排之前因
    CSharp
    python实战--Http代理服务器
    有道单词-批量导入[只有单词]
    编译原理(一道小证明题)
  • 原文地址:https://www.cnblogs.com/daytoday/p/1684274.html
Copyright © 2011-2022 走看看