473,734 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18795
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.Applicati on')
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.FileS ystemObject (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**********@c omcast.net> wrote in message
news:03******** *************** *********@4ax.c om...
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**********@c omcast.net> wrote in message
news:fn******** *************** *********@4ax.c om...
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="yourf ile.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*****@agrico reunited.com>
comp.lang.javas cript 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*****@agrico reunited.com> wrote:
"Martin" <ma**********@c omcast.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="yourf ile.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
12496
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 code samples? Thanks for your help!
0
41180
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 an excel document which the user can see (at this stage of development) and passed some data to it. I then used the savas method to save the file. Again this seems to work as the file is created. However once I close the excel file and try and...
2
1654
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 System.IO.StringWriter(); ......
0
1528
by: sanjaygbadak | last post by:
How can I create excel file without using references.
0
3944
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 string as: ------------------------------------------------------------------------------------------------ Dim fileNameXL As String = "_MYEXCEL_REPORTS.XLS" Dim pathNameXL As String = "\EXCEL_TEMP\"
4
24096
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
1655
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 only after a random length period of time. If I use the code in the discussion "ADOX in Office XP??" I get the same result. My code is very similar to that. Some programming languages have a method to flush the output buffer and close the file,...
7
5602
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 without using Spreadsheet::WriteExcel?
2
2869
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 code: public static void Convert( DataSet ds) { System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.IO.TextWriter txtWriter = stringWrite; HttpResponse response = new...
1
1953
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 existing excel file its throwing error. ERROR: Syntax error in INSERT INTO string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FEB_LOG.xls;Extended Properties='Excel 8.0;HDR=YES;'"; OleDbConnection objConn = new...
0
8783
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9458
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9248
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,...
1
6743
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
6040
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
4555
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...
0
4818
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2184
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.