是否可以使用OpenXML从Excel文件中并行检索值?

发布于 01-24 05:06 字数 1758 浏览 5 评论 0原文

我已经实现了以下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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文