473,387 Members | 1,374 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,387 software developers and data experts.

Create an Excel file with Javascript?

I have a situation where I'm displaying some information in a table on
a web page. I've given the user the ability to make several different
"queries" and show different sub-sets of the data.

I would like to add a button to the page that would allow the user to
create an .XLS file that would contain the current contents of the
table. I realize that I could create it on the server and allow him to
download it but I'd rather let him create it right there on his
machine. Is it possible to have a script that can do such a thing?

Obviously, I do not want to rely on there being any specific
Excel-related software installed on the user's machine.
Jul 23 '05 #1
7 18775
Martin wrote:
[...]
I would like to add a button to the page that would allow the user to
create an .XLS file that would contain the current contents of the
table. I realize that I could create it on the server and allow him to
download it but I'd rather let him create it right there on his
machine. Is it possible to have a script that can do such a thing?


Javascript in web pages can't access the file system, so I'd say probably
not.

There are a number of evil platform-specific ways of getting around this,
but they're all evil (LiveConnect, aaah!) or platform-specific (ActiveX,
aaaah!).

Possibly your best bet is to send the information to a CGI script somewhere
that creates the Excel file and makes it available for download; it
wouldn't be particularly difficult, and would move the nasty
creating-the-binary bit out of the Javascript domain.

--
+- David Given --McQ-+ "Feminism encourages women to leave their
| dg@cowlark.com | husbands, kill their children, practice withcraft,
| (dg@tao-group.com) | destroy capitalism and become lesbians." --- Rev.
+- www.cowlark.com --+ Pat Robertson

Jul 23 '05 #2


Martin wrote:

I would like to add a button to the page that would allow the user to
create an .XLS file that would contain the current contents of the
table. I realize that I could create it on the server and allow him to
download it but I'd rather let him create it right there on his
machine. Is it possible to have a script that can do such a thing?


Not really, a web page in general even if there are ways exposed to
script such as
new ActiveXObject('Excel.Application')
in IE/Win doesn't have the rights to do such things.
You might be able to used signed scripts with Mozilla/Netscape to
request privileges for file access but there is certainly no support
then to create an Excel file from the HTML DOM.
With IE/Win if someone is willing to consider your web site as trusted
then file access might be possible with Scripting.FileSystemObject (but
that is geared towards text files) and if Excel is around then you could
instantiate it.
But in general if you know how to create Excel on the server and have
the possibilities on the server of your site then do it on the server.

Or I guess if the browser user simply copies the table and pastes into
Excel it might work out.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3
"Martin" <ma**********@comcast.net> wrote in message
news:03********************************@4ax.com...
I have a situation where I'm displaying some information in a table on
a web page. I've given the user the ability to make several different
"queries" and show different sub-sets of the data.

I would like to add a button to the page that would allow the user to
create an .XLS file that would contain the current contents of the
table. I realize that I could create it on the server and allow him to
download it but I'd rather let him create it right there on his
machine. Is it possible to have a script that can do such a thing?

Obviously, I do not want to rely on there being any specific
Excel-related software installed on the user's machine.


You might offer the user an option to generate a CSV file which is displayed
as a Web page with instructions to save it with a CSV extension then to
double-click on it to open it in MS-Excel (if present) then to save that
with an XLS extension. Of course you could use FSO to do (most of) the
above (with the attendant security warnings).
Jul 23 '05 #4
In article <iu***************@newsfe1-win.ntli.net>,
David Given <dg@cowlark.com> wrote:
Martin wrote:
Possibly your best bet is to send the information to a CGI script somewhere
that creates the Excel file and makes it available for download; it
wouldn't be particularly difficult, and would move the nasty
creating-the-binary bit out of the Javascript domain.


Expanding on this idea. You could have a form when submitted would
upload the table to the server. The server could generate the excel
file and send the excel file as the response to the client. On windows
IE with excel, the page would open in Excel. Otherwise, it would most
likely be saved on disk.

You have a fast link and not that much data, the user will hardly notice.

(( Oh, I guess you wanted to do it on the client. ))

Robert
Jul 23 '05 #5
I have this working now - when the user clicks the provided link, I
generate the .XLS file on the server and send it out. The problem I
have now is, depending on the client's setup, the .XLS file is opening
up and displaying in the user's browser. Most of the time, this is not
what the user will want to do - he's downloading to save it for future
reference.

On one of my test machines, a dialog pops up asking if I want to open
the file or save it. Can someone tell me if there is a way for me to
force this dialog to pop-up ?

Thanks
On Fri, 21 Jan 2005 14:39:10 GMT, David Given <dg@cowlark.com> wrote:
Martin wrote:
[...]
I would like to add a button to the page that would allow the user to
create an .XLS file that would contain the current contents of the
table. I realize that I could create it on the server and allow him to
download it but I'd rather let him create it right there on his
machine. Is it possible to have a script that can do such a thing?


Javascript in web pages can't access the file system, so I'd say probably
not.

There are a number of evil platform-specific ways of getting around this,
but they're all evil (LiveConnect, aaah!) or platform-specific (ActiveX,
aaaah!).

Possibly your best bet is to send the information to a CGI script somewhere
that creates the Excel file and makes it available for download; it
wouldn't be particularly difficult, and would move the nasty
creating-the-binary bit out of the Javascript domain.


Jul 23 '05 #6
"Martin" <ma**********@comcast.net> wrote in message
news:fn********************************@4ax.com...
I have this working now - when the user clicks the provided link, I
generate the .XLS file on the server and send it out. The problem I
have now is, depending on the client's setup, the .XLS file is opening
up and displaying in the user's browser. Most of the time, this is not
what the user will want to do - he's downloading to save it for future
reference.

On one of my test machines, a dialog pops up asking if I want to open
the file or save it. Can someone tell me if there is a way for me to
force this dialog to pop-up ?


Yes. Before you send the XLS file from the server, send the following
headers:

Content-Disposition: attachment; filename="yourfile.xls"
Content-type: application/vnd.ms-excel

Most well-behaved browsers (including IE) will prompt the user to save
the file, even if Microsoft Excel is installed on the client system.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7
Grant -

Thanks. That does exactly what I want. And, I would never have figured
it out on my own.

BTW, the client didn't recognize "vnd.ms-excel" but when I changed it
to "xls", it did.

Thanks again.

Martin

On Mon, 24 Jan 2005 21:57:32 GMT, "Grant Wagner"
<gw*****@agricoreunited.com> wrote:
"Martin" <ma**********@comcast.net> wrote in message
news:fn********************************@4ax.com.. .
I have this working now - when the user clicks the provided link, I
generate the .XLS file on the server and send it out. The problem I
have now is, depending on the client's setup, the .XLS file is opening
up and displaying in the user's browser. Most of the time, this is not
what the user will want to do - he's downloading to save it for future
reference.

On one of my test machines, a dialog pops up asking if I want to open
the file or save it. Can someone tell me if there is a way for me to
force this dialog to pop-up ?


Yes. Before you send the XLS file from the server, send the following
headers:

Content-Disposition: attachment; filename="yourfile.xls"
Content-type: application/vnd.ms-excel

Most well-behaved browsers (including IE) will prompt the user to save
the file, even if Microsoft Excel is installed on the client system.


Jul 23 '05 #8

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

Similar topics

2
by: Cathy | last post by:
Hi All, Can anyone tell me how to create an Excel (.xls) file from a VB.Net app? I have a SQL Server database that contains a table with the data I want to export. How do I create the file? Any...
0
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created...
2
by: TJ | last post by:
Hi, Basically, I want to create excel file on the fly, then force users to download it without using automation. Here is one of ways.. System.IO.StringWriter sw = new...
0
by: sanjaygbadak | last post by:
How can I create excel file without using references.
0
by: =?Utf-8?B?Tml5YXpp?= | last post by:
Hi all, Does anyone know how to embed the Excel file in VB.NET 2005 Resources? Here is what I am doing at the moment: 1) In my VB.NET 2005 project code I load the excel with it path into...
4
by: Rahul | last post by:
I want to create an excel file for report in asp.net 2.0 ... without having office installed on the server. Rahul
0
by: Paul | last post by:
Hello, I have a VB 6 app that creates Excel files to export data that works fine. When I ported it to VB.NET it creates the file, but seems to finish writing the data and releasing the file...
7
by: rameshvummadi | last post by:
I want to create an excel file (Microsoft Excel) with tabs using perl. I need to run my perl script in the Unix environment. I can do it with Spreadsheet::WriteExcel. Can I create the excel file...
2
by: phanimadhav | last post by:
Hello Experts, I developed following code for excel file creation by using Dataset.But i got the following error(NullRefernec Exception was caught) at the response.End() My...
1
by: farnena | last post by:
I want to create a excel file every month and update details on certain events in a web application. 1. I dunno how to create Excel file in Web environment. 2. When I was trying to update the...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.