ASP.NET, Excel, Excel 2003, Excel 2007, Excel 2010, Programming, Software, Web Development

Generating Excel documents through HTML, XML, and CSS – Part 1

I recently had the requirement to take the HTML from a batch of reports on a Web application and output these with very specific formatting requirements to Excel. I am familiar with the basic syntax of setting the content type to ‘application/ms-excel’ before streaming  the HTML content. However things get rapidly more complex if the requirements include actually setting presets in Excel.

I’m surprised at how little documentation there is for how to do this online although everyone has a need to do it. The lack of information from the Microsoft official articles is also quite amazing. Basically the developer is left to their own devices when writing code to create spreadsheets dynamically through HTML, XML, and CSS.

The most helpful information I was able to find was at the following sites: Continue reading “Generating Excel documents through HTML, XML, and CSS – Part 1”

Advertisement
ASP.NET, Excel, Excel 2003, Excel 2007, Excel 2010, Programming, Software, Web Development

ASP.NET Export to Excel: Set the Default Print Paper Size Programmatically

I’ve been working on adding the ability to export to Excel format to reports that I have written in ASP.NET. While doing this I have received numerous feature requests including the ability to set by default the paper size to be printed to.

As a little bit of background on the topic: I use a traditional method of streaming the HTML version of the report to the browser with the content type set to MS Excel. This allows me to send Excel-specific markup to format parts of the Excel document.

One can set the default page settings for an Excel document using the Microsoft Excel XML Spreadsheet model (SpreadsheetML). Specifically, the XML hierarchy is:

<x:ExcelWorkbook>
 <x:ExcelWorksheets>
  <x:ExcelWorksheet>
   <x:WorksheetOptions>
    <x:Print>
     <x:PaperSizeIndex>

Although documentation exists on the Microsoft Excel XML Spreadsheet model, I have not actually seen any detailed description on the options available when setting the page sizes. Since these are simply numeric values their meaning is not immediately apparent to me so I have been testing what each value means by trial and error. Continue reading “ASP.NET Export to Excel: Set the Default Print Paper Size Programmatically”