介绍
Lightweight and fast library written in C# for reading Microsoft Excel files

ExcelDataReader是一个用c#写的轻量级且高效的操作Microsoft Excel文件的类库。

github地址: 
https://github.com/ExcelDataReader/ExcelDataReader

 

卡号卡状态人员姓名人员编号
2019071500正常卡首页95636858
using System;
using System.IO;
using ExcelDataReader;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using Utils.Framework;

namespace TestDemoC {
    class Program {
        static void Main(string[] args) {

            var excelPath = System.Environment.CurrentDirectory + "\\card2019-07-12 09_20_06.xls";

            using (var stream = File.Open(excelPath, FileMode.Open, FileAccess.Read)) {

                using (var reader = ExcelReaderFactory.CreateReader(stream)) {

                    do { while (reader.Read()) { } } while (reader.NextResult());

                    var configuration = new ExcelDataSetConfiguration { ConfigureDataTable = tableReader => new ExcelDataTableConfiguration { UseHeaderRow = true } };
                    var result = reader.AsDataSet(configuration);

                    var data = result.Tables[0].ToList<TestEntity>();

                    Log(data.Json());
                }
            }

            Console.ReadLine();
        }

        public class TestEntity {

            public string 卡号 { get; set; }

            public string 卡状态 { get; set; }

            public string 人员姓名 { get; set; }

            public string 人员编号 { get; set; }

        }

        private static void Log(string msg) {

            Console.Write($"{DateTime.Now:yyyy-MM-dd HH:mm:ss:fff} [Info] { msg}{System.Environment.NewLine}");
        }

    }
}

 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐