Click here to Skip to main content
16,017,351 members

Comments by MaureenMcDuffie (Top 2 by date)

MaureenMcDuffie 18-Jun-15 4:32am View    
Well you can try this Excel's tool for .NET Framework that I've been using for some time now. Its a quite straightforward, all you have to do in order to convert an excel file into a pdf file with C# code is the following:
ExcelFile.Load("Input.xlsx").Save("Output.pdf");
I've been using this on my windows service which runs every day and converts every spreadsheet type file (so .csv, .xls and .xlsx) into a PDF and uploads it to our repo.
MaureenMcDuffie 18-Jun-15 4:22am View    
You cannot export the GridView into an existing excel file with HtmlTextWriter. The only thing that you can do with it is export the HTML content of the GridView control into a new file which then you can name it with .xls extension. This is a known workaround which is useful in some cases and it works because most of the Excel applications (including MS Excel) will be able to open this file.

But in order to add a new sheet to an existing excel file you will have to go with some other approach. Unfortunately the Philippe's suggestion (using OpenXML SDK) will not suite you because that is able to manipulate with only .xlsx.
So instead take a look at this[^] article. That sample demonstrates how after using the HtmlTextWriter you can convert that HTML content into an excel file in C#.
Also take a look at how you can read the existing excel (both .xls and .xlsx) files in C#.
Note that both samples use the same C# library for manipulating with excel files.