2017-04-19 88 views
0

我使用ClosedXML導出Excel文件,我似乎無法導出Excel文件。每次點擊按鈕導出Excel文件(XLSX)時,都會出現錯誤。見下面...ClosedXML拋出:SecurityException:請求的註冊表訪問不允許

​​

我得到此錯誤:SecurityException:請求的註冊表訪問不被允許。

Exception thrown: 'System.TypeInitializationException' in WindowsBase.dll 
System.TypeInitializationException: The type initializer for 
'MS.Utility.EventTrace' threw an exception. ---> 
System.Security.SecurityException: Requested registry access is not allowed. 
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) 
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) 
at Microsoft.Win32.RegistryKey.OpenSubKey(String name) 
at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, 
Object defaultValue) 
at MS.Utility.EventTrace.IsClassicETWRegistryEnabled() 
at MS.Utility.EventTrace..cctor() 
--- End of inner exception stack trace --- 
at MS.Utility.EventTrace.EasyTraceEvent(Keyword keywords, Event eventID) 
at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, 
FileAccess packageAccess, Boolean streaming) 
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.CreateCore(Stream stream) 
at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Create(Stream 
stream, SpreadsheetDocumentType type, Boolean autoSave) 
at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Create(Stream 
stream, SpreadsheetDocumentType type) 
at ClosedXML.Excel.XLWorkbook.CreatePackage(Stream stream, Boolean 
newStream, SpreadsheetDocumentType spreadsheetDocumentType, Boolean 
validate) in C:\Git\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 111 
at ClosedXML.Excel.XLWorkbook.SaveAs(Stream stream, Boolean validate) in 
C:\Git\ClosedXML\ClosedXML\Excel\XLWorkbook.cs:line 547 
at ExcelHelper.ToExcel(DataSet dsInput, String sFileName, HttpResponse 
Response) in c:\inetpub\wwwroot\Felbro_B\App_Code\ExcelHelper.cs:line 139 

回答

1

我通過從Web.Config文件中刪除標識impersonate =「true」來解決該問題。

+0

您還可以接受你自己的答案,以便其他人可以看到,問題解決了。 –

+0

也許評論說問題不是'ClosedXML'相關。 –

相關問題