| 12
 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
 
 |  
public static void WriteInFile(String templateFile, String destinationPath) throws SQLException, InvalidFormatException, IOException {
 
 
		String query0 = "SELECT * FROM MATABLE";
		PreparedStatement stmt0 = DatabaseManager.getConnection().prepareStatement(query0);
		ResultSet rs0 = stmt0.executeQuery();
 
		OutputStream output = null;
 
		try {
 
			InputStream filetemplate = new FileInputStream(new File(templateFile));
 
			output = new FileOutputStream(destinationPath + "template.xlsx");
			byte[] buf = new byte[1024];
			int bytesRead;
			while ((bytesRead = filetemplate.read(buf)) > 0) {
				output.write(buf, 0, bytesRead);
			}
		} catch (FileNotFoundException e){
			HMI.printConsole(e.toString(), 0);
		}
 
		finally {
			output.close();
		}
 
		XSSFWorkbook wb = new XSSFWorkbook(destinationPath + "template.xlsx");
 
		Sheet sh = wb.getSheetAt(0);
 
		int i =10;
		while (rs0.next()) {
 
 
			sh.createRow(i);
 
			Row row1 = sh.getRow(i);
			Cell c0 = row1.createCell(0);
			Cell c1 = row1.createCell(1);
			Cell c2 = row1.createCell(2);
			Cell c3 = row1.createCell(3);
			Cell c4 = row1.createCell(4);
 
			c0.setCellValue(rs0.getString(1));
			c1.setCellValue(rs0.getString(2));
			c2.setCellValue(rs0.getString(3));
			c3.setCellValue(rs0.getString(4));
			c4.setCellValue(rs0.getString(5));
 
			i++;
		}
		// Ecriture et Fermeture du fichier cree
		FileOutputStream out = new FileOutputStream(destinationPath + "FichierDeSortie" + ".xlsx");
		wb.write(out);
		out.close();
 
	} | 
Partager