Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

response.setContentType("application/vnd.ms-excel")

Status
Not open for further replies.

jagi

Programmer
Mar 13, 2005
48
US
Hi,

I have a jsp(original page), which has a link "Print as Excel" (sounds stupid - but i HAVE to be able to print it as excel). When the user clicks on this link, an almost invisible (zero height and width)popup window should open which opens the original page contents but with:
response.setContentType("application/vnd.ms-excel"), and prints the excel sheet and closes by itself.

I am able to pop a small window, but as the response type is set to Excel it opens MS Excel WorkBook- which is very big and visible. And the window.print() is not printing the Excel sheet, instead its simply printing the pop-window itself and window.close() is closing the pop-up window, but not the Excel WorkBook.

My Code

Code:
<%response.setContentType("application/vnd.ms-excel");%>
<%@ include file="/jsp/ivpLocks/originalPage.jsp" %>

<html>
<head>
	<script type="JavaScript">
		function  printAndClose() {
			window.print();
			window.close();
		
		}
	</script>
</head>
<body onload="javascript: printAndClose();">
</body>
</html>

Can anyone help me with this ?
1. I want to open a very small Excel WorkBook(almost invisible to user)
2. printAndClose() method should print Excel sheet instead of the popup window.
3. Excel workbook should close by itself after printing.

Please Help. Thanks a bunch.

 
By setting the response type as "application/vnd.ms-excel" you are telling the browser to open the data in Excel ... so it seems fair enough to me. You may be better off writing this in ASP or VB or something ... of maybe even some VBScript could do it ?

In any case, there is nothing in "JSP" as such that can do this - I would recommend asking in the VB or ASP forums ...

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top