c# 使用ExcelDataReader读写excel(.xls,.xlsx)
介绍Lightweight and fast library written in C# for reading Microsoft Excel filesExcelDataReader是一个用c#写的轻量级且高效的操作Microsoft Excel文件的类库。github地址:https://github.com/ExcelDataReader/ExcelDataReader...
文章共231字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
介绍
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}");
}
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)