是否有免费或开源的库可以直接从c#程序中读取Excel文件(.xls) ?
它不需要太花哨,只需选择一个工作表并将数据作为字符串读取即可。到目前为止,我一直在使用Excel的Export to Unicode文本功能,并解析生成的(以制表符分隔的)文件,但我想消除手动步骤。
是否有免费或开源的库可以直接从c#程序中读取Excel文件(.xls) ?
它不需要太花哨,只需选择一个工作表并将数据作为字符串读取即可。到目前为止,我一直在使用Excel的Export to Unicode文本功能,并解析生成的(以制表符分隔的)文件,但我想消除手动步骤。
当前回答
虽然迟到了,但我是LinqToExcel的粉丝
其他回答
Excel数据阅读器怎么样?
http://exceldatareader.codeplex.com/
我在生产环境中使用了anger,将大量数据从各种Excel文件中提取到SQL Server Compact中。它工作得非常好,而且相当健壮。
这是我在Excel 2003中使用的:
Dictionary<string, string> props = new Dictionary<string, string>();
props["Provider"] = "Microsoft.Jet.OLEDB.4.0";
props["Data Source"] = repFile;
props["Extended Properties"] = "Excel 8.0";
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, string> prop in props)
{
sb.Append(prop.Key);
sb.Append('=');
sb.Append(prop.Value);
sb.Append(';');
}
string properties = sb.ToString();
using (OleDbConnection conn = new OleDbConnection(properties))
{
conn.Open();
DataSet ds = new DataSet();
string columns = String.Join(",", columnNames.ToArray());
using (OleDbDataAdapter da = new OleDbDataAdapter(
"SELECT " + columns + " FROM [" + worksheet + "$]", conn))
{
DataTable dt = new DataTable(tableName);
da.Fill(dt);
ds.Tables.Add(dt);
}
}
Koogra是一个用c#编写的开源组件,可以读写Excel文件。
SpreadsheetGear非常棒。是的,这是一笔费用,但与其他解决方案相比,这是值得的。它快速,可靠,非常全面,我不得不说,在我的全职软件工作中使用这个产品超过一年半之后,他们的客户支持非常棒!
如果我离题了请原谅,但这不是Office PIA的用途吗?