如何在 VB.net 中编辑单元格值 - 使用 .Interop.Excel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17854317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to edit cell value in VB.net - Using .Interop.Excel
提问by Josh
This is a simple question. I have this code:
这是一个简单的问题。我有这个代码:
CurrentRow = 3
MyColumn = 2
CurrentCell = (CurrentRow & "," & MyColumn)
WorkingSheet.Cells(CurrentCell).value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)
I thought that this would place the data on the 'WorkingSheet' in the position "B3" but it places the data in the cell "AF1".
我认为这会将数据放在位置“B3”的“工作表”上,但它会将数据放在单元格“AF1”中。
Why is this?
为什么是这样?
Thanks,
谢谢,
Josh
乔希
回答by varocarbas
Cellis not expected to be used as you are using it; you have to input the row and column indices (as integers) separated by a comma. Thus the right code is:
Cell预计不会在您使用时使用;您必须输入以逗号分隔的行和列索引(作为整数)。因此正确的代码是:
WorkingSheet.Cells(CurrentRow, MyColumn).Value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)
Another alternative you have is using Range. Example:
您拥有的另一种选择是使用Range. 例子:
WorkingSheet.Range("B3").Value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)

