on 08-21-2006 1:27 PM
Hi all,
I need to display XL file in the browser.
Here the problem is,In JSP I am providing one link, After clicking the ling I have to create one XL file and dispaly the XL file(open and display) with out clicking another link or button.
I wrote one action to create one XL file(after clicking the link it will come to action). Here I am creating XL file and storing the file. Here I need to displai the XL file in the browser with clicking another button or link.
<b>In single click only I have to create the file and disply the XL file.</b>
waiting for solution............
Thanks & Regards
Rama Krishnam Raju
Hi,
You can do it with JavaScript.
The code for opening a new browser and writing data to that browser looks something like this (in your JSP):
<script language="JavaScript">
function openExcelWindow(){
newWindow=window.open("excel.html","excelWindow");
newWindow.document.write(<%= excelData %>);
}
</script>
The Java variable excelData must contain the data.
In order to execute the javascript function after clicking the hyperlink, you can use the onClick attribute in your hyperlink: onClick="openExcelWindow()". Make sure href="#".
Good luck,
Roelof
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Have you set the browser to reload each page instead of using cached data?
Internet options, General/Temporary internet settings/Settings.
Check for newer versions: "Every visit to the page".
When you click a url that ends with ".xls", the browser normally asks what to do: Open, save or cancel.
Do you get this question?
Regards, Roelof
Hi,
pls see the code what I worte in jsp is
<b><% String filepath=(String)request.getAttribute("url");%>
<title>My JSP 'Dispaly.jsp' starting page</title>
<meta http-equiv="refresh" content="10;URL='<%=filepath %>' "> (here file path is "Registrationdata/Registrationdata22-7-106-1156254077328.xls")</b>
it is printing the data in browser as follows instead opening the spreadsheet.
<b>UM_User_id, UM_First_Name, UM_Middle_Name, UM_Last_Name, UM_Dept_Name, UM_City, UM_Primary_Email, UM_Created_On, No.of BPs Uploaded, UM_Status, UM_isValidDomain 1, rama , rao , n , Force ITES , hyd , acb@forceites.com , 2006-08-11 12:47:00.0 , 2 , Pending , Yes 2, karri , rama , reddy , yahoo , sec , acb@yahoo.com , 2006-08-11 12:47:00.0 , 2 , Pending , Yes 3, rama , krishnam , raju , yahoo , hyd , akb@yahoo.com , 2006-08-11 12:47:00.0 , 0 , Pending , No 4, rakesh , rww , rak , computers , hyd , zcb@yahoo.com , 2006-08-11 12:47:00.0 , 1 , Inactive , No 5, hemanth , h , n , electronics , sec , bcd@rediffmail.com , 2006-08-14 10:46:07.0 , 2 , Inactive , Yes 6, jagadish , mid , J , forceites , bombay , abc@forceites.com , 2006-08-22 13:33:33.0 , 0 , Active ,No 7, XYZ , Y , Z , gmail , calcutta , BCD@YA.COM , 2006-08-17 18:26:55.0 , 0 , Inactive , No</b>
It is not opening the spreadsheet but it is printing the data.
I need to open the spreadsheet on the browser with the data.
<b>Browser settings also I checked.</b>
kindly solve my prob.
Thanks & Regards
Rama
Hi Roelof,
Thank a lot.
But where i have to pass the XL file path for this method.
See the below link.
<b>http://finance.yahoo.com/d/quotes.csv?s=%5EIXIC&f=sl1d1t1c1ohgv&e=.csv</b>
I need like that(In the browser I have to display the XL file). Here i am trying to open the XL file but it is dispalying only the data without spread sheet.I have to dispaly the data with spread sheet.what i worte is..
<u>JSP Code:</u>
<%
String path = request.getContextPath();
String basePath = request.getScheme()"://"request.getServerName()":"request.getServerPort()path"/";
String filepath=(String)request.getAttribute("url");
System.out.println("url :"+filepath);
%>
<%
response.setContentType("application/excel");
response.sendRedirect(filepath);
%>
<script language="javascript">
function display(filename)
{
alert("fine path:"+filename);
window.open(filename);
}
</script>
</head>
<body onload = "javascript:display('<%=filepath%>')">
</body>
this is the code I wrote but it displaying( in Plain window) the data which is in XL file but not with spreadsheet.
this is the thing I have to do.
kindly give me suggestion to dispaly a spread sheet in browser.
Thanks & Regards
Rama Krishna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Ok, are you sure your file is in the right format?
Excel is a Microsoft proprietary format.
You could check this e.g. by creating a dummy page on your local PC with a hyperlink to the generated file on the server. Then right click on the hyperlink and choose "save link as".
Try to open the downloaded xls file in Excel. Let us know what happens.
Good luck,
Roelof
Hi,
Roelof,
Thank u very much for quick responce.
Here I am getting data from DB and creating CSV/XSL file and storing in the server(Tomcat)(there it is correct format only). manually it is opening but in the browser it is dispalying the data only instead of spreadsheet.
<b>With that link also it is displaying the data only instead of spreadsheet in my local system while trying.</b>
I need to dispaly the stored file at browser.
Thanks & Regards
Rama
Hi,
In that case, try VB scripting. I don't know much about VB script, but I found some resources.
A script for creating an Excel object in the browser:
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function button1_onclick() {
var ExcelSheet;
ExcelApp = new Object("Excel.Application");
ExcelSheet = new Object("Excel.Sheet");
// Make Excel visible through the Application object.
ExcelSheet.Application.Visible = true;
// Place some text in the first cell of the sheet.
ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
// Save the sheet.
ExcelSheet.SaveAs("C:\TEST.XLS");
// Close Excel with the Quit method on the Application object.
ExcelSheet.Application.Quit();
}
//-->
</SCRIPT>
You need to change this script in order to load the file from your server.
You may want to test for browser/platform, because it will only work on windows/IE:
<script language="JavaScript">
if ((navigator.userAgent.indexOf('MSIE') != -1)
&& (navigator.userAgent.indexOf('Win') != -1))
{document.writeln('<script language=
"VBscript">');
// write out rest of VBScript block here
document.writeln('</scr' + 'ipt>');
}
</script>
And a link to Microsoft's documentation:
Good luck!
Roelof
Hi again,
Still it's better to tell the browser to start the Excel plugin. Could it be that you misspelled CSV/XSL, it should be CSV/<b>XLS</b>.
With the VB scripting you can have problems with browser settings that do not allow scripts to run in hte browser.
I noticed the script says LANGUAGE=javascript, so I guess I was wrong. Copied it from http://groups.google.nl/group/comp.lang.javascript/browse_thread/thread/9bd17755acafa893/29c1f95e642...
Regard & good luck, Roelof
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.