473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Create Excel spreadsheet from Javascript

I'd like to create/display an Excel spreadsheet from javascript. We
have an HTML page with results of a search and it can be reasonably
large.

The first attempt was to format the data into an HTML table and send
it to an ASP page. The ASP page has:
Response.AddHeader ("Content-Disposition", "inline");
Response.ContentType = "application/vnd.ms-excel");
Response.Write(formatted_html_data);

Works fine until there's more than 100K bytes of data. It then hits
an ASP limit and blows chunks.

Second attempt: Do it all on the client side in Javascript. A
variable has the HTML:

<html>
<head>
<meta http-equiv="Content-Type" CONTENT="application/vnd.ms-excel">
<meta http-equiv="Content-Disposition" CONTENT="inline">
</head>
<body>
<table>
....html-formatted data...
</table></body></html>

We send the data to a new window:
var newWin = window.open('','','width=300,height=300');
newWin.document.write(variable_with_html);
newWin.document.close()

The window pops up, html-formatted data displays in it, but Excel
doesn't run.

What's the difference between the first method and the second? Both
send 'stuff' to the browser that it will interpret.

Are the <meta> tags wrong? It's the only thing I can think of, since
one is generated by ASP (and it works) and the other by me (doesn't
work).

Thanks,
Jim
Jul 20 '05 #1
1 47710
Jim, N2VX wrote:
I'd like to create/display an Excel spreadsheet from javascript. We
have an HTML page with results of a search and it can be reasonably
large.

The first attempt was to format the data into an HTML table and send
it to an ASP page. The ASP page has:
Response.AddHeader ("Content-Disposition", "inline");
Response.ContentType = "application/vnd.ms-excel");
Response.Write(formatted_html_data);

Works fine until there's more than 100K bytes of data. It then hits
an ASP limit and blows chunks.
Try NOT building up a HUGE string before you write to the Response
object. Have a function which outputs the Excel data to the Response
rather than one which creates a huge string.

HINT: You can create proper, functional Excel Spreadsheets by sending a
correctly formatted XML spreadsheet with that ContentType. See

http://msdn.microsoft.com/library/de.../odc_xmlss.asp

It's finicky about the XML formatting, but once you get it right, you
can get some really nice spreadsheets out. Persevere with this approach.

This is the way to go, you cannot generate a spreadsheet in javascript.
Second attempt: Do it all on the client side in Javascript. A
variable has the HTML:

<html>
<head>
<meta http-equiv="Content-Type" CONTENT="application/vnd.ms-excel">
<meta http-equiv="Content-Disposition" CONTENT="inline">
</head>
<body>
<table>
...html-formatted data...
</table></body></html>

We send the data to a new window:
var newWin = window.open('','','width=300,height=300');
newWin.document.write(variable_with_html);
newWin.document.close()

The window pops up, html-formatted data displays in it, but Excel
doesn't run.


No, it won't suddenly fire up Excel. You are writing data into an HTML
document in the browser. That's what document.write() does. Once you are
IN a document, it makes no difference what data you write into it - it's
an HTML DOCUMENT!

The previous method used the HTTP standard (Do a google on it) to inform
the browser what kind of data was coming back from the server. You
correctly informed the browser that Excel data was coming back
(ContentType = "application/vnd.ms-excel"), so the browser offers to run
the application (or save the output).

Hope this helps.

Nige

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Phil Powell | last post by:
What would one best recommend to parse an existing Excel spreadsheet (was done in Excel 97 or 2000 not sure to be honest)? I am looking for the most practical way of parsing an existing...
2
by: quadric | last post by:
Hi, I have an application that requires that Python initiate and mediate a live and iterative conversation between an external application (in which Python is embedded) and an external Excel...
6
by: Mark | last post by:
I've been asked to convert a pay increase spreadsheet to an intranet page. So far I've developed a page that uses a combination of ASP and Javascript to retrieve all of the required information...
3
by: Ken Hall | last post by:
Is it possible to create an Excel spreadsheet using VB.NET without opening the Excel application or having to have the Excel application on the operating computer? KH
3
by: Scott M. Lyon | last post by:
I'm trying to figure out a way to export data (actually the result of a Stored Procedure call from SQL Server) into a specified Excel spreadsheet format. Currently, I have the data read into a...
4
by: PeterW | last post by:
Hello. Is it possible, using code, to create a spreadsheet in excel format, with cells containing constant text and formulae and inserting data from a recordset in specific cells? If so,...
0
by: eolmos | last post by:
Hello everyone, I am currently working on a project that requires a webform in asp.net using C# as the code behind. The page must allow the user to create a report in excel. This report must also...
1
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
4
by: zacks | last post by:
I have an application that can read an Excel spreadsheet on a computer that doesn't have Excel installed on using the Jet ODBC 4.0 driver. I know need to modify the application to also be able to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.