我知道如何将单个单元格写入 excel 但是当我在数组 excel 表上尝试它时只填充最后一个值
这是我的范围
Excel.Range ServiceName = (Excel.Range)_sheet.get_Range(_sheet.Cells[38, "B"] as Excel.Range, _sheet.Cells[45, "B"] as Excel.Range);
_ServiceName 是包含 1,2,3,4,5,6 的列表
for (int i = 0; i < _ServiceName.Count; i++)
{
ServiceNameArray[0, i] = _ServiceName[i];
}
这是我试图写进excel,但正如我所说的,excel书中只有最后一项(6)
for (int i = 0; i < _ServiceName.Count; i++)
{
ServiceName.set_Value(Type.Missing, ServiceNameArray[0,i]);
}
有人有想法吗?
最佳答案
大卫皮拉斯是对的。你在那里做了一些其他奇怪的事情,我可以根据要求详细说明。
现在我只想指出您可以 直接分配 .Value
的属性(property)数组范围 :
ServiceName.Value2 = _ServiceName.toArray();
对于大量数据,这要快得多。
(旁注:如果你想对公式做同样的事情,出于某种奇怪的原因,你必须采取额外的步骤(加倍时间):
range.Formula = array;
range.Formula = range.Formula;
除非有更好的方法我不知道yet .)
关于c# - 如何将数组放入excel范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7223628/