Wednesday, 19 September 2012

Reading Data from excel file

How to read data from Excel file using Java

 

 

import java.io.*;
import java.sql.*;
public class ExcelReadTest{
public static void main(String[] args){ 
 Connection connection = null;
try{
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 Connection con = DriverManager.getConnection( "jdbc:odbc:exceltest" );
 Statement st = con.createStatement();
 ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
 
 ResultSetMetaData rsmd = rs.getMetaData();
 int numberOfColumns = rsmd.getColumnCount();
 
 
 while (rs.next()) {
 for (int i = 1; i <= numberOfColumns; i++) {
 if (i > 1) System.out.print(", ");
 String columnValue = rs.getString(i);
 System.out.print(columnValue);
 } 
 
System.out.println(""); 
}
 
st.close();
con.close();
}
catch(Exception ex) {
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}
}
 
 

OR

WorkbookSettings ws = new WorkbookSettings();   

ws.setLocale(new Locale("en","EN"));   

Workbook workbook = Workbook.getWorkbook(file);              

Sheet s = workbook.getSheet(0);         

LabelCell lcdate = s.findLabelCell("Date");          

LabelCell lcitem = s.findLabelCell("Item");                                  

LabelCell lcamount = s.findLabelCell("Amount");                                 

LabelCell lctype = s.findLabelCell("Type");                 

int columns = s.getColumns();          

   int rows = s.getRows();         

      System.out.println("col -->>> "+columns+"  rows -->>> "+rows);  


To print the data


String data;     

  for(int col = 0;col < columns;col++)         {             for(int row = 0;row < rows;row++)             {                data = s.getCell(col, row).getContents();   

       // Code to display ....   

       }  

 

 

(OR)

 

 

Navigate to this url's

http://poi.apache.org/index.html 

 http://www.coderanch.com/t/465901/JDBC/databases/insert-data-excel-file-java

http://www.ibm.com/developerworks/library/x-jxmlexl/index.html 

http://www.avajava.com/tutorials/lessons/how-do-i-read-from-an-excel-file-using-poi.html?page=1 

http://mrbool.com/reading-excel-file-with-java/24562 

18 comments:

  1. I simply want to say I’m very new to blogs and actually loved you’re blog site. Almost certainly I’m going to bookmark your blog post . You absolutely come with great well written articles. Thanks a lot for sharing your blog.

    Online Training in Chennai

    ReplyDelete
  2. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
    AWS Training in Chennai |Best Amazon Web Services Training in Chennai
    Learn Amazon Web Services Tutorial |AWS Tutorials For Beginners
    AWS Interview Questions And Answers
    AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR

    ReplyDelete
  3. Nice blog..! I really loved reading through this article. Thanks for sharing such
    a amazing post with us and keep blogging...Well written article Thank You for Sharing with Us project management courses in chennai | pmp training class in chennai | pmp training fee | project management training certification | project management training in chennai

    ReplyDelete
  4. Great Information
    Yaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
    Best video editing services in Hyderabad,ameerpet
    Best Graphic Designing services in Hyderabad,ameerpet­
    Best Ad Making services in Hyderabad,ameerpet­

    ReplyDelete
  5. Myself so glad to establish your blog entry since it's actually quite instructive. If it's not too much trouble continue composing this sort of web journals and I normally visit this blog. Examine my administrations.
    sap training in chennai

    sap training in tambaram

    azure training in chennai

    azure training in tambaram

    cyber security course in chennai

    cyber security course in tambaram

    ethical hacking course in chennai

    ethical hacking course in tambaram

    ReplyDelete
  6. SSC Coaching
    SSC Coaching
    Best SSC Coaching in Jaipur
    Best Coaching For SSC
    Best Coaching For SSC in Jaipur
    Best SSC Coaching
    Top SSC Coaching In Jaipur

    SSC CGL Coaching
    SSC CGL Coaching in Jaipur
    Best SSC CGL Coaching
    Best SSC CGL Coaching in jaipur
    Best Coaching For SSC CGL in Jaipur
    Best Coaching For SSC CGL

    Bank Coaching
    Bank Coaching in Jaipur
    Best Bank Coaching In Jaipur
    Best Bank Coaching
    Best Coaching For Bank
    Best Coaching For Bank In Jaipur

    Bank PO Coaching
    Bank PO Coaching In Jaipur
    Best Bank PO Coaching
    Best Bank PO Coaching In

    ReplyDelete
  7. I get a lot of great information from this blog. Thank you for your sharing this informative blog. Just now I have completed Selenium Training at iClass Gyansetu

    ReplyDelete
  8. I appreciate the effort you put into creating this detailed and useful article.microsoft devops course

    ReplyDelete
  9. I was looking for power bi live training that included interactive sessions, and OnlineITGuru seems to provide exactly that. Learning directly from experienced trainers makes it easier to understand complex concepts.power bi live training

    ReplyDelete
  10. Tableau Online Training is an excellent option for anyone interested in learning modern data visualization techniques. The best training programs combine theory with practical implementation, allowing learners to create interactive dashboards and meaningful reports. With growing demand for Tableau professionals, quality online training can open doors to exciting career opportunities.tableau online training

    ReplyDelete
  11. Learning Tableau through practical examples can make a big difference, especially for beginners. This article provides some helpful direction for anyone considering tableau online training to improve their dashboard and reporting skills. Thanks for sharing.tableau online training

    ReplyDelete
  12. Oracle OSB online training helps learners develop practical skills in enterprise service integration using Oracle Service Bus. This oracle osb online training covers proxy services, business services, message routing, pipelines, transformations, and deployment. Students gain hands-on experience through real-time projects and practical assignments.

    ReplyDelete