Home Answers Viewqa JSP-Servlet importing excel file

 
 


Yogi
importing excel file
2 Answer(s)      2 years and 5 months ago
Posted in : JSP-Servlet

Hi All I am developing a java application whre we upload a excel file in to database and all excel value should import in to the database column. I am using below logic for inserting value. it shwoing some garbaze value.

my code is:

package import java.io.FileInputStream; import java.util.Iterator; import java.util.Vector;

import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class ReadExcelFile {

public static void main(String[] args) {

    String fileName = "C:\\hhh.xls";
    Vector dataHolder = ReadCSV(fileName);
    printCellDataToConsole(dataHolder);
}

public static Vector ReadCSV(String fileName) {
    Vector cellVectorHolder = new Vector();

    try {
        FileInputStream myInput = new FileInputStream(fileName);

        POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

        HSSFSheet mySheet = myWorkBook.getSheetAt(0);

        Iterator rowIter = mySheet.rowIterator();

        while (rowIter.hasNext()) {
            HSSFRow myRow = (HSSFRow) rowIter.next();
            Iterator cellIter = myRow.cellIterator();
            Vector cellStoreVector = new Vector();
            while (cellIter.hasNext()) {
                HSSFCell myCell = (HSSFCell) cellIter.next();
                cellStoreVector.addElement(myCell);
            }
            cellVectorHolder.addElement(cellStoreVector);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return cellVectorHolder;
}

private static void printCellDataToConsole(Vector dataHolder) {

    for (int i = 0; i < dataHolder.size(); i++) {
        Vector cellStoreVector = (Vector) dataHolder.elementAt(i);
        for (int j = 0; j < cellStoreVector.size(); j++) {
            HSSFCell myCell = (HSSFCell) cellStoreVector.elementAt(j);
            String stringCellValue = myCell.toString();
            System.out.print(stringCellValue + "\t");
        }
        System.out.println();
    }
}

}

but it showing following output:

org.apache.poi.hssf.usermodel.HSSFCell@bfc8e0 org.apache.poi.hssf.usermodel.HSSFCell@11d0a4f
org.apache.poi.hssf.usermodel.HSSFCell@18fd984 org.apache.poi.hssf.usermodel.HSSFCell@111a775
org.apache.poi.hssf.usermodel.HSSFCell@91cee org.apache.poi.hssf.usermodel.HSSFCell@4a63d8

it is not showing real excel sheet value.

please suggest good way to solve this problem.

View Answers

February 21, 2011 at 9:53 PM


sorry if it's too late, try myCell.getStringCellValue() instead of myCell.toString()

That way you are only writing the object in memory.


February 21, 2011 at 9:54 PM


sorry if it's too late, try myCell.getStringCellValue() instead of myCell.toString()

That way you are only writing the object in memory









Related Pages:
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
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
Importing in eclipse - Java Beginners
Importing in eclipse  I'm using eclipse for designing struts application... I'm manually copying the tld files and creating struts-config.xml file for my project... Is there the best way to import the tld files or to add
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
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...  
How to read excel contents when uploaded
where the user uploads his excel file. Jsp page must read the excel contents... files.Please do help..   user logins and he uploads his excel file. the excel... is it possible?   user logins and he uploads his excel file. the excel file must
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
Importing Preferences
Importing Preferences       This example demonstrates you how to import a file of exported.... You can see in the given example that we have create an file input stream
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
Packages - Importing
Java NotesPackages - Importing Multiple classes of larger programs... in the file system, and may be nested just as directories are nested. Using existing..., which is in a directory named java. Importing classes explictly If you need
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
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 in java . . . .
Importing in java . . . .   We all know that when we are importing a class of a package in another package , the methods which are public are only available and we can use it . But suppose the method has default access specifier
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
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
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
Importing hibernate project
Importing hibernate project  What are the steps to import hibernate project in myeclipse
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
Inserting data in Excel File - Java Beginners
Inserting data in Excel File  Dear Sir, How can we fill the excel with fetched data from the database like Oracle, DB2? Is it possible to create an excel with filled data? Kindly give me the solutions to questions
excel to database
excel to database   How to export data from excel sheet to mysql database by using java with request parameter Here q=40 is a request parameter...(); Workbook workbook = Workbook.getWorkbook(new File("C:/data.xls"), ws
How to Unlock Excel Password
How to Unlock Excel Password  anyone help me how to recover lost Excel file password
Reading And Writing Excel File
reading and writing excel file   ... org.apache.poi.poif.filesystem.POIFileSystem class is used to buffer the excel file into an object. In other words, we can say that it is used to read the excel file. After reading the excel
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.*" %> <
Convert CSV to excel File - Java Beginners
Convert CSV to excel File  Sir, i have CSV file as input. I need to convert that CSV file to excel file and format. Currently i am using HSSF POI api to format the excel file. Here i am unable to read the data from the CSV
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
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
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
Import Excel file(date) into mysql database in php
Import Excel file(date) into mysql database in php  I try to import excel file which contains data date(yyyy-mm-dd) into mysql database in php..._select_db("DBA",$connect); //select the table //$file = $_FILES['data.csv
retrieving excel data when file uploading
retrieving excel data when file uploading  <%@page import...); } } %> when i gave full path name i got excel data but when file...\\hp\\Desktop\\Book1.xls"; String filename=request.getParameter("excel
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
Importing Your Own Package
Importing Your Own Package  I would like to know if it is possible to create a class with your own methods so that you can import them when writing programs
How to upload a large excel file - JSP-Servlet
How to upload a large excel file   Dear sir , How to upload a large excel file and how to read a that large excel file or how to get a each column values from that large excel file.For small file i am getting values
Create and Save Excel File in JSP
Create and Save Excel File in JSP  ... and saving Excel file from JSP application. In this example we are going... file.  To create an excel sheet we can use third party API which is Apache
How to import data from sql server table into an excel file by creating the rows dynamically in the excel according to the dataabase??
How to import data from sql server table into an excel file by creating... data from sql server table into an excel file by creating the rows dynamically... to create an excel file according to that and keep updating the same
connect jdbc to an Excel spreadsheet
to an Excel spreadsheet file using jdbc?   Hello Friend, Follow... Excel Driver(*.xls) Select work book or excel file and Create the DSN name (e.g... of the selected excel file in the query. Thanks
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

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.