最佳的方式来阅读一个Excel文件(.xls / .xlsx)格式 [英] Optimal way to Read an Excel file (.xls/.xlsx)
问题描述
我知道有很多不同的方法来读取Excel文件:
I know that there are different ways to read an Excel file:
-
Iterop
-
OLEDB
-
的Open XML SDK
Iterop
Oledb
Open Xml SDK
兼容性不是因为该方案将在受控的环境中执行的问题。
Compatibility is not a question because the program will be executed in a controlled environment.
我的要求:结果
读取文件到数据表
/ 自定义Entitie
S(我不知道如何使动态属性/领域为对象[列名在一个Excel文件中variating])
My Requirement :
Read a file to a DataTable
/ CUstom Entitie
s (I don't know how to make dynamic properties/fields to an object[column names will be variating in an Excel file])
使用的DataTable /自定义实体
使用其数据来执行某些操作。
Use DataTable/Custom Entities
to perform some operations using its data.
更新数据表
与操作的结果。
写回 excel文件
。
这将是简单的。
此外,如果可能的建议我的自定义实体(添加属性/字段动态对象)
Also if possible advice me on custom Entities (adding properties/fields to an object dynamically)
推荐答案
看看 LINQ到Excel中。 。这是相当整洁
Take a look at Linq-to-Excel. It's pretty neat.
var book = new LinqToExcel.ExcelQueryFactory(@"File.xlsx");
var query =
from row in book.Worksheet("Stock Entry")
let item = new
{
Code = row["Code"].Cast<string>(),
Supplier = row["Supplier"].Cast<string>(),
Ref = row["Ref"].Cast<string>(),
}
where item.Supplier == "Walmart"
select item;
它还允许强类型行访问了。
It also allows for strongly-typed row access too.
这篇关于最佳的方式来阅读一个Excel文件(.xls / .xlsx)格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!