所以我现在正在这样做......
//Codeblock edited to include otaku upgrade
const String GIFpastespecialformat = @"Picture (GIF)";
const Int32 Onemoreshape = 1;
Int32 shapeCount = sht.Shapes.Count;
WorksheetPasteSpecialArgs wspa = new worksheetpastespecialargs();
wspa.Format = GIFpastespecialformat;
wspa.Link = False;
wspa.DisplayAsIcon = False;
List<Int32> oldShapes = new List<Int32>();
foreach (var item in sht.Shapes.Items())
{
oldShapes.Add(Item.ID);
}
sht.PasteSpecial(wspa);
if((shapeCount + Onemoreshape) == sht.Shapes.Count)
{
foreach (var item in sht.Shapes.Items())
{
if(oldShapes.Exists(i => i == item.ID) == false)
{
//work with shape here
}
}
}
else
{
//report and deal with comexception, user intervention, etc
}
其中sht是表示我正在使用的工作表的变量。
答案 0 :(得分:1)
代码非常扎实。我可能做的唯一增强就是保持形状的计数 - oldShapes.Count
,看看粘贴后该数字是否会发生变化。如果是这样,则插入了一个形状。