完成粘贴操作后检测工作簿中新形状的正确方法
所以我目前正在这样做...
//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 是代表我正在使用的工作表的变量。
so i am currently doing this...
//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
}
Where sht is the variable representing the worksheet i am working with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码相当扎实。也许我要做的唯一增强就是保留形状的计数 -
oldShapes.Count
并查看粘贴后该数字是否发生变化。如果是这样,则已插入一个形状。The code is pretty solid. Probably the only enhancement I would make is just keep a count of the shapes -
oldShapes.Count
and just see if that number changes after a Paste. If so, a shape has been inserted.