如何将公式从visual basic粘贴到excel中

时间:2010-05-18 07:31:59

标签: vb.net visual-studio excel

在Visual Basic代码中如下工作

MyWorksheet.Range("A1:D1").Formula = "A1B2"

在excel中显示

 A1 as A1B2
 B1 as A1B2
 C1 as A1B2
 D1 as A1B2 

我想做什么

 A1 as A1B2
 B1 as A1B3
 C1 as A2B4
 D1 as A2B5

先谢谢

1 个答案:

答案 0 :(得分:0)

在VBA中,它是:

For colNumber = 1 To 4
   Row.Cells(1, clNumber).Formula = "A" & colNumber & "B" & colNumber + 1
Next clNumber

在.Net中是:

for(int colNumber = 1; colNumber<=4; colNumber++)
   {
    MyWorksheet.Row.Cells(1, colNumber).Formula = "A" + colNumber + "B" + (colNumber + 1)
   }