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

Open XML in excel with javascript?

I have a spreadsheet saved as an XML spreadsheet so I can manipulate
it easier (and don't need COM). When I'm done, I want to display to
the user. Currently, I'm using simple JavaScript in my PHP file to
display the file when complete:
echo '<script type="text/javascript"window.open("'.$file_nm.'")</
script>';

Since the file is .XML, which defaults to the browser to open - the
above code will display the XML as raw XML (text) in a new browser
window - rather than opening with excel.
In the XML is:
<?mso-application progid="Excel.Sheet"?>
So, if the XML is saved locally - then opened, it will default to
Excel to open.

Is there anyway for the script to indicate that excel should be used
to open, rather than the (default) for XML - which is the browser?

Thanks in advance.
Jan 29 '08 #1
4 11913
On Jan 29, 3:09 pm, JaxDawg <jaxd...@gmail.comwrote:
I have a spreadsheet saved as an XML spreadsheet so I can manipulate
it easier (and don't need COM). When I'm done, I want to display to
the user. Currently, I'm using simple JavaScript in my PHP file to
display the file when complete:
echo '<script type="text/javascript"window.open("'.$file_nm.'")</
script>';

Since the file is .XML, which defaults to the browser to open - the
above code will display the XML as raw XML (text) in a new browser
window - rather than opening with excel.
In the XML is:
<?mso-application progid="Excel.Sheet"?>
So, if the XML is saved locally - then opened, it will default to
Excel to open.

Is there anyway for the script to indicate that excel should be used
to open, rather than the (default) for XML - which is the browser?

Thanks in advance.
Not much to do with javascript but a content type of "application/
vnd.ms-excel" set by the server should do the trick.

A simple python cgi script on server: printxls.pyg

#!/python25/python
import sys
print "Content-type: application/vnd.ms-excel"
print
for line in file("/helloworld.html"): print line

An Excel file saved as extremely simple HTML: helloworld.html

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html;
charset=windows-1252">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 10">
</head>
<body><table><col><tr><td>Hello World!</td></tr></table></body>
</html>

The browser directed to Apache web server: "http://localhost:8080/cgi-
bin/printxls.pyg"

See the link below for a screenshot.

http://www.postyourimage.com/view_im...fUCM1201667857

Let me know if this solves the issue or if I'm way off. :)

-Tom Woz
Jan 30 '08 #2
Interesting... I like the approach... will give it a shot.

Thanks!
Jan 30 '08 #3
JaxDawg wrote:
I have a spreadsheet saved as an XML spreadsheet so I can manipulate
it easier (and don't need COM). *When I'm done, I want to display to
the user. *Currently, I'm using simple JavaScript in my PHP file to
display the file when complete:
* *echo '<script type="text/javascript"window.open("'.$file_nm.'")</
script>';

Since the file is .XML, which defaults to the browser to open - the
above code will display the XML as raw XML (text) in a new browser
window - rather than opening with excel.
In the XML is:
<?mso-application progid="Excel.Sheet"?>
So, if the XML is saved locally - then opened, it will default to
Excel to open.

Is there anyway for the script to indicate that excel should be used
to open, rather than the (default) for XML - which is the browser?
I would do something like this:

1. Perform the xml2xls conversion server-side
2. Rename the .php extension into .xls
3. Make .xls extensions execute as PHP
4. Output binary xls with Excel header

This way you should obtain maximum compatibility with all kinds of
programs that deal with .xls-extensions (and not only the typical
Microsoft workarounds which are often problematic).

I have one question though. You start with xls, then save it as xml,
and then want to open it again as xls at the client machine... why
don't you just store the initial xls-file ? (but maybe I'm missing
something)

--
Bart
Jan 30 '08 #4
On Jan 30, 10:03 am, Bart Van der Donck <b...@nijlen.comwrote:
JaxDawg wrote:
I have a spreadsheet saved as an XML spreadsheet so I can manipulate
it easier (and don't need COM). When I'm done, I want to display to
the user. Currently, I'm using simple JavaScript in my PHP file to
display the file when complete:
echo '<script type="text/javascript"window.open("'.$file_nm.'")</
script>';
Since the file is .XML, which defaults to the browser to open - the
above code will display the XML as raw XML (text) in a new browser
window - rather than opening with excel.
In the XML is:
<?mso-application progid="Excel.Sheet"?>
So, if the XML is saved locally - then opened, it will default to
Excel to open.
Is there anyway for the script to indicate that excel should be used
to open, rather than the (default) for XML - which is the browser?

I would do something like this:

1. Perform the xml2xls conversion server-side
2. Rename the .php extension into .xls
3. Make .xls extensions execute as PHP
4. Output binary xls with Excel header

This way you should obtain maximum compatibility with all kinds of
programs that deal with .xls-extensions (and not only the typical
Microsoft workarounds which are often problematic).

I have one question though. You start with xls, then save it as xml,
and then want to open it again as xls at the client machine... why
don't you just store the initial xls-file ? (but maybe I'm missing
something)

--
Bart
No, its never really an .xls file. To create a "base" file, I went
into excel and created a sheet then "saved as" xml. That was a one
time thing. The php scripts ALWAYS manipulate/display the XML file -
they don't mess with xls at all (been down that road, royal pain).
xml2xls is another interesting idea - not sure how to do that, but
will look into that also...
Jan 30 '08 #5

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

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
18
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page...
1
by: Lize | last post by:
Hi, I'm writing an ASP application to open an excel workbook, then run a macro stored in the excel file, which produces outputs that will be displayed back onto my ASP application. Now the...
1
by: v_verno | last post by:
Good day, I have a web page that shows info retrieved from a MySQL db and I would like to convert all these data into an .XLS file. Have searched the net high and low but seems that I'm unable to...
1
by: Sonnich | last post by:
Hi! I have a asp file, which opens a document into excel ( Response.ContentType = "application/vnd.ms-excel") The point is, that it creates my excel document well, but I need: 1) to open...
3
by: Fauna | last post by:
I'm having an Excel problem. I hope this is the appropriate group to post in. I am converting an existing classic ASP web application to ASP .NET. There is a reporting menu where the user...
3
by: toffee | last post by:
Hi all, I got a pre-formatted spreadsheet. would it be possible using js to copy the data from a table on the current webpage, open the spreadsheet and paste the content ? if so, anyone got any...
2
by: defabiisk | last post by:
Hello, I'm trying to open some data I've collected in my Perl DBI script - in excel. I'm using Javascript function to try and open the data in execl - without trying to do a SaveAs first. So I...
7
by: Peter | last post by:
ASP.NET 2.0 I am trying to open a Word document and Excel document from a dialog web page, what's the best way to do that? I have tried the following: Response.Clear();...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.