gpt4 book ai didi

c# - powerpoint c# 加载项形状分组问题

转载 作者:行者123 更新时间:2023-11-30 15:03:08 26 4
gpt4 key购买 nike

我使用 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();
}

关于c# - powerpoint c# 加载项形状分组问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11959849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com