s'il vous plait je n'arrive pas à stocker les informations dans la chaine des idées
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Iterator; 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; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.util.CellReference; import org.apache.poi.hssf.usermodel.HSSFCell; public class Readxls { public static void main(String[] args) { try { InputStream input=new FileInputStream("tes.xls"); HSSFWorkbook wb = new HSSFWorkbook(input); HSSFSheet sheet = wb.getSheetAt(0); Iterator<Row> rowIterator = (sheet).rowIterator(); while(rowIterator.hasNext()) { HSSFRow row = (HSSFRow) rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); while(cellIterator.hasNext()) { HSSFCell cell = (HSSFCell) cellIterator.next(); String[] values = new String[row.getPhysicalNumberOfCells()]; int i=0,j=0 ; switch(cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: System.out.print(cell.getBooleanCellValue() + ";"); break; case Cell.CELL_TYPE_NUMERIC: // System.out.print(cell.getNumericCellValue() + ";"); values[i++]=Integer.toString((int) cell.getNumericCellValue()); System.out.print(values); break; case Cell.CELL_TYPE_STRING: // System.out.print(cell.getStringCellValue() + ";"); values[i++] = cell.getStringCellValue(); System.out.print(values); break; } } System.out.println(""); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }}}
Partager