Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
Java in General
java code to read excel columns row wise
Moieen Khatri
Ranch Hand
Posts: 144
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
/** * */ import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFCell; import java.io.FileInputStream; import java.io.IOException; import java.util.Iterator; import java.util.Vector; public class ExcelReader { public static void main(String[] args) throws Exception { String filename = "C:\\bugs reported.xls"; FileInputStream fis = null; try { fis = new FileInputStream(filename); HSSFWorkbook workbook = new HSSFWorkbook(fis); HSSFSheet sheet = workbook.getSheetAt(0); Iterator rowIter = sheet.rowIterator(); while(rowIter.hasNext()){ HSSFRow myRow = (HSSFRow) rowIter.next(); Iterator cellIter = myRow.cellIterator(); Vector<String> cellStoreVector=new Vector<String>(); while(cellIter.hasNext()){ HSSFCell myCell = (HSSFCell) cellIter.next(); String cellvalue = myCell.getStringCellValue(); cellStoreVector.addElement(cellvalue); } String firstcolumnValue = null; String secondcolumnValue = null; int i = 0; firstcolumnValue = cellStoreVector.get(i).toString(); secondcolumnValue = cellStoreVector.get(i+1).toString(); insertQuery(firstcolumnValue,secondcolumnValue); } } catch (IOException e) { e.printStackTrace(); } finally { if (fis != null) { fis.close(); } } // showExelData(sheetData); } private static void insertQuery(String firstcolumnvalue,String secondcolumnvalue) { System.out.println(firstcolumnvalue + " " +secondcolumnvalue); } }
Maneesh Godbole
Bartender
Posts: 11497
19
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Do you have a question, or are you just sharing information?
[
How to ask questions
] [
Donate a pint, save a life!
] [
Onff-turn it on!
]
Moieen Khatri
Ranch Hand
Posts: 144
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
just sharing information
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How can I analize Excel file with Apache POI?
Java Code to export data to Excel
Unable to refresh Excel formula using POI
excel sheet data insertion
How do i format a string to date
More...