是否可以使用OpenXML从Excel文件中并行检索值?
我已经实现了以下GET值的变体(参见 link ),我用它来读取Excel Tabel。但是,由于读取每个单元格的速度缓慢,我已经实现了一个相似之处:
DataTable resultTable = DataManager.GetEmptyCredentialsTable();
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = 1;
// Parallel loading Excel row data.
Parallel.ForEach<int, DataTable>(
rowNumberArray,
options,
// Creating subsets of the credentials table to be loaded in.
() => DataManager.GetEmptyCredentialsTable(),
(int r, ParallelLoopState loop, DataTable dt) =>
{
string clientName = GetCellData(wbPart, wspCredentials, "B" + r.ToString());
// There has to be a client name in order to parse the data row.
if (clientName != null && clientName != "")
{
dt.Rows.Add(GetRow(wbPart, wspCredentials, dt, r));
}
return dt;
},
final_dt =>
{
lock (resultTable)
{
resultTable.Merge(final_dt);
}
});
但是,如果我们设置options.maxdegreofparallelism = 2
,这是无法正常工作的,因为OpenXML似乎并不支持这一点。是否有人以更快的方式从Excel文档中检索单元格值?也许我们可以规避并行访问限制吗?
I have implemented a variant of the following get cell value (see link) and I use this to read an Excel tabel. However, due to the slow pace of reading every cell, I have implemented a parallel foreach:
DataTable resultTable = DataManager.GetEmptyCredentialsTable();
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = 1;
// Parallel loading Excel row data.
Parallel.ForEach<int, DataTable>(
rowNumberArray,
options,
// Creating subsets of the credentials table to be loaded in.
() => DataManager.GetEmptyCredentialsTable(),
(int r, ParallelLoopState loop, DataTable dt) =>
{
string clientName = GetCellData(wbPart, wspCredentials, "B" + r.ToString());
// There has to be a client name in order to parse the data row.
if (clientName != null && clientName != "")
{
dt.Rows.Add(GetRow(wbPart, wspCredentials, dt, r));
}
return dt;
},
final_dt =>
{
lock (resultTable)
{
resultTable.Merge(final_dt);
}
});
But this does not work properly if we set the options.MaxDegreeOfParallelism = 2
, because OpenXML does not seem to support this. Does someone have a solution to retrieve the cell values from an Excel document in a bit more speedy manner? Or perhaps can we circumvent the parallel access limitations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论