Open XML in excel with javascript?

J

JaxDawg

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.
 
T

tomtom.wozniak

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:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice"
xmlns:x="urn:schemas-microsoft-com:eek:ffice: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_image.php?img_id=j8R0xh9VhUlfUCM1201667857

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

-Tom Woz
 
B

Bart Van der Donck

JaxDawg said:
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)
 
J

JaxDawg

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)

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top