通过wpf桌面应用程序打开Excel文档(受保护的视图),将显示错误消息 [英] Opening Excel document(protected View) through wpf desktop application , error message is displayed

查看:236
本文介绍了通过wpf桌面应用程序打开Excel文档(受保护的视图),将显示错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

打开Excel文档(受保护的视图)通过wpf桌面应用程序,显示错误消息

 

如果我们尝试选择受保护的Excel文件应用程序将变得无法响应。并在桌面上显示以下错误消息。

"您正试图打开一个您信任中心的文件阻止设置阻止的文件类型"

  ;

注意: - 通过保存excel工作簿(受保护的视图)具有保存类型的Excel: - 带标题的Excel。

这将创建excel工作簿,其中
受保护的视图

 

供参考 我们附加了一个示例wpf应用程序,其中包含打开excel文档的代码,我们还附上​​了我们面临问题的excel表格

https://1drv.ms/f/s!ApdSFjPuSsmGa1ZMpZGBkgX_XFA

https://1drv.ms/f/s!ApdSFjPuSsmGa1ZMpZGBkgX_XFA

任何人都可以请告诉我们如何确定Excel是否处于"受保护的视图"状态。通过
C#应用程序。

< span style ="margin:0px; font-family:'Calibri','sans-serif'; font-size:11pt">谢谢。

Thanks.




DotNetTeamX

DotNetTeamX

推荐答案



嗨  DotNetTeamX,



>>任何人都可以告诉我们如何确定是否Excel位于"受保护的视图"中。通过C#应用程序。



据我所知,没有这样的API我们可以确定Excel是否是在"受保护的视图"中。
$


解决此问题的最简单,最安全的方法是,单击"基于每个文档启用编辑"按钮,当您打开已下载的Excel(或其他Microsoft Office)文件时。



或者,您可以选择在Excel中禁用受保护的视图功能,这样就不会打开任何已下载的Excel文件时,会收到更长时间的警告。
在Excel中转​​到文件>选项>信托中心>信任中心设置>受保护的视图,然后取消选中"启用受保护的视图" 来源于互联网的文件



或者您可以使用OLEDB连接在WPF .NET应用程序中执行创建,读取和更新操作。因此,必须在计算机中安装用于数据连接的Office System驱动程序。然后,当发生错误时,请提示用户。



参考:
读取,写入和更新Excel WPF中的文件

$


你也可以参考一些第三方图书馆,你可以看看以下内容:



ExcelDataReader
:用C#编写的轻量级快速库,用于读取Microsoft Excel文件



Spire.XLS for .NET。
$


Spire.XLS for。 NET是一个专业的Excel .NET组件,可用于任何类型o f .NET 2.0,3.5,4.0或4.5框架应用程序,ASP.NET网站和Windows窗体应用程序。 Spire.XLS for .NET提供了对象模型Excel API,用于在.NET平台中加速
Excel编程 - 从模板创建新的Excel文档,编辑现有的Excel文档并转换Excel文件。



注意:此响应包含对第三方万维网站点的引用。 Microsoft提供此信息是为了方便您。 Microsoft不控制这些网站,也未测试在这些网站上找到的任何软件或信息;因此,
Microsoft不能就其中发现的任何软件或信息的质量,安全性或适用性做出任何陈述。使用互联网上的任何软件都存在固有的危险,微软提醒您在从互联网上检索任何软件之前确保您完全了解风险。 



最好的问候,



Yong Lu

Hi  DotNetTeamX,

>>Can anyone please let us know how to determine whether the Excel is in "Protected View" through C# application.

As far as I know, there no such API that we can determine whether the Excel is in "Protected View".

The simplest and most secure method to get around this issue is to simply click the Enable Editing button, on a per-document basis, when you open an Excel (or other Microsoft office) file that has been downloaded.

Alternatively, you can choose to disable the Protected View feature within Excel so that you no longer receive the warning upon opening any Excel file that has been downloaded. In Excel go to File > Options > Trust Center > Trust Center Settings > Protected View, and then uncheck Enabled Protected View for files originating from the Internet

or you can use the OLEDB connection to do the Create, Read and Update operations in a WPF .NET application. So the Office System Driver for Data Connectivity must be installed in the machine. Then, When an error occurs, please prompt the user.

Reference: Read, Write and Update an Excel File in WPF

You can also refer some third party libraries, you can take a look at the following:

ExcelDataReader : Lightweight and fast library written in C# for reading Microsoft Excel files

Spire.XLS for .NET.

Spire.XLS for .NET is a professional Excel .NET component that can be used to any type of .NET 2.0, 3.5, 4.0 or 4.5 framework application, both ASP.NET web sites and Windows Forms application. Spire.XLS for .NET offers object model Excel API for speeding up Excel programming in .NET platform - create new Excel documents from template, edit existing Excel documents and convert Excel files.

Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 

Best Regards,

Yong Lu


这篇关于通过wpf桌面应用程序打开Excel文档(受保护的视图),将显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆