I want to silently print Excel files via a C# console application. However, when attempting to follow this example program to silently print Excel files in C# I get an error message like the one shown in the attached image.
Hi! Which framework are you targeting? If it’s .NET you need to use the Windows specific TFM like net8.0-windows to be able to use printing. You can find more information here: Supported Platforms | GemBox.Spreadsheet
Thanks for letting me know. Since you said .NET 6.0 and above, I assume that GemBox will work on .NET 8.0 then? I just upgraded to using Visual Studio 2022 with .NET 8.0 and will be doing some testing of it in the coming days.
Unfortunately, it doesn’t seem to be working for me. I’m using .NET 8.0 with Visual Studio 2022 and I get the same error message. Keep in mind that this is a console application so maybe that sample code won’t work with a console app:
That solved my issue; thank you for the assistance. However, now I have another issue which is that nothing prints when the program runs. Meaning the sample program I was using:
I set the printer name to a network printer and made sure that the file being loaded exists. Nothing prints. If I change the printer name to a printer name that doesn’t exist, I get an error message which is good. However, nothing happens when I have it set to a printer that exists. The program just finishes running and nothing prints.
Unfortunately, I was unable to reproduce this issue.
Can you try using a different printer, perhaps a local printer?
Also, can you try using a virtual printer (for example, “Microsoft Print to PDF”)?
I tried using a different network printer and that didn’t work. However, Microsoft Print to PDF did work. Unfortunately, I need the document to actually print rather than just saving it as a PDF.
I’m happy to report that I was able to get the sample code to work. I had previously added content to a single cell in the Excel file that I was using to test on. Once I replaced that with a file that had more content, the page printed out.
However, the row numbers are included on the printed page. I didn’t see an option in the worksheet PrintOptions to remove those. It makes the printed page look uglier. Do you happen to know how to remove them?