Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VB.Net:在特定单元格中插入形状_Excel_Vb.net_Vba_Cell_Shape - Fatal编程技术网

Excel VB.Net:在特定单元格中插入形状

Excel VB.Net:在特定单元格中插入形状,excel,vb.net,vba,cell,shape,Excel,Vb.net,Vba,Cell,Shape,我试图在一个特定的单元格中插入一个形状,例如(5,5)。我能够将形状输入excel,但不知道如何将其输入(5,5)。经过研究,我知道形状位于工作表的单元格顶部。我还了解到,.Range在这里可能会有所帮助 我只是不知道如何把这些拼图拼在一起,使我的形状达到(5,5) xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoshapeisoscelestrangle,17,0,15,13) 另外,我是vb.net的初学者,所以如果你能把所有的事情都简化,我会

我试图在一个特定的单元格中插入一个形状,例如(5,5)。我能够将形状输入excel,但不知道如何将其输入(5,5)。经过研究,我知道形状位于工作表的单元格顶部。我还了解到,
.Range
在这里可能会有所帮助

我只是不知道如何把这些拼图拼在一起,使我的形状达到(5,5)

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

另外,我是vb.net的初学者,所以如果你能把所有的事情都简化,我会非常感激

编辑: 已尝试此代码。。但它将数字
7
放在(5,5)中,而不是形状

重新变暗为msoauthosapetype=msoauthosapetype.msoShapeIsoscelesTriangle
xlWorkSheet.Cells(5,5)=重新设置

还尝试:

xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeIsoscelesTriangle,xlWorkSheet.Range(xlWorkSheet.Cells(5,5))。左侧,xlWorkSheet.Range(xlWorkSheet.Cells(5,5))。顶部,15,13)

但是收到了一个错误

发生“System.Runtime.InteropServices.COMException”类型的未处理异常

编辑:工作的代码

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

使用VBA我想在B2中打印,您可以使用高度和宽度更改按钮高度和宽度:

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)

使用VBA,我将在B2中打印此按钮,您可以使用“高度”和“宽度”更改按钮的高度和宽度:

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)

沿着这些线的东西
xlsheet.get_范围(xlsheet.cells(5.5)).top
单元格(5.5).top

发生类型为“System.Runtime.InteropServices.COMException”的未处理异常


调试,使用
xlsheet.Range(xlsheet.Cells(5,5)).Top
分解它,is
xlsheet
ok,is
xlsheet.Cells(5,5)
ok,is
xlsheet.Range(xlsheet.Cells(5,5))
ok,错误在哪里,分解大语句,实际上从它们的组成部分开始,然后查看它们的返回并像您在这里所做的那样链接在一起
xlsheet.Shapes.AddShape(MsoAutoShapeType.msoShapeIsoscel‌​esTriangle,xlWorkSheet.Range(xlWorkSheet.Cells(5,5))。Left,xlWorkSheet.Range(xlWorkSheet.Cells(5,5)).Top,15,13)
我们看不到您的代码/屏幕

沿着这些线的东西
xlWorkSheet.get_Range(xlWorkSheet.Cells(5.5)).Top
Cells(5.5.Top

发生类型为“System.Runtime.InteropServices.COMException”的未处理异常


调试,使用
xlsheet.Range(xlsheet.Cells(5,5)).Top
分解它,is
xlsheet
ok,is
xlsheet.Cells(5,5)
ok,is
xlsheet.Range(xlsheet.Cells(5,5))
ok,错误在哪里,分解大语句,实际上从它们的组成部分开始,然后查看它们的返回并像您在这里所做的那样链接在一起
xlsheet.Shapes.AddShape(MsoAutoShapeType.msoShapeIsoscel‌​esTriangle,xlsheet.Range(xlsheet.Cells(5,5))。Left,xlsheet.Range(xlsheet.Cells(5,5))。Top,15,13)
我们看不到您的代码/屏幕

VB.NET和vba是两个不同的东西。我认为它们在这方面是相似的;如果不是,我道歉!您可以从单元格中获取左侧和顶部属性吗?在vba
单元格(5,5)中。top
@Nathan_Sav这就是我读到的内容,但我不确定如何处理它。VB.NET和vba是两件不同的事情。我认为它们在这方面是相似的;如果不是,我道歉!您可以从单元格中获取左侧和顶部属性吗?在vba
单元格(5,5).top
@Nathan_Sav中,这就是我读到的内容,但我不知道如何进行