VSTO PowerPoint 代码删除Shape后再恢复出现无法再次获取的问题
做PowerPoint的VSTO插件项目,遇到个很奇怪的问题,当代码执行删除某些Shape时,没问题,但是操作Undo也就是恢复后,无法再次获取到之前删除的对象,这种情况只在Office2007中出现,亲测2010没问题。
就在快要放弃的时候,终于看到了这个
传送门:https://www.add-in-express.com/creating-addins-blog/2014/06/24/exception-hresult-0x800a01a8/
关键内容搬运如下:
private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed) {
PowerPoint.DocumentWindow activeWindow = PowerPointApp.ActiveWindow;
if (activeWindow != null) {
PowerPoint.View view = activeWindow.View;
if (view != null) {
object obj = view.Slide;
if (obj != null) {
if (obj is PowerPoint.Slide) {
PowerPoint.Shapes shapes = (obj as PowerPoint.Slide).Shapes;
if (shapes.HasTitle == Microsoft.Office.Core.MsoTriState.msoTrue) {
PowerPoint.Shape titleShape = shapes.Title;
object titleParent = null;
try {
titleParent = titleShape.Parent;
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
if (titleParent != null) {
// use titleParent
}
titleShape.Delete();
// leaving the COM object below unreleased causes 0x800A01A8 if you click Undo in the PP UI and invoke this code anew
Marshal.ReleaseComObject(titleShape); titleShape = null;
}
Marshal.ReleaseComObject(shapes); shapes = null;
}
Marshal.ReleaseComObject(obj); obj = null;
}
Marshal.ReleaseComObject(view); view = null;
}
Marshal.ReleaseComObject(activeWindow); activeWindow = null;
}
}
理解后,很容易就解决了这个问题,分享一下
VSTO PowerPoint 代码删除Shape后再恢复出现无法再次获取的问题的更多相关文章
- windows 10 删除库后自动恢复的解决方法
目录 什么是windows 库? 手动删除不行吗? 如何正确的"删除"? title: windows 10 删除库后自动恢复的解决方法 date: 2019-06-09 15:4 ...
- django 删除表后如何恢复
大家都知道Python manage.py makemigrations 创建迁移文件也就是sql语句,python manage.py migrate执行makemigrations创建的文件,如果 ...
- kafka删除topic后再创建同名的topic报错(ERROR org.apache.kafka.common.errors.TopicExistsException)
[hadoop@datanode3 logs]$ kafka-topics.sh --delete --zookeeper datanode1:2181 --topic firstTopic firs ...
- k8s删除节点后再重新添加进去(踩坑)
开启本地集群,发现一台节点出问题了,想删除再换一台节点,结果就踩坑了,还好本地有好几套环境. 再master节点执行以下命令 [root@k8s-master ~]# kubectl drain k8 ...
- ios8中,相册创建后手动删除,不能再进行创建显示
// Add a new ALAssetsGroup to the library. // The name of the ALAssetsGroup is name and the type is ...
- [转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slave_master_info' cannot be opened.问题
[转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slav ...
- id 自增------删除数据后恢复到删除前自增id
删除数据后,执行下面语句: ALTER TBALE TableName AUTO_INCREMENT=1 mysql删除比较 一.DROP drop table tablename 绝招:删除内容和 ...
- 无备份mysql删除表后恢复
mysql从5.6.17开始自动设置innodb_file_per_table为on,每个表设置单独表空间,数据不是集中存放在ibdata1里.下面测试下无备份后drop表后的恢复. 前奏生成数据字典 ...
- 在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了?
在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了? 在删除成功后,加上这句话就可以了:$("#dg").datagrid ...
随机推荐
- 【less】Bootstrap / Less 学习
我是借助的 考拉 来编译LESS~~ http://www.openkoala.org/download.html 官网 less 提供的主要功能 1.变量个人觉得,变量是 Less 最重要的功能.举 ...
- 大众点评cat系统的搭建笔记
项目地址:https://github.com/dianping/cat 编译步骤: 这个项目比较另类,把编译需要的jar包,单独放在git分支mvn-repo里了,而且官方文档里给了一个错误的命令提 ...
- [LeetCode] Battleships in a Board 平板上的战船
Given an 2D board, count how many different battleships are in it. The battleships are represented w ...
- [LeetCode] Reverse Bits 翻转位
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- [LeetCode] Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
- [LeetCode] Longest Valid Parentheses 最长有效括号
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- python基础-面向对象编程
一.三大编程范式 编程范式即编程的方法论,标识一种编程风格 三大编程范式: 1.面向过程编程 2.函数式编程 3.面向对象编程 二.编程进化论 1.编程最开始就是无组织无结构,从简单控制流中按步写指令 ...
- 使用TortoiseGit对android studio工程进行代码版本控制
阅读下列文章时请保证你是否有以下工具: 1.Android Studio 2.TortoiseGit 和 msysGit 安卓工程版本控制哪些文件可以忽略 可以省略的文件如下: 目录 .gradle ...
- What's Security
研究安全应该时常问自己这个问题,什么是安全,什么是安全,什么是安全,安全的本质是什么,只有理解了安全的本质,才能成功的设计一个安全方案. 现在的感觉是没有绝对的安全,所谓的'安全'其实都只不过是增加攻 ...