Excel Interop:按数字引用,而不是按字符串引用
早上好。
阅读有关优化 Excel Interop 的问题的答案后,我发现使用 worksheet.Range["A1:C3"]
引用单元格(与worksheet.get_range("A1:C3")
) 不太方便。我想以某种方式使用整数/长数字引用单元格,并且我不想将列号 {1, 2, 3, ...} 映射到列字母 {"A", "B", "C “,...}。
注意:我知道 .Cells
,但这不是一个选项,因为这仅返回单个单元格。
有什么想法吗?
问候
Good morning.
After having read the answer on a question about optimizing Excel Interop, I found that referencing a cell using worksheet.Range["A1:C3"]
(same as worksheet.get_range("A1:C3")
) isn't very handy. I'd like to reference the cell somehow using integer/long numbers, and I wouldn't want to map column numbers {1, 2, 3, ...} to column letters {"A", "B", "C", ...}.
Note: I know about .Cells
, but this isn't an option as this only returns single cells AFAIK.
Any idea?
regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Excel 宏 (VBA) 中,您可以使用这种方式:
将其重写为 C#/VB.NET 应该很容易。
In Excel macro (VBA) you can use this way:
It should be easy rewrite it to C#/VB.NET.
您可以使用 Cells 属性创建一个 Range 对象,该对象可用作 Range 属性的参数。
查看此处的示例: http://msdn.microsoft.com/en-us /library/bb178282.aspx 在页面中间有一个示例,其中使用 Cells 属性获取两个范围对象,并将其传递给 Range 属性而不是传递字符串:
一般来说,Cells 属性返回一个 Range 对象,您可以使用它执行任何您想要的操作:http://msdn. microsoft.com/en-us/library/bb148836.aspx
You can use the Cells property to create a Range object that can be used as argument to the Range property.
Check out the example here: http://msdn.microsoft.com/en-us/library/bb178282.aspx In the middle of the page you have an example where you use the Cells property to get two range objects that you pass to the Range property instead of passing strings:
In general, the Cells property returns a Range object that you can do whatever you want with: http://msdn.microsoft.com/en-us/library/bb148836.aspx