进一步的代码在.xls上或多或少都可以正常工作,在.xlsx上它的速度相当慢。问题在哪里?
vector = activeSheet.Columns["A", Type.Missing];
double[] temp = new double[vector.Rows.Count];
int i = 0;
foreach (var item in vector.Value2)
{
if (item == null)
break;
temp[i] = vector.Value2[i + 1, 1];
i++;
}
array = new double[i];
for (int j = 0; j < i; j++)
{
array[j] = temp[j];
}
答案 0 :(得分:0)
这一行包含一个问题:
vector = activeSheet.Columns["A", Type.Missing];
我已将上面的代码更改为:
double[] temp = new double[activeSheet.Rows.Count];
int i = 0;
for (i = 0; i < activeSheet.Rows.Count; i++)
{
var item = (activeSheet.Cells[i + 1, 1] as Excel.Range).Value2;
if (item == null)
break;
temp[i] = item;
}
...
现在它眨眼间就能正常工作。 感谢@Sayse和@Eddy的建议。