|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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!!! |
|
#2
|
||||
|
||||
|
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 12:35 PM. |
|
#3
|
||||
|
||||
|
|
|
#4
|
|||
|
|||
|
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")); } } |
|
#5
|
|||
|
|||
|
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 ![]() |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
Thank you
Thank you to try to think about that.
I am still waiting for someone help!! T_T |
|
#8
|
||||
|
||||
|
did you save the window.open into a variable to call later?
colton22 |
|
#9
|
|||
|
|||
|
Quote:
No, I did not save it. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Save excel file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|