voici le contenu de notre fichier excel
code | nom | prenom | |
123 | swissi | ramzi | |
563 | benfarhat | mehdi | |
9875 | test | test | |
563 | tounsi | ahmed |
Voici le code pour lire ce fichier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Parseur1 { | |
public static void main(String[] args) { | |
try { | |
File fichier = new File("person.xls"); | |
// Lecture du fichier excel | |
InputStream inp = new FileInputStream(fichier); | |
// recupère le fichier excel | |
HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(inp)); | |
// Recupére page 1 du fichier xls | |
HSSFSheet sheet = wb.getSheetAt(0); | |
// nombre de ligne | |
int nbLigneFichier = sheet.getPhysicalNumberOfRows(); | |
int nombreDeCelluleMax = 0; | |
for (int ligne = 0; ligne < nbLigneFichier; ligne++) { | |
// recuperation de chaque ligne | |
HSSFRow row = sheet.getRow(ligne); | |
// si la ligne contient au moins une cellule | |
if (row != null) { | |
if (row.getPhysicalNumberOfCells() > nombreDeCelluleMax) | |
nombreDeCelluleMax = row.getPhysicalNumberOfCells(); | |
String code = row.getCell(0).toString(); | |
System.out.println("------code---------> " + code); | |
String nom = "" + row.getCell(1).toString(); | |
System.out.println("-------nom--------> " + nom); | |
String prenom = row.getCell(2).toString(); | |
System.out.println("-------prenom--------> " + prenom); | |
} | |
} | |
inp.close(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
https://www.youtube.com/watch?v=WcPyH40OTRY
ReplyDelete