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 ...
随机推荐
- OpenStack 企业私有云的若干需求(4):混合云支持 (Hybrid Cloud Support)
本系列会介绍OpenStack 企业私有云的几个需求: 自动扩展(Auto-scaling)支持 多租户和租户隔离 (multi-tenancy and tenancy isolation) 混合云( ...
- Struts2 验证码图片实例
本文转载于DongLiYang的博客http://www.cnblogs.com/dongliyang/archive/2012/08/24/2654431.html 其中修改过一部分,针对使用注解而 ...
- [LeetCode] Integer Replacement 整数替换
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- [LeetCode] Ugly Number II 丑陋数之二
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- Docker实践--部署Nodejs应用
这个例子的目标是为了向大家展示如何在Docker的container里运行Node.js程序.我会先创建一个简单的Node.js web app,来构建一个镜像.然后基于这个Image运行一个cont ...
- Rabin-Karp指纹字符串查找算法
首先计算模式字符串的散列函数, 如果找到一个和模式字符串散列值相同的子字符串, 那么继续验证两者是否匹配. 这个过程等价于将模式保存在一个散列表中, 然后在文本中的所有子字符串查找. 但不需要为散列表 ...
- console的花式用法
1.百度的招聘启示 如图: 下面是输出代码: if(window.console){ var cons = console; if(cons){ cons.log("%c\n ", ...
- ActiveMQ入门
ActiveMQ简介 概要 开源 JMS-compliant 消息中间件message-oriented middleware(MOM) 松耦合,相对于RPC的紧耦合 发送消息fire-and-for ...
- Javascript模板引擎插件收集
为什么要用JS的模板引擎,打个比方,如果你要通过接口绑定数据,最终要加进去DOM中,我们普遍的做法就是不断的+,最终append进去,但是这样的做法就是后续人员压根就没法维护.所以这时模板引擎出来了. ...