By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

Open XML in excel with javascript?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
Interesting... I like the approach... will give it a shot.

Thanks!
Jan 30 '08 #3

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.