How to edit cell value in VB.net - Using .Interop.Excel

有些话、适合烂在心里 提交于 2019-12-11 12:59:02

问题


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".

Why is this?

Thanks,

Josh


回答1:


Cell is 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:

WorkingSheet.Cells(CurrentRow, MyColumn).Value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)

Another alternative you have is using Range. Example:

WorkingSheet.Range("B3").Value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)


来源:https://stackoverflow.com/questions/17854317/how-to-edit-cell-value-in-vb-net-using-interop-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!