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