编程语言
首页 > 编程语言> > PowerPoint C#加载项形状分组问题

PowerPoint C#加载项形状分组问题

作者:互联网

我使用Visual Studio 2010开发PowerPoint 2010加载项,并且在幻灯片上对两个对象进行分组时遇到了重大问题.我正在尝试创建两个对象,将它们放在幻灯片上,并将它们全部分组在同一函数中.添加对象并将它们放置在幻灯片上不是问题.但是当涉及分组部分时…

我努力了:

PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
PowerPoint.Slide curSlide = myPPT.ActiveWindow.View.Slide;
string[] myRangeArray = new string[2];
myRangeArray[0] =  "nameOfShape0";
myRangeArray[1] = "nameOfShape1";
curSlide.Shapes.Range(myRangeArray).Group();

PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
PowerPoint.Slide curSlide = myPPT.ActiveWindow.View.Slide;
curSlide.Shapes.Range(Array("nameOfShape0", "nameOfShape1")).Group();

两者都惨败.我对此感到非常沮丧,并真的希望某种友善的灵魂能够为我解决.谢谢.

更新:
这是我正在使用的完整代码:

PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
PowerPoint.Slide curSlide = myPPT.ActiveWindow.View.Slide;

PowerPoint.Shape browser = curSlide.Shapes.AddOLEObject(110, 70, 500, 400, "Shell.Explorer.2");
var slideName = "webBrowser_0";
browser.Name = slideName;

PowerPoint.Shape rectangle = curSlide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 110, 70, 500, 400);
rectangle.Name = "shape2";
string[] myRangeArray = new string[2];
myRangeArray[0] = "webBrowser_0";
myRangeArray[1] = "shape2";
curSlide.Shapes.Range(myRangeArray).Group();

我收到的错误是“ ShapeRange对象必须包含至少两个项目”

解决方法:

您的代码对我来说很好.尝试这个:

private void ThisAddIn_Startup(object sender, System.EventArgs e) {
    this.Application.PresentationNewSlide += Application_PresentationNewSlide;
}

void Application_PresentationNewSlide(PowerPoint.Slide Sld) {
    PowerPoint.Shape textBox = Sld.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 500, 50);
    textBox.Name = "shape1";
    textBox.TextFrame.TextRange.InsertAfter("This text was added by using code.");

    textBox = Sld.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 0, 100, 500, 50);
    textBox.TextFrame.TextRange.InsertAfter("This text was also added by using code.");
    textBox.Name = "shape2";

    PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
    PowerPoint.Slide curSlide = myPPT.ActiveWindow.View.Slide;
    string[] myRangeArray = new string[2];
    myRangeArray[0] = "shape1";
    myRangeArray[1] = "shape2";
    curSlide.Shapes.Range(myRangeArray).Group();
}

标签:add-in,visual-studio-2010,powerpoint,c
来源: https://codeday.me/bug/20191101/1980085.html