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条)