【发布时间】:2018-03-17 19:27:00
【问题描述】:
我正在使用 VS2008 和 VSTO(C#) 在 Office 2007 上编写 Excel 插件。 此插件需要存储嵌入或工作簿内部的信息,以在用户再次使用此类信息打开工作簿时恢复某些状态。在保存工作簿之前,插件会在 XML 中序列化所有信息,打开工作簿后,插件会尝试反序列化这些信息(如果找到)。
我尝试使用 Office.DocumentProperties,但每个字符串元素被截断(最多 256 个字符)
在事件 Excel.AppEvents_WorkbookOpenEventHandler 和 Excel.AppEvents_WorkbookBeforeCloseEventHandler :
Office.DocumentProperties properties = (Office.DocumentProperties)this.Application.ActiveWorkbook.CustomDocumentProperties;
properties.Add(Constants.ADDIN_PERSISTENCE, false, Office.MsoDocProperties.msoPropertyTypeString, serialize(configurationInstance), null);
在事件AppEvents_WorkbookOpenEventHandler:
Office.DocumentProperties properties = (Office.DocumentProperties)Application.ActiveWorkbook.CustomDocumentProperties;
Configuration configurationInstance = deserialize((string)properties[Constants.ADDIN_PERSISTENCE]);
但这不起作用,因为序列化返回的字符串长度超过 256 个字符。
在其他插件中,通过 Excel 2003,我将信息存储在“非常隐藏”工作表的第一个单元格中,名称很奇怪。不知道有没有更好的解决办法。
【问题讨论】:
标签: excel persistence vsto add-in