我使用ClosedXML导出Excel文件,我似乎无法导出Excel文件.每次我点击按钮导出Excel文件(XLSX)我都会收到一个错误.见下文...
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dsInput);
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=" + sFileName + ".xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream, false);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误: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) …Run Code Online (Sandbox Code Playgroud)