有没有一个易于实现的库,可以用来读取Excel文件,并在以后创建它们呢?这是最好的选择吗?
http://support.microsoft.com/kb/302084
是的,有多个开源库可用于使用C#读取和/或编写Excel电子表格。
以下是C#库的简短列表:
最新的策划列表维护在这里。
示例:使用ExcelMapper读取Excel文件
a. 使用NuGet安装,通过在NuGet包管理器中运行以下命令:
Install-Package ExcelMapper
ExcelMapper 的 C# 代码示例
public void ReadExcelUsingExcelMapperExtension()
{
string filePath = @"C:\Temp\ListOfPeople.xlsx";
var people = new ExcelMapper(filePath).Fetch<Person>().ToList();
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
免责声明: 我喜欢 ExcelMapper 的简洁性,因此包括了这个包的示例代码。要使用其他库完成相同的操作,则需要更多的代码。