• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Excelsheet content reading

 
Arun vel
Greenhorn
Posts: 15
Java MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am trying to read an excel sheet for the purpose of writing it into database.By the below code ,I am getting the contents of the cell in first row,first column..Can you please help me to iterate it for the number of rows and columns.Little bit urgent...

 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you have the first sheet you can iterate using the for loop

for (int j = 0; j < sheet.getColumns(); j++) { //get columns
for (int i = 0; i < sheet.getRows(); i++) { //get rows
//whatever you want to do
 
Arun vel
Greenhorn
Posts: 15
Java MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay...Now I am getting the values of all the rows and columns..How can I store the value of each columns(as a field) for the purpose of storing in the database..
Thanks for the reply..
 
Tim Moores
Bartender
Posts: 2839
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What difficulty are you facing in storing those values in the DB? Are you familiar with the JDBC API?
 
Arun vel
Greenhorn
Posts: 15
Java MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya..I do have a knowledge in JDBC Api...But the thing is,I dont know how to store the values which I get from the excelsheet cells to some variables,so that only I can use them in my queries..
 
Tim Moores
Bartender
Posts: 2839
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't "String stringa1 = a1.getContents()" do that? I'm not familiar with jExcelAPI, buit if that's not the right method then the Cell class should have other methods that do return the correct data from the cell.
 
Arun vel
Greenhorn
Posts: 15
Java MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya...this is working...I have already tried...But it will retrieve the contents of a particular cell only...But I want to read all the cell(records) to a number of rows...
 
Tim Moores
Bartender
Posts: 2839
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a loop (or maybe two nested loops) would be involved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic