Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  138] [ 7]  / answers: 1 / hits: 66487  / 13 Years ago, fri, june 17, 2011, 12:00:00

From the JSP page, I need to browse excel file and after selecting file on system, I need to read that excel file contents and fill my form.



Currently I have tried with below code but its only working in IE with some changes in IE internet options for ActiveXObject. Its not working in rest of the browsers.



<script>
function mytest2() {
var Excel;
Excel = new ActiveXObject(Excel.Application);
Excel.Visible = false;
form1.my_textarea2.value = Excel.Workbooks.Open(C:/Documents and Settings/isadmin/Desktop/test.xlsx).ActiveSheet.Cells(1,1).Value;
Excel.Quit();
}
</script>


Please suggest some solution so that it works in all browsers.


More From » excel

 Answers
0

It is generally not possible to read/write any file via JavaScript in a browser. So without any additional plug-ins you will not be able to read/write Excel files from the browser. The ActiveX objects of Excel let you do this, but only IE supports ActiveX objects.



There may be other plugins for other browsers, but i am aware of none.



In the first place, why do you want to do that? Can you give a use case? Perhaps there are better options available than what you are trying.



UPDATE



You will have to pass the excel file to the server and do the reading of the excel in the server side (in a servlet for instance).



You will have to use a <input type='file'> in the JSP within a multipart form

<form name=myForm action=myServlet enctype=multipart/form-data method=post>



On the server side, you may want to use Apache Commons File Upload.



Once you have the file (or a stream on it) you can parse the file using, say, Apache POI HSSF/XSSF and then update the data to a database or pass it back to a JSP


[#91660] Wednesday, June 15, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarod

Total Points: 62
Total Questions: 111
Total Answers: 83

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
jarod questions
;