完成粘贴操作后检测工作簿中新形状的正确方法

发布于 2024-10-20 21:09:32 字数 822 浏览 2 评论 0原文

所以我目前正在这样做...

//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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2024-10-27 21:09:32

代码相当扎实。也许我要做的唯一增强就是保留形状的计数 - 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文