List of usage examples for org.apache.poi.hssf.usermodel HSSFCell getRichStringCellValue
public HSSFRichTextString getRichStringCellValue()
From source file:tournoi.ExcelToBDD.java
public boolean insertJoueur(String filePath) { boolean flag = true; db = new DBConnection(); con = db.getConnection();/*from w w w . ja v a 2 s . c om*/ try { // ??excel FileInputStream fin = new FileInputStream(filePath); // HSSFWorkbook workbook = new HSSFWorkbook(fin);// HSSFSheet sheet = workbook.getSheetAt(0);// HSSFRow row = null;// excel HSSFCell cell = null; HSSFCell cell2 = null; HSSFCell cell3 = null; HSSFCell cell4 = null; HSSFCell cell5 = null; HSSFCell cell6 = null; HSSFCell cell7 = null; int totalRow = sheet.getLastRowNum();// excel? System.out.println(totalRow); // ? for (int i = 1; i <= totalRow; i++) { row = sheet.getRow(i); cell = row.getCell(0); int id_joueur = (int) cell.getNumericCellValue(); cell2 = row.getCell(1); String nom = cell2.getRichStringCellValue().toString(); cell3 = row.getCell(2); String prenom = cell3.getRichStringCellValue().toString(); cell4 = row.getCell(3); int national_point = (int) cell4.getNumericCellValue(); cell5 = row.getCell(4); String categorie = cell5.getRichStringCellValue().toString(); cell6 = row.getCell(5); String federation = cell6.getRichStringCellValue().toString(); cell7 = row.getCell(6); String ligne = cell7.getRichStringCellValue().toString(); //String sql = "INSERT INTO text1(ID,BM,AQ,CQ,DQ) VALUES (?,?,?,?,?)"; // " String sql = "INSERT INTO joueurs VALUES('" + id_joueur + "','" + nom + "','" + prenom + "','" + national_point + "','" + categorie + "','" + federation + "','" + ligne + "')"; pst = con.prepareStatement(sql); pst.execute(); System.out.println("Import rows " + i); } //con.commit(); fin.close(); System.out.println("Success import excel to mysql table"); } catch (FileNotFoundException e) { flag = false; System.out.println("MYSQL ERROR:" + e.getMessage()); } catch (IOException ex) { flag = false; System.out.println("MYSQL ERROR:" + ex.getMessage()); } catch (SQLException exx) { flag = false; System.out.println("MYSQL ERROR:" + exx.getMessage()); } finally { try { pst.close(); con.close(); } catch (SQLException e) { System.out.println("MYSQL ERROR:" + e.getMessage()); } } return flag; }
From source file:tournoi.ExcelToBDD.java
public boolean insertArbitre(String filePath) { boolean flag = true; db = new DBConnection(); con = db.getConnection();/*from w w w .j av a2s. c om*/ try { // ??excel FileInputStream fin = new FileInputStream(filePath); // HSSFWorkbook workbook = new HSSFWorkbook(fin); //Get the workbook instance for XLS file HSSFSheet sheet = workbook.getSheetAt(1);//Get first sheet from the workbook System.out.println(workbook.getSheetName(1)); HSSFRow row = null;// excel HSSFCell cell = null; HSSFCell cell2 = null; HSSFCell cell3 = null; int totalRow = sheet.getLastRowNum();// excel? System.out.println(totalRow); // ? for (int i = 1; i <= totalRow; i++) { row = sheet.getRow(i); cell = row.getCell(0); int id_arbitre = (int) cell.getNumericCellValue(); cell2 = row.getCell(1); String nom = cell2.getRichStringCellValue().toString(); cell3 = row.getCell(2); String prenom = cell3.getRichStringCellValue().toString(); // cell4 = row.getCell(3); // int national_point = (int) cell4.getNumericCellValue(); // cell5 = row.getCell(4); // String categorie = cell5.getRichStringCellValue().toString(); //String sql = "INSERT INTO text1(ID,BM,AQ,CQ,DQ) VALUES (?,?,?,?,?)"; // " String sql = "INSERT INTO arbitres VALUES('" + id_arbitre + "','" + nom + "','" + prenom + "')"; pst = con.prepareStatement(sql); pst.execute(); System.out.println("Import rows " + i); } //con.commit(); fin.close(); System.out.println("Success import excel to mysql table"); } catch (FileNotFoundException e) { flag = false; System.out.println("MYSQL ERROR:" + e.getMessage()); } catch (IOException ex) { flag = false; System.out.println("MYSQL ERROR:" + ex.getMessage()); } catch (SQLException exx) { flag = false; System.out.println("MYSQL ERROR:" + exx.getMessage()); } finally { try { pst.close(); con.close(); } catch (SQLException e) { System.out.println("MYSQL ERROR:" + e.getMessage()); } } return flag; }
From source file:tournoi.ExcelToBDD.java
public boolean insertJoueur(String filePath, String table) { boolean flag = true; db = new DBConnection(); con = db.getConnection();//from w w w . j a v a 2 s. com try { // ??excel FileInputStream fin = new FileInputStream(filePath); HSSFWorkbook workbook = new HSSFWorkbook(fin);// HSSFSheet sheet = workbook.getSheetAt(0);// HSSFRow row = null;// excel HSSFCell cell = null; HSSFCell cell2 = null; HSSFCell cell3 = null; HSSFCell cell4 = null; HSSFCell cell5 = null; HSSFCell cell6 = null; HSSFCell cell7 = null; int totalCol = sheet.getDefaultColumnWidth();// obtenir le nbr de column for (int i = 1; i <= totalCol; i++) { } int totalRow = sheet.getLastRowNum();// excel? System.out.println(totalRow); // ? for (int i = 1; i <= totalRow; i++) { row = sheet.getRow(i); cell = row.getCell(0); int id_joueur = (int) cell.getNumericCellValue(); cell2 = row.getCell(1); String nom = cell2.getRichStringCellValue().toString(); cell3 = row.getCell(2); String prenom = cell3.getRichStringCellValue().toString(); cell4 = row.getCell(3); int national_point = (int) cell4.getNumericCellValue(); cell5 = row.getCell(4); String categorie = cell5.getRichStringCellValue().toString(); cell6 = row.getCell(5); String federation = cell6.getRichStringCellValue().toString(); cell7 = row.getCell(6); String ligne = cell7.getRichStringCellValue().toString(); //String sql = "INSERT INTO text1(ID,BM,AQ,CQ,DQ) VALUES (?,?,?,?,?)"; // " String sql = "INSERT INTO joueurs VALUES('" + id_joueur + "','" + nom + "','" + prenom + "','" + national_point + "','" + categorie + "','" + federation + "','" + ligne + "')"; pst = con.prepareStatement(sql); pst.execute(); System.out.println("Import rows " + i); } //con.commit(); fin.close(); System.out.println("Success import excel to mysql table"); } catch (FileNotFoundException e) { flag = false; System.out.println("MYSQL ERROR:" + e.getMessage()); } catch (IOException ex) { flag = false; System.out.println("MYSQL ERROR:" + ex.getMessage()); } catch (SQLException exx) { flag = false; System.out.println("MYSQL ERROR:" + exx.getMessage()); } finally { try { pst.close(); con.close(); } catch (SQLException e) { System.out.println("MYSQL ERROR:" + e.getMessage()); } } return flag; }
From source file:ubic.basecode.io.excel.ExcelUtil.java
License:Apache License
/** * @param sheet//from w w w . ja v a 2 s. c om * @param row * @param col * @return */ public static String getValue(HSSFSheet sheet, int row, int col) { if (col > 255) { throw new RuntimeException("Column position is over 255"); } if (sheet.getRow(row) == null) return null; HSSFCell cell = sheet.getRow(row).getCell(col); if (cell == null) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_STRING) return cell.getRichStringCellValue().getString(); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { // WARNING not ideal for numbers. return Double.toString(cell.getNumericCellValue()); } if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) return cell.getCellFormula(); return ""; }
From source file:util.read.java
private static Hashtable showExelData(List sheetData) { Hashtable<String, Integer> h = new Hashtable<String, Integer>(); int x = 0;/*from ww w. ja va 2 s. c o m*/ for (int i = 0; i < sheetData.size(); i++) { List list = (List) sheetData.get(i); for (int j = 0; j < list.size(); j++) { HSSFCell cell = (HSSFCell) list.get(j); //System.out.print(cell.getRichStringCellValue().getString()); String k = cell.getRichStringCellValue().getString(); h.put(k, x); x++; } //System.out.println(h); } return h; }
From source file:util.read1.java
private static ArrayList showExelData(List sheetData) { ArrayList<bean> a = new ArrayList<bean>(); int[][] m = new int[10][10]; int x = 0;//from w w w . java 2 s .c om for (int i = 0; i < sheetData.size(); i++) { List list = (List) sheetData.get(i); HSSFCell cell1 = (HSSFCell) list.get(0); HSSFCell cell2 = (HSSFCell) list.get(1); HSSFCell cell3 = (HSSFCell) list.get(2); HSSFCell cell4 = (HSSFCell) list.get(3); HSSFCell cell5 = (HSSFCell) list.get(4); bean b = new bean(); b.setTransport(cell1.getRichStringCellValue().getString()); b.setFromcity(cell2.getRichStringCellValue().getString()); b.setTocity(cell3.getRichStringCellValue().getString()); // b.setCost(cell4.getRichStringCellValue().getString()); int c = (int) cell4.getNumericCellValue(); b.setCost(c); int t = (int) cell5.getNumericCellValue(); b.setTime(t); a.add(b); } return a; }