bonjour
je ne sais pas comment stocker la chaine dans le fichier et merci pour votre aide
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; 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) throws FileNotFoundException { try { InputStream input=new FileInputStream("C:\\classeur1.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()) { File fil =new File ("t4.txt"); try { FileWriter fw = new FileWriter (fil); BufferedWriter bw = new BufferedWriter (fw); PrintWriter fichierSortie = new PrintWriter (bw); HSSFCell cell = (HSSFCell) cellIterator.next(); String[] values = new String[row.getPhysicalNumberOfCells()]; int i=0 ; switch(cell.getCellType()) { case Cell.CELL_TYPE_BLANK: System.out.print(" "+";"); fichierSortie.println (" "+";"); break; 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[0]+";"); fichierSortie.println (values[0]+";"); break; case Cell.CELL_TYPE_STRING: //System.out.print(cell.getStringCellValue() + ";"); values[i++] = cell.getStringCellValue(); System.out.print(values[0]+";"); fichierSortie.println (values[0]+";"); break; } fichierSortie.close();} catch (Exception e){ System.out.println(e.toString()); System.out.println(""); }} //creation et ecriture dans le fichier /*File fil =new File ("t4.txt"); try { FileWriter fw = new FileWriter (fil); BufferedWriter bw = new BufferedWriter (fw); PrintWriter fichierSortie = new PrintWriter (bw); fichierSortie.println ( values[0]); fichierSortie.close();} //System.out.println("Le fichier " + fil + " a été créé!"); catch (Exception e){ System.out.println(e.toString()); System.out.println(""); }*/ System.out.println(""); }} catch (FileNotFoundException e) { //e.printStackTrace(); System.out.println(e.toString()); } catch (IOException e) { e.printStackTrace(); } }}
Partager