1

I am given to understand that there are ways to generate Excel files from Classic ASP, by means of basically making an HTML table and calling it a spreadsheet. The output, however, doesn't seem to be quite what I'm looking for -- when opened in Excel, it looks like an HTML page with a table instead of a normal spreadsheet. So I'm not sure I want to go with that, though I'm open to being sold on the possibility.

Due to reasons, I'm working with a website that runs ASP Classic using JavaScript, which appears to have been very uncommon even back when ASP Classic was cutting-edge. I understand there are also means of generating Excel files in JavaScript, but they seem to be for more typical environments like a browser or Node.js; I think #include only works with other ASP files.

I would just output a CSV file, except that I have to be able to include images in the spreadsheet.

Community
  • 1
  • 1
Shay Guy
  • 1,010
  • 1
  • 10
  • 21

3 Answers3

0

The html table method works well if the table tag is the only tag in the body of the html, and you don't have any specific styling for the table cells that will conflict with what Excel would normally do.

What you might consider is something called SpreadsheetML, which is an xml schema that Excel will understand for defining a spreadsheet. This is different than the xml format used for the newer Office documents. Take a look here for an example:

Generating an Excel file in ASP.NET

Also, the accepted answer in that same question will cover some of your other options. It's targeted for ASP.Net rather than classic ASP, but a lot of the material still applies.

Community
  • 1
  • 1
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Like I said, I've tried the HTML method, without other tags or any styling at all, and it doesn't exactly "open it as if it were a native document." There's still an error message when it opens, along with the blank white background in place of the usual grid and the "shrink-wrapped" column widths and row heights. – Shay Guy Jan 27 '14 at 22:48
  • Can you include images in SpreadsheetML? I tried pasting an image into a new spreadsheet and saving as XML Spreadsheet 2003, and the image wasn't saved. My intuition likewise suggests a plain-text format like XML wouldn't support images. – Shay Guy Jan 28 '14 at 00:50
  • You can refer to images elsewhere on the file system :/ – Joel Coehoorn Jan 28 '14 at 16:39
0

If you were using VBScript ASP then you would simply need to add the following lines, before your opening <table> tag

<%
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=yourspreadsheetname.xls"
%>

To convert these two lines into server side JS I think it would just be a case of adding a semicolon at the end of each line.

John
  • 4,658
  • 2
  • 14
  • 23
  • This is the method I referred to earlier; I actually haven't tried it *without* those lines. It doesn't solve the problems I've mentioned. – Shay Guy Jan 27 '14 at 23:26
  • If Excel is installed on your server look at this - http://www.4guysfromrolla.com/webtech/022801-1.shtml - It's VBS, but you can have VBS and JS ASP files side by side – John Jan 27 '14 at 23:35
0

Javascript runs on the browser, so it doesn´t matter if your backend is Classic ASP or any other.

As of Excel 2007+ the XLSX format is just a ZIP containing a set of XML files following the [Office Open XML specification][1].

This can definetely been done in JavaScript, and there are a bunch of libraries that provide this functionality. Just Google them.

jsegarra
  • 101
  • 2
  • 3