Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 30th, 2006, 07:18 AM
amsuone amsuone is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 9 amsuone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 11 sec
Reputation Power: 0
Unhappy Save excel file

Any one help me how to save excel file from browser.

I have 2 frame for data, the top frame for the excel file and the bottom frame for button to save.

I have used java script when event onclick from save button as below :

window.parent.mainFrame.document.execCommand('Save As', null, null);

but it does not work!!!

Reply With Quote
  #2  
Old October 6th, 2006, 01:30 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - *Local Friend*
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 469 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 36 m 37 sec
Reputation Power: 12
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
i have no knowledge about this but instead of going

parent.mainFrame.document.ex..

try something like

parent.mainFrame.[object] if there is one, like i said i know nothing about it, i will start to research it more now because i am curious now

colton22

Last edited by colton22 : October 6th, 2006 at 01:35 PM.

Reply With Quote
  #3  
Old October 6th, 2006, 01:38 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - *Local Friend*
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 469 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 36 m 37 sec
Reputation Power: 12
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22

Reply With Quote
  #4  
Old October 6th, 2006, 10:27 PM
amsuone amsuone is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 9 amsuone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 11 sec
Reputation Power: 0
try with java servlet

I can not found out how to save by java script so I used java servlet for it as below :


import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;


public class ExcelFileDownload extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;

private HSSFWorkbook workbook = null;
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet .http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request, response);
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPost(javax.servle t.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {

String FileDownLoad = getServletContext().getRealPath(getFileDownloadPat h(request));
System.out.println("Path download = "+ FileDownLoad);
if (FileDownLoad != null) {

POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(FileDownLoad));

this.workbook = new HSSFWorkbook(fs);
}

String filename = "xls_downloadFile";
if (filename.toLowerCase().endsWith(".xls")) {
filename = filename.substring(0, filename.length() - 4);
}

OutputStream ostream = response.getOutputStream();
response.setContentType("application/msexcel");
response.setHeader("Content-disposition","attachment; filename="+ filename + ".xls" );

workbook.write(ostream);
ostream.close();

} catch (Exception e) {
throw new ServletException("Unable to build Excel Document", e);
}
}

private String getFileDownloadPath(HttpServletRequest request){
return String.valueOf(request.getParameter("fileDownload"));
}
}

Reply With Quote
  #5  
Old October 6th, 2006, 10:51 PM
amsuone amsuone is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 9 amsuone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 11 sec
Reputation Power: 0
It's work but have a problem.

Follow code in class "ExcelFileDownload", it's can open dialog for download file. But I have a problem to call the servlet from browser. I have try as below :

<a href="./srv-xlsdelete?fileDownload=/WEB-INF/tmpreport/tmp" + name + ".xls">Save</a>

This like can open dialog box for save. but after I save the excel file from browser(in Top frame). it has a problem with MS excel program, it does not work. I can not open the file that I have been save and I can not do anything on excel file. Maybe because the path of file on excel still link to "./srv-xlsdelete?fileDownload=/WEB-INF/tmpreport/tmp" + name + ".xls" .

Then I try to call servet as below :
<script>
window.open("./srv-xlsdelete?fileDownload=/WEB-INF/tmpreport/tmp" + name + ".xls", null, null)
</script>

It's work, it does not have problem for excel program. I can open every excel file after I save the excel file from browser. But it's still have a problem. Because when the code window.open(....) work, it will be have a new empty window which I don't want.

I have try to change the arg as window.open("...", "_parent", null). It does not have a new window but the problem is occur with the excel program the same as I use <a href="..">.

So I think it need to have a window to hold data for excel when I try to save. DO YOU HAVE ANY IDEAS FOR ME?????
PLEASE HELP ME!!!!

T_T

Reply With Quote
  #6  
Old October 9th, 2006, 07:19 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - *Local Friend*
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 469 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 36 m 37 sec
Reputation Power: 12
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
im trying to think in the mean time i will reserch more of this, if anyone else is reading this and knows plesae post


colton22

Reply With Quote
  #7  
Old October 12th, 2006, 01:05 AM
amsuone amsuone is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 9 amsuone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 11 sec
Reputation Power: 0
Thank you

Thank you to try to think about that.
I am still waiting for someone help!!

T_T

Reply With Quote
  #8  
Old October 12th, 2006, 06:53 AM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - *Local Friend*
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 469 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 36 m 37 sec
Reputation Power: 12
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
did you save the window.open into a variable to call later?

colton22

Reply With Quote
  #9  
Old October 19th, 2006, 11:19 PM
amsuone amsuone is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 9 amsuone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 11 sec
Reputation Power: 0
Quote:
Originally Posted by colton22
did you save the window.open into a variable to call later?

colton22



No, I did not save it.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Save excel file


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap