473,585 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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"wind ow.open("'.$fil e_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.S heet"?>
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 11945
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"wind ow.open("'.$fil e_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.S heet"?>
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 "applicatio n/
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:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
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.S heet>
<meta name=Generator content="Micros oft Excel 10">
</head>
<body><table><c ol><tr><td>Hell o 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"wind ow.open("'.$fil e_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.S heet"?>
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.co mwrote:
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"wind ow.open("'.$fil e_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.S heet"?>
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
35518
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 and extract information from specific worksheets and cells. I'm not really sure how to get started with this process. I ran the COM Makepy...
18
8825
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 (same folder). The cookie is not received. Can someone explain why? I worked around this by adding a cache-control header with a value of...
1
6375
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 problem I'm having is whenever I try to open a workbook (of any format, i.e. 97/2000, 95, or xp, and of any size, and with or without macros), excel...
1
9317
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 find a free tool that can do the above and therefore I'm forced to do everything from scratch. Till now have developed two different versions of...
1
1241
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 another excel file (static) at the same time, to I get the created file and a new one too.
3
2191
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 clicks on a link and it opens an Excel file in the browser. The browser we are using is IE 6. The old application does this via a javascript...
3
15982
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 links or pointers? i've already tried google - but all i get is ActiveX methods which work in a very few cases.
2
1998
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 have data all formatted in a Variable and I want this to open in excel - once I get the data to open i n excel - its then the use can review the data...
7
3999
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(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
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...
0
8199
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. ...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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...
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
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...

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.