This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Opening New Window with a different MIME TYPE

 
T Griffin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to build a function that will take an HTML table on one
page and open it in excel in a separate window. The problem I seem to
be having is that when I open a new window using the document.open()
method, it's seems to open it as a text/html stream. Here is the code
I use. Each table has a unique ID. I get the HTML and try to open a
new window. The new window still opens as HTML not in EXCEL. The
kicker is that if I save the new window as HTML and then open it
separately - it WILL open in excel!!! (Must use IE v5.01, and using
Java Server Pages)
If anyone can help it would be appreciated
Troy

Code:

function getTabletoExcel(tableid) {

//find the table by the ID
tmpobj=document.all[tableid];

//get the HTML
strHtml=tmpobj.outerHTML;

//opens in separate window
//still does not open as excel???
excelwindow = window.open("", "EXCEL"); // a window object
excelwindow.document.open("application/vnd.ms-excel", "");

//try to set various content types - STILL does not work
excelwindow.document.writeln('<%@ page
contentType="application/vnd.ms-excel" %>');
excelwindow.document.writeln('<%
response.setHeader("Content-Type","application/vnd.ms-excel");%>');
excelwindow.document.writeln('<%
response.setContentType("application/vnd.ms-excel");%>');

excelwindow.document.write(strHtml);
excelwindow.document.close();

//If I save the output generated and open it separately it DOES open
in EXCEL!!!
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic