473,769 Members | 6,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.AddHea der ("Content-Disposition", "inline");
Response.Conten tType = "applicatio n/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="applic ation/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,h eight=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 47748
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.AddHea der ("Content-Disposition", "inline");
Response.Conten tType = "applicatio n/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="applic ation/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,h eight=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 = "applicatio n/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
8560
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 spreadsheet to place contents into a mySQL db. Thanx, Phil PS: can you use fopen() to read the contents and parse? The spreadsheet is on a remote site.
2
2117
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 spreadsheet. Python will have to pass info to the spreadsheet, spreadsheet will make calculations, Python will obtain results and pass back to application, application will evaluate results of spreadsheet calculations and create new set of data and
6
6370
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 from the HR database. The problem is that I need to be able to calculate the new salary based on an increase_amount field, as well as maintain a running total of the increase amounts. Once the amounts have been determined, I then need to submit...
3
2549
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
11689
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 DataSet that consists of one DataTable. That DataTable has a specific name (for arguments purposes, let's say it's called "DataGrid"), that I need to use as the tab name in the exported Excel
4
8140
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, could someone point me to an information page with details on how to achieve this? Many thanks
0
2176
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 generate a chart based on the input dataset. (By the way, the component must be free) So far, I have tried a lot of components which are really good but they do not provide all the required functionality altogether and some of them have trade offs when...
1
3044
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 report. I always get when trying to test it " 500 Internal Server Error - The server encountered an internal error or misconfiguration and was unable to complete your request." Can somebody help me please.
4
1920
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 create a new Excel spreadsheet and write data to it on the same computer, a computer that does not have Excel, or even Office installed. I have done some research on this and it appears it cannot be done. Can anyone verify that or better...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.