c# - 当我从 Web 打开 Excel 文档时,无法重新调整 Excel 的 ctrl+s 事件的用途
问题描述
我使用以下代码从 web url 打开一个 excel 文档:
<a href="ms-excel:ofe|u|https://www.example.com/test.xlsx">Open with excel</a>
一个空的 excel 书被成功打开。根据我的 excel vsto 项目的场景,文档必须保存在我们的云中,而不是用户的电脑中。因此,我重新利用了 excel 的保存事件,创建了一个名为 CustomSave 的方法,并在其中编写了我的上传代码。
我的功能区和 c# 代码如下所示:
MainRibbon.xml
<commands>
<command idMso="ThemeSaveCurrent" onAction="CustomSave"/>
<command idMso="FileSaveAsExcelXlsb" onAction="CustomSave"/>
<command idMso="ChartSaveTemplates" onAction="CustomSave"/>
<command idMso="WindowSaveWorkspace" onAction="CustomSave"/>
<command idMso="FileSaveACopy" onAction="CustomSave"/>
<command idMso="FileSave" onAction="CustomSave" />
<command idMso="FileSaveAs" onAction="CustomSave" />
<command idMso="FileSaveAsMenu" onAction="CustomSave" />
<command idMso="FileSaveAsExcelXlsx" onAction="CustomSave" />
<command idMso="FileSaveAsExcelXlsb" onAction="CustomSave" />
<command idMso="FileSaveAsExcel97_2003" onAction="CustomSave" />
<command idMso="FileSaveAsOtherFormats" onAction="CustomSave"/>
</commands>
MainRibbon.cs
public void CustomSave(IRibbonControl control, bool cancelDefault)
{
MyUploadMethod(); //Method which uploads current document to the cloud.
cancelDefault = false;
}
我还添加了 WorkbookBeforeSave 方法:
ThisAddIn.cs
private void WorkbookBeforeSave(Excel.Workbook workbook, bool SaveAsUI,ref bool Cancel)
{
Cancel = true;
SaveAsUI = false;
MyUploadMethod(); //Method which uploads current document to the cloud.
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.WorkbookBeforeSave += WorkbookBeforeSave;
}
尽管我的 CustomSave 方法按预期拦截了 excel 中的所有保存事件,但是当我从键盘按 ctrl+s 时,它不会进入 CustomSave 方法或 WorkbookBeforeSave 方法。当我单击 ctrl+s 键时,我收到以下警告:
我对 word 和 power point 做了同样的事情,没有问题,但对 excel 却做不到。顺便说一句,当我从 Web 打开文档时,文档状态始终变为只读,除非我将其保存在本地,否则它的状态不会改变。如果不保存在本地,我无法将文档直接上传到云端。但我不想将文档保存到本地电脑。如果您对我的问题有任何建议,我会很高兴。
解决方案
推荐阅读
- python - weblogic wlst 控制台不显示环境变量的完整列表
- javascript - 在 VueJS 中使用 Axios - 这个未定义
- sql - 在oracle中使用正则表达式提取子字符串
- python - chrome 历史数据库访问被锁定
- angular - 如何为 ngx-treeview 提供占位符。有财产吗?
- javascript - 构造一个结构复杂的Javascript对象?
- sql-server - 禁用自动客户端故障转移
- r - 多条 ggplot2 图表中的排序图例
- sql-server - 如何在项目代码=的发票表中选择最后一个价格?和客户=?
- python - (Python) 删除文件名中的连续空格;留一个空格