Home Answers Viewqa Development-process Browse Excel File Problem

 
 


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

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 Pages:
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 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 Button Enlarge Field - Development process
data in the field.   Hi friend, Code for Browse the file. Set the "size" to enlarge the browse button. For any more problem...Browse Button Enlarge Field  How can I enlarge the browse text field
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
browse image
browse image  how to browse the image in image box by browse button... img; JTextField text=new JTextField(20); JButton browse,save; JPanel p=new JPanel(new GridLayout(1,2)); JLabel label=new JLabel(); File file = null; String path
browse image
browse image  how to browse the image in image box by browse button... img; JTextField text=new JTextField(20); JButton browse,save; JPanel p=new JPanel(new GridLayout(1,2)); JLabel label=new JLabel(); File file = null; String path
Browse an image
Browse an image  hi................ i want to browse an image from... text=new JTextField(20); JButton browse,save; JPanel p=new JPanel(new GridLayout(1,2)); JLabel label=new JLabel(); File file = null; String path=""; public
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
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
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
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
excel
excel  how to read columns values of excel file in java and store in array list in java like col1 col2 2 3 1 7 7 9 then list1 have values of col1 and list2 have values of col2...  
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
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
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE>
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE>
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  
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
swing application to import a object in a excel
'create from file' window>browse (this browse path I want to give inside the swing... to make a swing application where I can import a object in a cell of a excel... to do it. please help. The details of the excel operation which i want to do
Read Excel file and generate bar graph
Read Excel file and generate bar graph In this tutorial, you will learn how to read an excel file and generate bar graph. Here is an example that reads an excel file using POI api and store the data into array list. We have created
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
how to browse folder and directory in jsp
how to browse folder and directory in jsp  how to browse folder.../Desktop/Startest/"; java.io.File file; java.io.File dir = new java.io.File(root); String[] list = dir.list(); for (int i = 0; i < list.length; i++) { file
excel report fro jsp mysql
excel report fro jsp mysql  Dear Sir, I am facing some problem while... your site, I can able to generate excel file for all data types other than blob data. But I need your help for generating a excel file from mysql DB for blob
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
Import object in Excel using java swing
Import object in Excel using java swing  Hi sir, I want to make.... The details of the excel operation which i want to do by one click: in excel its... to: 'insert' ribbon>select 'object'>select 'create from file' window>
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
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
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
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
download excel
download excel  hi i create an excel file but i don't i know how to give download link to that excel file please give me any code or steps to give download link
Export data in excel sheet in java in struts - Struts
Export data in excel sheet in java in struts  Hello, All how can i export data in excel file i java  Hi friend, For solving the problem visit to : http://www.roseindia.net/jsp/excelfile.shtml Thanks
extracting phone number n storing in excel
extracting phone number n storing in excel  i need a program to open a doc file n extract phone numbers from it and store it in a excel sheet?? plz do reply and help me out with the problem
extracting phone number n storing in excel
extracting phone number n storing in excel  i need a program to open a doc file n extract phone numbers from it and store it in a excel sheet?? plz do reply and help me out with the problem
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
Using a image for Browse button instead of normal html Browse button... : The above code snippet is able to open the File Chooser. There is also a Upload button, when I upload the file selected, it gives me errors
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
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
code for attendence in excel sheet - Java Magazine
the problem : Create a Excel file   Search...code for attendence in excel sheet  When i enter an "Empid "in an an HTML page, time of the system should save in the excel file of that Empid row(IE
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
uploading and reading the excel daa
uploading and reading the excel daa  uploading the excel file not getting the data of the excel
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
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.