Browse Excel File Problem

Browse Excel File Problem

View Answers

June 12, 2009 at 5:18 PM

Hi Friend,

Please send your code so that we can help you.

Thanks

June 15, 2009 at 11:24 AM

Hi
I am using 3 jsp files.Here is my code.


Browsefile.jsp:

<%@page language="java" import="java.sql.*"%>
<html>
<body bgcolor=#EFF1FB>
<form name="browsetable">


<script type="text/javascript">

var xmlHttp,table,xmlHttp1,optr,i=1,j=1,query,path,filepath;
function showxlsFileTable(str)
{
path=str;
//alert(str);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}

var url="GetxlsFileTable.jsp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged1;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
// alert("Im in function="+str);
}
function showxlsFileColumn(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="GetxlsFileColumn.jsp";

//url=url+"?q="+str;
url=url+"?q="+str+ "&q1=" +path;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
// alert("Im in function="+str);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
function stateChanged1()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint1").innerHTML=xmlHttp.responseText;
}
}
function stateChanged2()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint2").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
//alert("Your browser broke!");

}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

function showTableValue(str)
{
//alert("2 "+filepath);
filetable=str;
fpath=filepath.substring(filepath.length-3,filepath.length);
if(fpath=="xls")
showxlsFileColumn(str)
//alert(document.addmytbl.datafile.value);

}
function readFile(fileBrowser)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert('Unable to access local files due to browser security settings. To overcome this, follow these steps: (1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again.');
return;
}

filepath=fileBrowser.value;
fpath=filepath.substring(filepath.length-3,filepath.length);
// alert(filepath);
if(fpath=="xls")
showxlsFileTable(filepath)

var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
try
{
// Back slashes for windows
file.initWithPath( fileName.replace(/\//g, "\\\\") );
}
catch(e)
{
if (e.result!=Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e;
alert("File '" + fileName + "' cannot be loaded: relative paths are not allowed. Please provide an absolute path to this file.");
return;
}

if ( file.exists() == false ) {
alert("File '" + fileName + "' not found.");
return;
}

}



</script>

<br><br>
Browse to select a file&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="file" name="fileBrowser" size="40" onchange="readFile(this)">
<p><div id="txtHint1"><b></b></div></p>
<p><div id="txtHint"><b></b></div></p>
<p><div id="txtHint2"><b></b></div></p>


</form>
</body>
</html>
_________________________________________________________________________

For Getting the tablenames am using next file.

GetxlsFileTable.jsp:

<%@page language="java" import="java.sql.*"%>
<html>
<%
String filepath=request.getParameter("q");
Connection cn;
ResultSet rs;
Statement st;
String tableName="";
//out.println("<br><br><table width=400 border><td>Table Column Name</td>");
%>
<h4>Select Table:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<select name=sheet2 onchange='showTableValue(this.value)'></h4>
<option value="-">-
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException se)
{
se.printStackTrace();
}
try
{

String database = "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+filepath.trim();
//System.out.println("tableName:"+tableName);
cn = DriverManager.getConnection(database,"","");
DatabaseMetaData dbmd = cn.getMetaData();
// String[] types = {"TABLE"};
rs = dbmd.getTables(null, null, "%", null);
while (rs.next())
{
tableName = rs.getString(3);
//System.out.println("tableName1111:"+tableName);
if(tableName.endsWith("$"))
{
tableName=tableName.substring(0,tableName.length()-1);
// tableName.addElement(tableName);
}
System.out.println("tableName:"+tableName);
%>
<option value<%=tableName%>><%=tableName%></option>
<%
}
%>

</select>
<%

}
catch (SQLException e)
{
}
%>
</html>

_______________________________________________________________________

For getting the table columns, am using this file.

GetxlsFileColumn.jsp:

<%@page language="java" import="java.sql.*"%>
<html>
<%
String sel1=request.getParameter("q");
//System.out.println("sel1=:"+sel1);
String filepath=request.getParameter("q1");
//System.out.println("filepath:"+filepath);
Connection cn;
ResultSet rs;
Statement st;
String columnName="";
//out.println("<br><br><table width=400 border><td>Table Column Name</td>");
%>
<h4>Column in importing table:<select name=sheet2 size=4 onchange='showValue1(this.value)'></h4>
<!--<option value="-">-->
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException se)
{
se.printStackTrace();
}
try
{
//String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
// database+= filepath.trim() + ";";
String database = "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+filepath.trim();

cn = DriverManager.getConnection(database,"","");
DatabaseMetaData dbmd = cn.getMetaData();
rs = dbmd.getColumns(null, null, sel1+"$", null);
while (rs.next())
{
columnName = rs.getString("COLUMN_NAME");
//System.out.println("columnName:"+columnName);
%>
<option value<%=columnName%>><%=columnName%></option>

<%

}
%>
</select>
<%
}
catch (SQLException e)
{
}
%>
</html>

_________________________________________________________________________










Related Tutorials/Questions & Answers:
Browse Excel File Problem - Development process
Browse Excel File Problem  I am using a web application,in which i have to browse an excel file columns. It is working in my system. But if i access... displayed when i browse the file. What is the problem?  Hi Friend
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
Advertisements
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
how to read data from excel file through browse and insert into oracle database using jsp or oracle???  sir.. i have number of excel sheets which...://www.roseindia.net/answers/viewqa/JSP-Servlet/28123-write-excel-file-into-the-oracle
browse and submit the excel sheet into mysql as a table
browse and submit the excel sheet into mysql as a table  sir, i want to browse and after clicking a submit button, the data in the excel sheet should be stored in the mysql5.0 as a table
browse a file with java - Development process
browse a file with java  I want to count the number of white line and comment line in a file type with sql with java
Java file browse
Java file browse In this section, you will learn how to browse a file and allows the user to choose a file. Description of code GUI provide File choosers for navigating the file system, and then provide the utility to choose either
Export data in excel sheet via Browse and upload button into mysql database
Export data in excel sheet via Browse and upload button into mysql database  how to create a Browse & Upload Buttons and then save the information from it in mysql database's Table Am using struts2,hibernate for making
jsp - excel generating problem - JSP-Servlet
and download it.After saving the file. Then view excel file.The view image on this page is result excel file. If you have more problem then give details...jsp - excel generating problem  Hi, I worked with the creating
importing excel file
importing excel file  Hi All I am developing a java application whre we upload a excel file in to database and all excel value should import... it is not showing real excel sheet value. please suggest good way to solve this problem
Reading an excel file into array
Reading an excel file into array  Hi, I'm trying to read in an excel file, search a column for containing key words (entered by a user) and then displaying the matching rows in a table. I'm fairly new to JavaScript. Can anyone
Excel file Handling in Java
Excel file Handling in Java  Hello Sir, I am new to Java, I have Started Java Core by myself. I want to make a project which include 3-4 Excel file to handle.Please explain how to read and write Excel file in Java.Is it tough
how to use Excel Templet to write excel file using java.
how to use Excel Templet to write excel file using java.  how to use Excel Templet to write excel file using java
excel file using JDBC java.?
excel file using JDBC java.?  hey, i am a telecomm. engineer , and i am try to develop a tool which reads from a excel file and then appends the same excel file as required. i am writing my code on notepad and have successfully
importing excel file and drawing multiple graphs from one excel file
importing excel file and drawing multiple graphs from one excel file  thanks a lot sir for replying with code for importing excel file... time from one excel file using different columns..and instead of passing column
Excel file wriring using java
Excel file wriring using java  i have one predefined bill format in excel i want to append values in it using java apche POI or Jexcel i tried it but it overwrites file and lost previous contents what can i do
Reading and querying an Excel file in JavaScript
Reading and querying an Excel file in JavaScript  Hi, I'm trying to read in an excel file, search a column for containing key words (entered by a user) and then displaying the matching rows in a table. I'm fairly new
write excel file into the oracle database
write excel file into the oracle database  dear sir, i need the jsp code that reads the excel file and stores it into the oracle database table..and also i need the code to connect oracle database? thank u in advance
how to use Excel Template to write excel file using java
how to use Excel Template to write excel file using java  How to use Excel template to write data in that file using java
Problem reading word file
Problem reading word file  Deepak you provide me code for extarcting equation from a word file and also to write in a word file.But when I again want to read preveously created word file(created by your code) it gives an error
File Uploading Problem
File Uploading Problem  I have a file uploading code but it create problem $(document).ready(function(){ $('#upload').click(function(){ var... it gives the problem org.apache.commons.fileupload.FileUploadException
File Uploading Problem
File Uploading Problem  I have a file uploading code but it create problem $(document).ready(function(){ $('#upload').click(function(){ var... it gives the problem org.apache.commons.fileupload.FileUploadException
Linking an Excel File with the Application tool
Linking an Excel File with the Application tool  I have to link an excel file with a application software which I am developing.I have this code... on the questions that are in the excel file like extracting the questions from the excel file
Inserting data in Excel File - Java Beginners
Inserting data in Excel File  Dear Sir, How can we fill the excel... an excel with filled data? Kindly give me the solutions to questions... the problem : Thanks
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
how to insert excel file into mysql datbase in servlet
how to insert excel file into mysql datbase in servlet  emphashow to insert excel file into mysql datbase inservletized text
Problem in executing macro enabled excel sheet using java
Problem in executing macro enabled excel sheet using java  Hi, I have written a java code which will read a excel sheet with macro enabled... to execute VB script it is unable to execute macro and cannot generate the script file
connection of java file to excel file and put data from excel file into oracle db
connection of java file to excel file and put data from excel file into oracle db  how to create button on excel sheet using java swing and how we give action to that button excel sheet? how we connect excel file to java file
How to insert rows from Excel spreadsheet into database by browsing the excel file?
file?  I want to insert rows from excel sheet to database.for this i... the excel file using file browsing dialogue through form in JSP. How can i select excel file and insert rows into MSSQL database in JSP???   Have a look
application context file problem
application context file problem  how to configure junit application context file with struts........? it is not finding sessionfactory method
struts jar file problem
struts jar file problem  hi.. I'm using struts-core-1.3.9.jar. it works well if am using ma application with internet but it shows me an error while initializing ActionServlet when i disconnected to Internet The error stack trace
insert rows from Excel sheet into a database by browsing the file
it user friendly.i.e user should browse the existing excel file... Excel file in java(JSP). I can insert rows using ODBC connetion. But using odbc...insert rows from Excel sheet into a database by browsing the file  
reading data from excel file and plotting graph
reading data from excel file and plotting graph  I am doing a project using NetBeans in which i have to take input an excel file and then using the data in excel file, i have to plot graphs based on CELL ID selected. please help
JavaScript get excel file data
JavaScript get excel file data...; By the use of JavaScript we can get the excel file data as well. Here is the example which gets the data from the excel file with the cell and row index
How to browse and upload the file in same page using jsp.
How to browse and upload the file in same page using jsp.  Hi, I am doing a project and i want to browse and upload the file in same page inside... allow the user to browse a file to upload. The file is then uploaded to server
How to browse and upload the file in same page using jsp.
How to browse and upload the file in same page using jsp.  Hi Sir, I am doing a project in jsp servlets and i want to browse and upload.... The given code allow the user to browse a file to upload. The file is then uploaded
insert values from excel file into database
insert values from excel file into database   hi i want to insert values from Excel file into database.Whatever field and contents are there in excel... the following link: Insert values from excel file to database
Linking excel file with a application tool using swing
Linking excel file with a application tool using swing  I have to link an excel file with my application software using java swing.As soon as i click on the link button a window should open for selecting the excel file(just like
problem while reading .csv file
problem while reading .csv file  I have a problem here..... i am reading a .csv extention file which has some value....but the problem is der is an amount column which contains , in between (eg) 3,899.00 which inturns creates
read excel file from Java - Java Beginners
read excel file from Java  How we read excel file data with the help of java?  Hi friend, For read more information on Java POI visit to : http://www.roseindia.net/java/poi/ Thanks
PHP Open Excel File in browser - PHP
PHP Open Excel File in browser  How we can open an excel file using PHP code. I don?t want to let the user to download it rather I would like to get it open in the web browser. Any help would be great. Thank you very much
downloading excel file using Java and springs
downloading excel file using Java and springs  I need to find out how to download an excel file using the spring framework in java. Please help me out as I am new to springs and its urgent
To read & write a excel file using the core java
To read & write a excel file using the core java  Hai, I'm new to JavaProgram.But now i need java program to read & write a excel file so, can anyone help me to learn the above mentioned topic(link for the portion
Problem in getting file path in js
Problem in getting file path in js  hi, I am using ofbiz framework , How i can get the file path in javascript for input type = "file" and i am using only firefox not other browser. so please help me it is very important for me
Exception when opening a excel file in JFrame
Exception when opening a excel file in JFrame  Hello, I have a problem when trying to display a Excel file in a Jframe. The exception is like this: com.jniwrapper.LibraryNotFoundException. here is my code public jexcelTest1
how to display the excel file content in the jsp
how to display the excel file content in the jsp  How to present the content of the newly created excel file in the following jsp to the web browser...="application/vnd.ms-excel" %> <%@ page import="java.io.*" %> <
Problem with appending data to the end of file
Problem with appending data to the end of file  MY JSP CODE... successfully</h1>"); %> </body> </html> JAVA CLASS FILE CODE... { public static void add(String name,String mail,String path) throws IOException { File
how to display the output of the newly created excel file
how to display the output of the newly created excel file  the following program will create the test.xlsx file, how can i display the content of the test.xlsx file in the web browser? thanks, %@ page import
how to display the excel file in the web browser.
how to display the excel file in the web browser.  > %@ page.../vnd.ms-excel" > %> <%@ page import="java.io.*" %> <% >... FileOutputStream > ("c:\\excel\\aqtemplate.xlsx"); > wb.write
retrieving of value from excel file - JSP-Servlet
retrieving of value from excel file  Dear sir, Thanks for sending... this message to all the employees when i upload a file then it fetch a data from that excel sheet i.e this matter will take a para meter values from the excel
retrieving of value from excel file - JSP-Servlet
retrieving of value from excel file  Dear sir, Thanks for sending... this message to all the employees when i upload a file then it fetch a data from that excel sheet i.e this matter will take a para meter values from the excel

Ads