c# interop excel: 将一维数组写入 excel 范围

c# interop excel: Write 1D array to excel range

我想将一维数组复制到 excel 中的列范围。为此,我正在使用 interop

我已经尝试过这些东西:

我什至尝试使用 range.value2,但这些东西将数组中的第一个索引值复制到整个范围。

假设,如果范围内有 200 行并且数组包含整数 101-300,则使用上述尝试的方法在整个范围内仅复制 101。

谁能帮我解决这个问题?如果有人能向我解释这种奇怪的行为,那会更有帮助!提前致谢。

Note: I know I can do it through a for loop, but that takes time. I would surely like to know a method which takes less than a minute to iterate a million rows.

我真的不知道上述方法到底有什么问题。但我找到了解决方案:

Excel.Range range = sheetSource.UsedRange.Columns[columnIndx];
range.Value = application.WorksheetFunction.Transpose(Ary);