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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


saurabh nahata
excel
2 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners


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...


Advertisement
View Answers

March 21, 2012 at 1:57 PM


 import java.io.*;
 import java.util.*;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFCell;

    public class ReadExcel{
        public static void main(String[]args){
    short a=0;  
    short b=1;  
     int i=0;   
    ArrayList list1=new ArrayList();
    ArrayList list2=new ArrayList();
        String   value1="", value2="";//,value3=" ", value4="";    
       String filename ="C:/data.xls";     
        if(filename != null && !filename.equals("")){
        try{    
        FileInputStream fs =new FileInputStream(filename);    
        HSSFWorkbook wb = new HSSFWorkbook(fs);   
        for(int k = 0; k < wb.getNumberOfSheets(); k++){    
         int j=i+1;    
         HSSFSheet sheet = wb.getSheetAt(k);    
         int rows  = sheet.getPhysicalNumberOfRows();    
         for(int r = 1; r < rows; r++){    
         HSSFRow row   = sheet.getRow(r);    
         int cells = row.getPhysicalNumberOfCells();    
            HSSFCell cell1  = row.getCell(a);      
            value1 = cell1.getStringCellValue();   
            HSSFCell cell2  = row.getCell(b);     
            value2 = cell2.getStringCellValue();    

            list1.add(value1);
            list2.add(value2);



}       
 i++;   
}    
}catch(Exception e){  

 }

 }
 System.out.println("List1 values : ");
 for(int j=0;j<list1.size();j++){
     System.out.println(list1.get(j).toString());
 }
 System.out.println("List2 values : ");

  for(int j=0;j<list2.size();j++){
     System.out.println(list2.get(j).toString());
 }

        }
    }


March 21, 2012 at 1:57 PM


 import java.io.*;
 import java.util.*;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFCell;

    public class ReadExcel{
        public static void main(String[]args){
    short a=0;  
    short b=1;  
     int i=0;   
    ArrayList list1=new ArrayList();
    ArrayList list2=new ArrayList();
        String   value1="", value2="";//,value3=" ", value4="";    
       String filename ="C:/data.xls";     
        if(filename != null && !filename.equals("")){
        try{    
        FileInputStream fs =new FileInputStream(filename);    
        HSSFWorkbook wb = new HSSFWorkbook(fs);   
        for(int k = 0; k < wb.getNumberOfSheets(); k++){    
         int j=i+1;    
         HSSFSheet sheet = wb.getSheetAt(k);    
         int rows  = sheet.getPhysicalNumberOfRows();    
         for(int r = 1; r < rows; r++){    
         HSSFRow row   = sheet.getRow(r);    
         int cells = row.getPhysicalNumberOfCells();    
            HSSFCell cell1  = row.getCell(a);      
            value1 = cell1.getStringCellValue();   
            HSSFCell cell2  = row.getCell(b);     
            value2 = cell2.getStringCellValue();    

            list1.add(value1);
            list2.add(value2);



}       
 i++;   
}    
}catch(Exception e){  

 }

 }
 System.out.println("List1 values : ");
 for(int j=0;j<list1.size();j++){
     System.out.println(list1.get(j).toString());
 }
 System.out.println("List2 values : ");

  for(int j=0;j<list2.size();j++){
     System.out.println(list2.get(j).toString());
 }

        }
    }


Related Tutorials/Questions & Answers:
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...  
excel
excel  how to save excel sheet data into the database using poi api?   import java.io.*; import java.sql.*; import java.util.*; import java.util.regex.*; import org.apache.poi.hssf.usermodel.
Advertisements
JDBC to EXcel
JDBC to EXcel  How to insert data in excel sheet from java
JAVA EXCEL
JAVA EXCEL  How to read the contents of an excel, perform some calculation and wrote the calculated values to another excel using poi
Excel to database
Excel to database  Hi I want to update SQL database with the values from excel using java code. Can you help me
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
Sql to excel
Sql to excel  How to convert a Sql Data into excel Doc with Using Netbeans
JAVA_EXCEL
JAVA_EXCEL  I need to read the all the contents of excel which has... content another excel. For example if I have three tabs in an excel with some contents... to another excel. Please help me out with this problem
JSP TO EXCEL
JSP TO EXCEL  Hi sir/mam, How to import data to excel using jsp without retrieving database.   friend, you can't import excel data into the middle of an HTML pages (your JSP will result in an HTML page
To Generate Excel
With EXCEL in it has to open up how can i achieve this pls explain
convert excel into pdf
convert excel into pdf  How to convert excel into pdf files
uploading and reading the excel daa
uploading and reading the excel daa  uploading the excel file not getting the data of the excel
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 ..request parameter using i export the all data to database   <
How to Unlock Excel Password
How to Unlock Excel Password  anyone help me how to recover lost Excel file password
struts2 excel downloads
struts2 excel downloads  hi friend, how to set Timestamps(Date+time) values to excel sheet cells
Excel Column change
Excel Column change  How to change sequence of columns in Excel sheet through Java
VB and excel - Development process
VB and excel  Hello sir, I want to create an excel sheet in VB 6.0 and get the data from Excel to MS-Access and set the macro in MS-Access for the Excel sheet data. Data contain in Excel Sheet to display in MS-Access and set
JSP to Excel - JSP-Servlet
JSP to Excel  Need an example of JSP and Excel database connection. Thanks
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
struts2 excel downloads
struts2 excel downloads  hi sir, am new to the real time environment. am going to create excel sheet and setting values to excel sheet from db table dynamically by using Hibernate persistence logic.......am using struts2
jsp to excel - JSP-Servlet
jsp to excel  Hi All, I'm writing a program of jsp to Excel conversion with Using POI. My problem is i'm unable to put multiple data into excel...)); } FileOutputStream fileOut = new FileOutputStream("c:\\excel\\wct.xls
Excel Password Cracker Software
Excel Password Cracker Software  Hello I just want to know what is Excel Password Recovery software? I want need to recover a worksheet since I forgotten
Export html data to excel
Export html data to excel  I am trying to export data from an html page to an excel sheet.Any advise
currency symbols in excel
currency symbols in excel  How to add a currency symbol in Excel sheet? Please guide me
excel uploading in jsp
excel uploading in jsp  could you provide the source code for: 1)have to upload an empty excel sheet at client side i.e if client clicks an excel icon an empty excel sheet should open 2)when they fill data in that sheet and click
connect jdbc to an Excel spreadsheet
connect jdbc to an Excel spreadsheet  hello, How can I connect 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
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
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 to ms access
excel to ms access  hello sir i am developing a application which requires extracting data from excel sheet and place in the ms access database using java programming for example: in excel sheet i have 2 columns and more than
Excel - JSP-Servlet
Excel  How to export data from jsp to excel sheet. I am using struts1.2 in my application.  Hi friend, Code to data from Jsp to excel...: "success.jsp" For more information on excel sheet Using JSP visit
search for exact match in excel
search for exact match in excel  How to search for an exact match in excel and show data if the matched sting is found? Please tell me the script. Thanks in Advance
Advertisements
 

 

 

DMCA.com