c# 使用ExcelDataReader读写excel(.xls,.xlsx)

c# 使用ExcelDataReader读写excel(.xls,.xlsx)

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

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

github地址: 

 

卡号卡状态人员姓名人员编号
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}");}}
}

 

发布者:admin,转转请注明出处:http://www.yc00.com/news/1687774012a42857.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信