- Home
- Forum
- ASP.NET Core - EJ 2
- ExcelToPdfConverter is inaccessible due to its protection level
ExcelToPdfConverter is inaccessible due to its protection level
NOTE: I could not find the XL control in the dropdown above, and it wouldn't let me continue without selecting one, so I chose PDF Viewer, even though that's not the right one.
I've used NuGet to install XLIO and renderer.
I was able to create the workbook and download it per your example code.
But I want to convert the workbook to a pdf and download that instead.
When I type ExcelToPdfConverter, I get an error:
ExcelToPdfConverter is inaccessible due to its protection level
What am I missing?
I poked around and experimented and I now think your documentation for Blazor XL is inaccurate and incomplete -- or at least the sample code is wrong (maybe outdated?)/
Here's what worked for me:
//Save the document as a stream and return the stream.
XlsIORenderer renderer = new();
PdfDocument pdfDoc = new();
pdfDoc = renderer.ConvertToPDF(worksheet);
using ( MemoryStream stream = new MemoryStream() )
{
//Save the created Excel document to MemoryStream
//workbook.SaveAs(stream); // to save and download as Excel
pdfDoc.Save(stream);
return stream;
}
- You must have installed Syncfusion.XlsIORenderer.Net.Core NuGet package, which is a .NET Standard NuGet package into your .NET Standard application but using ExcelToPdfConverter class, which is available in only .NET Framework.
- This causes compilation issue in your .NET Standard application.
- ExcelToPdfConverter class is named as XlsIORenderer in .NET Standard and hence XlsIORenderer class should be used in .NET Standard applications.
So, I guess I'm confused. My app is a Net Core app, so did I install the right NuGet packages?
I couldn't find anything in the documentation that explained the need for different code when in Core. The end result in my project is fantastic, but I gotta say it was a pretty frustrating experience figuring out how to make it work with the sample code and documentation.
- If you are using WindowsForms or WPF you can use the code snippet provided under C# tab.
- Similarly for UWP application you can use the code snippet provided under UWP tab.
- Code snippet provided under ASP.NET Core tab should be used for ASP.NET Core application and code snippet provided under Xamarin tab should be used for Xamarin application.
- 4 Replies
- 2 Participants
-
KA Keith A Price
- Jul 28, 2021 07:00 PM UTC
- Jul 30, 2021 06:35 AM UTC