Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: org.apache.poi.xssf.usermodel.XSSFCell;

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default org.apache.poi.xssf.usermodel.XSSFCell;

    can any one suggest me which jar files support import org.apache.poi.xssf.usermodel.XSSFCell;
    in my application i need to insert xlsx file data into sql database
    here i am getting error as ---org.apache.poi.poifs.filesystem.OfficeXmlFileExcep tion: The supplied data appears to be in the Office 2007+ XML. POI only supports OLE2 Office documents

    here my code is
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.util.regex.*;
    import org.apache.poi.hssf.usermodel.*;
    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 ; 
    import org.apache.poi.ss.usermodel.*;
    import java.text.*;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
     
    public class insertdata {
    public static void main( String [] args ) {
      String fileName="C:\\file.xlsx";
      Vector dataHolder=read(fileName);
      saveToDatabase(dataHolder);
    }
      public static Vector read(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 saveToDatabase(Vector dataHolder) 
      {
              String USERID="";
              String FIRST_NAME="";
              String LAST_NAME="";
              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 st = myCell.toString();
                              USERID=st.substring(0,1);
                              FIRST_NAME=st.substring(0);
                              LAST_NAME=st.substring(0);
                                                      }
                      try{
                           Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
                           Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.1.222:1433/database1","sa","admin");
                           Statement stat=con.createStatement();
                           int k=stat.executeUpdate("insert into empdata(USERID,FIRST_NAME,LAST_NAME) value('"+USERID+"','"+FIRST_NAME+"','"+LAST_NAME+"')");
                            System.out.println("Data is inserted");
                            stat.close();
                            con.close();
                          }
                          catch(Exception e){}
      }
      }
    }

    reply me ASAP

  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: org.apache.poi.xssf.usermodel.XSSFCell;

    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member madelarbo's Avatar
    Join Date
    Jul 2011
    Location
    Muntinlupa City
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: org.apache.poi.xssf.usermodel.XSSFCell;

    i have a sample cpde for this =) i can read EXCEL FILE.. and it is simple like the other one...and it is shorter and i read mutiple file in one run =)

  4. #4
    Junior Member madelarbo's Avatar
    Join Date
    Jul 2011
    Location
    Muntinlupa City
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: org.apache.poi.xssf.usermodel.XSSFCell;

    try using HIBERNATE ANNOTATION.. it is simple. and oraganize =)