VB.Net:在某些单元格中插入形状

我试图插入一个特定的单元格,例如(5,5)。 我能够把形状变成excel,但是不能弄清楚如何放入(5,5)。 经过研究,我知道形状位于工作表中的单元格之上。 我也了解到.Range在这里可能会有所帮助。

我只是不确定如何把这些拼图块拼在一起,使我的形状去(5,5)。

xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeIsoscelesTriangle, 17, 0, 15, 13)

此外,是一个初学者VB.NET所以如果你可以愚蠢的一切下来,我真的很感激它!

编辑:试过这个代码..但它把数字7 (5,5),而不是形状。

Dim aNew As MsoAutoShapeType = MsoAutoShapeType.msoShapeIsoscelesTriangle xlWorkSheet.Cells(5, 5) = anew

还试过:

xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeIsoscelesTriangle, xlWorkSheet.Range(xlWorkSheet.Cells(5, 5)).Left, xlWorkSheet.Range(xlWorkSheet.Cells(5, 5)).Top, 15, 13)

但收到了一个错误

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred

编辑:代码工作…

xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, (xlWorkSheet.Cells(3, 5)).Left, (xlWorkSheet.Cells(3, 5)).Top, 25, 14)

沿着这些行xlWorkSheet.get_range(xlWorkSheet.cells(5.5)).topcells(5.5).top

发生了types为“System.Runtime.InteropServices.COMException”的未处理的exception

debugging,使用xlWorkSheet.Range(xlWorkSheet.Cells(5, 5)).Top打破它,所以,是xlWorkSheet ok,是xlWorkSheet.Cells(5, 5)好,是xlWorkSheet.Range(xlWorkSheet.Cells(5, 5))好吧,错误在哪里,分解大的语句,实际上是从它们的组成部分开始,然后看看它们的返回和链接,就像你在这里所做的一样xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeIsoscel‌​esTriangle, xlWorkSheet.Range(xlWorkSheet.Cells(5, 5)).Left, xlWorkSheet.Range(xlWorkSheet.Cells(5, 5)).Top, 15, 13)我们不能看到你的代码/屏幕

使用VBA我会去这个在B2中打印,你可以使用高度和宽度来改变button的高度和宽度:

 Dim button As Shape Set button = ActiveSheet.Shapes("Button 1") button.Top = Range("B2").Top button.Left = Range("B2").left button.Height = 50 button.Width = 100 

或者在你的例子中:

 xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeIsoscelesTriangle, Range("B2").left, Range("B2").Top, 15, 13)