是否可以创建一个ppt形状列表,即使从幻灯片中删除原件?
也可以维护其值?我想在幻灯片中创建所有形状的列表,操纵幻灯片,但仍保留原始的所有信息。
List<Microsoft.Office.Interop.PowerPoint.Shape> pptShapes = new List<Microsoft.Office.Interop.PowerPoint.Shape>();
for (int jCurr = 1; jCurr <= slide.Shapes.Count; jCurr++)
{
currShp = slide.Shapes[jCurr];
pptShapes.Add(currShp);
}
//Do something else like delete a few of the shapes
if (slide.Shapes[1] != null)
{
slide.Shapes[1].Delete();
}
//Below gives me Null since I deleted the original shape
MessageBox.Show(pptShapes[0].Type.ToString());
我想维护原始形状,因为以后我计划将特殊的占位符复制/粘贴到占位符等。因此,我不仅需要内容。
如果要引用要从某种集合中删除的值,那么无论com还是托管,都需要按值执行副本。在您的示例中,这看起来像这样:
List<Microsoft.Office.Interop.PowerPoint.Shape> pptShapes = new List<Microsoft.Office.Interop.PowerPoint.Shape>();
for (int jCurr = 1; jCurr <= slide.Shapes.Count; jCurr++)
{
currShp = slide.Shapes[jCurr];
pptShapes.Add(currShp);
}
string deletedString = "";
if (slide.Shapes[1] != null)
{
string deletedString = pptShapes[0].Type.ToString();
slide.Shapes[1].Delete();
}
MessageBox.Show(deletedString);
对于参考类型,您需要执行此对象的deepcopy。