首页 > 解决方案 > C#如何使用foreach方法循环Excel命名范围

问题描述

我需要循环一些 Excel 数据,但每个文件中有 100 万个数据。

我尝试使用“for”和“Parallel.For”进行循环,但速度太慢,因此我想尝试使用 foreach 但我不知道如何制作。Parallel.For 代码如下:

Parallel.For(2, lastUsedRow, i =>
       {
           int AddValue = DValue + 1;
           DValue = AddValue;
           currentsheet.Cells[1, 1].Value = AddValue + "/" + lastUsedRow;
           if (currentsheet.Cells[i, 3].Value != "")
           {
               currentsheet.Cells[i, 3].Value = Regex.Replace(currentsheet.Cells[i, 3].Text, "[ \\[ \\] \\^ \\-_*×――(^)(^)$%~!@#$…&amp;%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "");
               currentsheet.Cells[i, 3].Value = currentsheet.Cells[i, 3].Text.ToUpper();
               currentsheet.Cells[i, 3].Value = currentsheet.Cells[i, 3].Text.Replace(" ", "");
           }
           else
           {
               currentsheet.Cells[i, 3].Value = "";
           }
           string COLVALUE = currentsheet.Cells[i, 3].Text;
           if (Regex.Matches(COLVALUE, "[a-zA-Z]").Count != 0 & COLVALUE.Length != 12)
           {
               currentsheet.Cells[i, 3].Value = "";
               currentsheet.Cells[i, 4].Value = COLVALUE;
           }
       });

这里的每个朋友都知道如何在行范围或命名范围内进行 foreach 循环吗?非常感谢。

标签: c#excelvsto

解决方案


推荐阅读