在C#中复制PPT形状的对象值
Copy Object Value of PPT shapes in C#
是否可以创建一个 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());
我想保持原来的形状,因为以后我打算copy/paste特殊到占位符等,所以我需要的不仅仅是内容。
如果您想要引用一个您希望从某种集合中删除的值,无论是 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。
是否可以创建一个 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());
我想保持原来的形状,因为以后我打算copy/paste特殊到占位符等,所以我需要的不仅仅是内容。
如果您想要引用一个您希望从某种集合中删除的值,无论是 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。