使用c# VSTO插件获得选定的图表对象或文本框架或表?



我试图在VSTO插件的PPTX文件中获得当前选择的对象。

我正在使用下面的包来创建幻灯片中的图表、表格和文本。

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

我有一个按钮出现在酒吧里。一旦用户点击了它,我想在任何幻灯片中获得当前选中的对象。我该怎么做呢?在interop包中是否存在任何方法

如果你正在选择一个或多个形状,你可以这样做

if (Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange.Count > 0)
{
//iterate over all the shapes selected by the user
foreach (PowerPoint.Shape shp in Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange)
{
if (shp.HasTable == Office.MsoTriState.msoTrue)
{
//Do something
}
if (shp.HasChart == Office.MsoTriState.msoTrue)
{
//Do something
}
if (shp.HasTextFrame == Office.MsoTriState.msoTrue)
{
//Do something
}
//or you could just return the shp object
}
}

相关内容

最新更新