小编SAE*_*EED的帖子

Interop Excel很慢

我正在编写一个应用程序来打开Excel工作表并阅读它

MyApp = new Excel.Application();
MyBook = MyApp.Workbooks.Open(filename);
MySheet = (Excel.Worksheet)MyBook.Sheets[1]; // Explict cast is not required here
lastRow = MySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
MyApp.Visible = false;
Run Code Online (Sandbox Code Playgroud)

这需要大约6-7秒才能完成,这是正常的互操作Excel吗?

还有一种比这更快的阅读Excel的方法吗?

string[] xx = new string[lastRow];
for (int index = 1; index <= lastRow; index++)
{
   int maxCol = endCol - startCol;
   for (int j = 1; j <= maxCol; j++)
   {
      try
      {
         xx[index - 1] += (MySheet.Cells[index, j] as Excel.Range).Value2.ToString();
      }
      catch
      {    
      }

      if (j != maxCol) xx[index - 1] += "|"; …
Run Code Online (Sandbox Code Playgroud)

c# excel excel-interop

5
推荐指数
2
解决办法
1802
查看次数

标签 统计

c# ×1

excel ×1

excel-interop ×1