使用Excel互操作设置单元格的值 [英] Set cell value using Excel interop

查看:141
本文介绍了使用Excel互操作设置单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我正在尝试设置与Excel的互操作库中的单元格的值。我可以用下面的做到这一点:

Ok, so I'm trying to set the value of a cell with the excel interop library. I am able to do it with the following:

sheet.Cells[row, col] = value;



但它是我有多少可怕的设置慢。所以我试图走这条路线:

but it's terribly slow for how many I'm setting. So I'm trying to go this route:

Range excelRange = sheet.UsedRange;
excelRange.Cells.set_Item(row, col, value);



的代码执行,但没有数据被放置在小区。对我缺少什么,我有什么建议?谢谢!

The code executes, but no data is put in the cell. Any suggestions on what I'm missing? Thanks!

推荐答案

您第一个方法应该可以正常工作的任何合理(和很多不合理的)量的细胞,只要你有禁用屏幕更新( Application.ScreenUpdating = FALSE )。该知识库文章描述了如何使用C#来设置细胞的行和列,以及访问。

Your first method should work fine for any reasonable (and a lot of unreasonable) amounts of cells, provided you have disabled screen updating (Application.ScreenUpdating = false). The Knowledgebase Article describing how to set cells using C# accesses by row and column as well.

这篇关于使用Excel互操作设置单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆