/    Sign up×
Community /Pin to ProfileBookmark

Alternative to ActivexObjects

Hi guys,

I trying to create an excel sheet from the table generated by the jsp.
<script type=”text/javascript”>
function ToExcel(){
var i;
var j;
var mycell;
var tableID = “tblInnerHTML”;
alert(tableID);
var objXL = new ActiveXObject(“Excel.Application”);
var objWB = objXL.Workbooks.Add();
var objWS = objWB.ActiveSheet;

for (i=0; i < document.getElementById(tableID).rows.length; i++)
{
for (j=0; j < document.getElementById(tableID).rows(i).cells.length; j++)
{
mycell = document.getElementById(tableID).rows(i).cells(j)
objWS.Cells(i+1,j+1).Value = mycell.innerText;

}

}

objWS.Range(“A1”, “Z1”).EntireColumn.AutoFit();

objXL.Visible = true;

}
</script>

The use of ActiveXObjects makes it work perfectly in iexplorer, but not in mozilla.
What should I use in Mozilla to create the excel application?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@slaughtersJul 31.2008 — Simply include this meta-tag in the page which contains the table and excel will be launched to load the table instead of it loading in a web page:

[code=html]<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="application/vnd.ms-excel"> [/code]
You can do the same for word doc's, etc..

BUT if you are using JSP to generate the table page then just do it this way:

[CODE]<%-- Set the content type header with the JSP directive --%>
<%@ page contentType="application/vnd.ms-excel" %>

<%-- Set the content disposition header --%>
<% response.setHeader("Content-Disposition", "attachment; filename="mult-table.xls""); %>

<table>
<% for(int i = 1; i <= 12; i++){ %>
<tr>
<% for(int j = 1; j <= 12; j++){ %>
<td>
<%= i * j %>
</td>
<% } %>
</tr>
<% } %>
</table>[/CODE]
Copy linkTweet thisAlerts:
@felgallJul 31.2008 — All of the code above is IE only.

You will not get Excel to load in any other browser regardless of what header you use although you may get it to load the page into Excel directly provided that Excel is actually available.

Commands such as innerText are JScript commands that are not a part of JavaScript and JavaScript also has no equivalent to activeX - all those commands are for intranet use only where you know everyone is using IE.
Copy linkTweet thisAlerts:
@slaughtersAug 01.2008 — All of the code above is IE only...[/QUOTE]You are not refering to my post, but the original posters code - correct ?

Setting the content type to "application/vnd.ms-excel" works regardless of what browser you use. You are just dependent on having excel installed on the PC that is viewing the page

(should even work on the MAC, but I don't own one to try it on ? )

You can find a more comprehensive list of mime types here:

http://www.w3schools.com/media/media_mimeref.asp
Copy linkTweet thisAlerts:
@KorAug 01.2008 — 
Setting the content type to "application/vnd.ms-excel" works regardless of what browser you use. You are just dependent on having excel installed on the PC that is viewing the page

(should even work on the MAC, but I don't own one to try it on ? )
[/quote]

No. It seems like you don't sense the difference between a browser and an Operating System. That code will work only if [I]the browser[/I] is IE, no matter the OS. And for Mac there is only the dead-and-buried IE-for-Mac, which was such a bad browser than even its creators, Microsoft, have abandoned it an year or tow ago. For the moment, the Mac users rely mainly on Safari or FireFox.

I don't know if there is an equivalent for ActiveX in handling crossbrowser an Excel file. Probably the best way is to use a server-side application to parse Excel data into an universal transfer data structured language/notation, such as XML or JSON.
Copy linkTweet thisAlerts:
@slaughtersAug 01.2008 — No. It seems like you don't sense the difference between a browser and an Operating System. ....[/QUOTE]It's more like that I believed that setting content to "application/vnd.ms-excel" caused the browser to believe the content was *not* text/html and would force a "save as" or "open with" dialog box.

Which is what it actually does. If you have Apache/Tomcat installed, or some other JSP web server then run the code I provided.

It works fine. It does not matter what browser you are using.

http://www.stansight.com/tmp.jpg

[upl-file uuid=0e0065cf-4018-48a7-80f4-ee83186fd0d9 size=38kB]tmp.jpg[/upl-file]
Copy linkTweet thisAlerts:
@KorAug 01.2008 — Ok, I see. I agree it could work. I promise to test ?
Copy linkTweet thisAlerts:
@felgallAug 01.2008 — It is of course still dependent on someone having a suitable program to open it with. Some people on dial-up still consider OpenOffice to be too large to attempt to download it.
×

Success!

Help @sarvagna spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...