Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Development-process Browse Excel File Problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


biya
Browse Excel File Problem
2 Answer(s)      5 years and 4 months ago
Posted in : Development process



Advertisement
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
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  
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
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
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
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
Advertisements
 

 

 

DMCA.com