如何在 PowerPoint VSTO 中查找演示文稿的文件格式?
我一直在为 2007 Office System 开发一些 Office 加载项。加载项需要知道文件格式,因为只有当格式是较新的基于 XML 的压缩格式(docx、xlsx、xlsm、pptx 等)之一时,它们才会执行操作。
尽管每个 Office 产品的 API(调用和行为)存在差异,但我还是成功地为 Word 和 Excel 制作了可用的加载项。在这两种情况下,我都可以检测保存事件并根据文件格式以及是保存还是另存为操作进行更改。然而,我来到了 PowerPoint,我很难确定文件是什么格式或正在保存为什么格式,以及它是常规保存还是另存为操作。
所以,我的问题是,在 PowerPoint VSTO 加载项中:
- 是否有任何方法可以确定文件格式(除了文件扩展名比较之外)?
- 是否可以确定保存是常规保存还是另存为?
更新
好吧,我改变了我的搜索,发现这些问题似乎回答了我的第一个问题(即除了使用扩展之外别无他法),但第二个问题仍然存在(也许直到我改进我的搜索功能)。
I have been working on some Office add-ins for the 2007 Office System. The add-ins need to know the file format as they are only to perform their actions when the format is one of the newer compressed XML-based formats (docx, xlsx, xlsm, pptx, etc.).
Despite the disparity in the APIs (calls and behaviours) for each Office product, I have managed to produce working add-ins for Word and Excel. In both of these, I can detect the save event and make my changes based on the file format and whether it is a save or save as operation. However, I have come to PowerPoint and I am struggling to determine what format the file is or is being saved as and whether it is a regular save or a save as operation.
So, my questions are, in a PowerPoint VSTO add-in:
- Is there any way to determine the file format (other than just a file extension comparison)?
- Is it possible to determine if a save is a regular save or a save as?
Update
Okay, I changed my search and found these questions that seem to answer my first question (i.e. there is no way other than to use the extension), but the second question still stands (perhaps until I improve my search-fu).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我记得用PPT,没有办法做到。您必须拦截 OPEN 事件,缓存文档的文件名,然后在保存期间检查文件名。如果相同,则为SAVE,如果不同,则为另存为。
如果文档是新的,则不会有初始文件名,因此保存必须另存为。
As I recall with PPT, there's no way to do it. You have to intercept the OPEN event, cache the file name for the document, then, during the save, check the filename. if its the same, then it was a SAVE, If different, it's a save as.
If the document was NEW, there won't be an initial filename, so the save would HAVE to be a save as.
Application.PresentationBeforeSave
是要挂钩的事件,它会告诉您这是“另存为...”,因为它发生在“另存为”对话框出现之前。Application.PresentationSave
是常规保存(但可以以编程方式用于“另存为...”)所以我要做的就是放置一个类似于
Dim isSaveAs As Boolean 的全局变量= False
在模块中,然后在Application.PresentationBeforeSave
将其设置为True
(除非其参数Cancel = True
- 在这种情况我会将其设置回False
)。然后,在Application.PresentationSave
事件中,我将检查If isSaveAs = True then DoThis Else DoThat
。然后在Application.PresentationSave
事件结束时将isSaveAs
设置回False
。Application.PresentationBeforeSave
is the event to hook that will tell you this is a "Save As..." because it occurs right before the Save As dialog appears.Application.PresentationSave
is a regular save (but can be used for a "Save As..." programatically)So what I would do is put a global variable of something like
Dim isSaveAs As Boolean = False
in the module, then inApplication.PresentationBeforeSave
set it toTrue
(unless its argument ofCancel = True
- in that case I would set it back toFalse
). Then in theApplication.PresentationSave
event I would check forIf isSaveAs = True Then DoThis Else DoThat
. Then setisSaveAs
back toFalse
at the end of theApplication.PresentationSave
event.