Apache poi

punto85 Messages postés 8 Statut Membre -  
punto85 Messages postés 8 Statut Membre -
Bonjour
qui sait comment utiliser Apache Poi?
mon but est de créer un programme qui extrait les données des cellules d'un tableaux excel et de les intégrer dans la base de données(ou plutôt dans un data-table).
quelqu'un pourrais me donner le code qui me permette de faire ce genre de programme sachant que j'ai déjà un tableau excel avec plusieurs données.
Merci d'avance.

4 réponses

  1. sakoba2010 Messages postés 165 Statut Membre 15
     
    Pourquoi avez vous besoin d'un autre code?
    0
    1. punto85 Messages postés 8 Statut Membre
       
      Voila le genre de code que j'ai fais:

      package testpoi2;

      import Model.Opcvm;
      import java.io.FileInputStream;
      import java.util.Iterator;
      import org.apache.poi.hssf.usermodel.HSSFCell;
      import org.apache.poi.hssf.usermodel.HSSFRow;
      import org.apache.poi.hssf.usermodel.HSSFSheet;
      import org.apache.poi.hssf.usermodel.HSSFWorkbook;
      import org.apache.poi.poifs.filesystem.POIFSFileSystem;

      public class testpoi3 {

      public static void main(String[] args) {

      String fileName = "C:\\Users\\BILO\\Desktop\\BNS\\sicavtest.xls";
      HSSFCell[][] cellHolder = ReadExcel(fileName);




      //
      }

      public static HSSFCell[][] ReadExcel(String fileName) {
      String[][] HSSFCell = new String[1000][1000];
      HSSFCell[][] cellHolder = new HSSFCell[1000][1000];
      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();
      int i = 0;
      while (rowIter.hasNext()) {
      int j = 0;
      HSSFRow myRow = (HSSFRow) rowIter.next();
      Iterator cellIter = myRow.cellIterator();
      while (cellIter.hasNext()) {
      Opcvm o = new Opcvm();
      HSSFCell myCell = (HSSFCell) cellIter.next();
      cellHolder[i][j] = myCell;
      j++;

      if ((j == 1) && myCell.getCellType() == myCell.CELL_TYPE_NUMERIC) {
      o.setIdopcvm(myCell.toString());
      o.getIdopcvm();
      continue;
      } else if ((j == 1 || j == 2) && myCell.getCellType() == myCell.CELL_TYPE_STRING) {
      o.setDenomination(myCell.getStringCellValue());
      continue;

      } else if ((j == 3) && myCell.getCellType() == myCell.CELL_TYPE_STRING) {
      o.setGestionnaire(myCell.getStringCellValue());

      continue;
      } else if ((j == 4) && myCell.getCellType() == myCell.CELL_TYPE_NUMERIC) {
      o.setDouverture(myCell.getDateCellValue());
      continue;
      } else if ((j == 5) && myCell.getCellType() == myCell.CELL_TYPE_NUMERIC) {
      o.setVldebutannee((float)myCell.getNumericCellValue());
      System.out.println(o);
      continue;

      }

      }
      i++;
      }
      } catch (Exception e) {
      e.printStackTrace();
      }
      return cellHolder;

      }
      }


      et ça ne me permet pas d'extraire tout les cellules.
      peux tu me donner ton avis?
      0
  2. punto85 Messages postés 8 Statut Membre
     
    C bon j'ai trouvé
    Merci sakoba2010
    0
  3. punto85 Messages postés 8 Statut Membre
     
    est ce que tu pourrait me faire un autre code sachant que j'ai déja un fichier excel nommé "Test2" dans le repertoire "C:\test"
    -1