Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Previous revision | ||
howto:web:serve-html-as-an-excel-file-from-a-web-application [2018-08-05 04:25] |
howto:web:serve-html-as-an-excel-file-from-a-web-application [2020-09-10 13:58] (current) brendan [Serve HTML as an Excel File from a Web Application] |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~META: | ||
+ | creator = Brendan Kidwell | ||
+ | &date created = 2008-01-10 | ||
+ | &date updated = 2014-08-30 | ||
+ | ~~ | ||
+ | {{tag> | ||
+ | ~~DISCUSSION~~ | ||
+ | ====== Serve HTML as an Excel File from a Web Application ====== | ||
+ | |||
+ | It is possible to store HTML in a file named <wrap file> | ||
+ | |||
+ | * Output the spreadsheet as almost plain HTML, allowing for easy programming | ||
+ | * Use the Freeze Panes feature to freeze header rows and/or columns | ||
+ | * Use merged cells | ||
+ | * Include line breaks in cells | ||
+ | |||
+ | //Please note: The solution on this page shows you how to put HTML-encoded data in an <wrap file> | ||
+ | |||
+ | //This is a quick-and-dirty way to get a table from your web app into Excel without an external library and without a lot of coding. Past comments about these deficiencies in the solution provided here have been deleted and future comments along those lines will be deleted.// | ||
+ | |||
+ | If you don't like this solution, search for libraries and articles about writing valid <wrap file> | ||
+ | |||
+ | ===== Skeleton ===== | ||
+ | |||
+ | Create a new file with the <wrap file> | ||
+ | |||
+ | <file xml example.xls> | ||
+ | <html xmlns: | ||
+ | xmlns: | ||
+ | xmlns=" | ||
+ | |||
+ | < | ||
+ | <meta http-equiv=Content-Type content=" | ||
+ | <meta name=ProgId content=Excel.Sheet> | ||
+ | <meta name=Generator content=" | ||
+ | |||
+ | <!--[if gte mso 9]>< | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | ... | ||
+ | </tr> | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | ... | ||
+ | </tr> | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | If you are **not** using the Freeze Panes feature, omit the six lines from ''< | ||
+ | |||
+ | ===== Making the File Available on the Web Server ===== | ||
+ | |||
+ | If the file is stored statically on the web server, make sure the server is configured to send the correct MIME type for the <wrap file> | ||
+ | |||
+ | If you are generating the file dynamically as the output of a script, make sure to send this MIME type in the HTTP headers before your script outputs the body of the file. Also you should include the '' | ||
+ | |||
+ | < | ||
+ | Content-Type: | ||
+ | Content-Disposition: | ||
+ | </ | ||
+ | ===== Styling Cells ===== | ||
+ | |||
+ | Table header cells and data cells get certain default formatting (header: bold centered; data: normal left aligned). To add additional formatting, use the usual HTML tags like " | ||
+ | |||
+ | To add a **line break** within a cell, use this code: | ||
+ | |||
+ | <code xml> | ||
+ | <br style=" | ||
+ | </ | ||
+ | |||
+ | To **merge cells** together, do it as you normally would in an HTML table. Don't forget to include and omit the appropriate cells later in the row and in succeeding rows. For example, this code puts three cells in the a 2×2 block of cells: | ||
+ | |||
+ | <code xml> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | ===== Example File ===== | ||
+ | |||
+ | Here is an example file to play with: {{: | ||
+ | |||
+ | Screenshot: | ||
+ | |||
+ | {{: | ||