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
| private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
FileInputStream inputStream = new FileInputStream(new File("CHEMIN"));
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
Row row = rowIterator.next();
Row row1 = rowIterator.next();
Row row2 = rowIterator.next();
//Jusqu'à row64 car 64 lignes de données à récupérer...
String param1 = (String) row.getCell(1).getStringCellValue();
jLabel1.setText(param1);
dtParam1 = param1;
int nomComplet = (int) row.getCell(2).getNumericCellValue();
eDT1 = Integer.toString(nomComplet);
jTextField1.setText(eDT1);
String param2 = (String) row1.getCell(1).getStringCellValue();
jLabel2.setText(param2);
dtParam2 = param2;
int nomComplet1 = (int) row1.getCell(2).getNumericCellValue();
eDT1 = Integer.toString(nomComplet1);
jTextField2.setText(eDT1);
String param3 = (String) row2.getCell(1).getStringCellValue();
jLabel3.setText(param3);
dtParam3 = param3;
int nomComplet2 = (int) row2.getCell(2).getNumericCellValue();
eDT2 = Integer.toString(nomComplet2);
jTextField3.setText(eDT2);
//Tout ça pour 64 données, avec deux valeurs par ligne à chaque fois dont une en int et une en String
} catch (FileNotFoundException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document xml = builder.newDocument(); //Création du fichier
Element root = xml.createElement("conf"); //Création de notre élément racine
Element param = xml.createElement("param");
Element param1 = xml.createElement("param");
Element param2 = xml.createElement("param");
//jusqu'à Element param64
root.appendChild(param);
root.appendChild(param1);
root.appendChild(param2);
//jusqu'à root.appendChild(param64);
dt1 = jTextField1.getText();
dt2 = jTextField2.getText();
//jusqu'à dt64
param.setAttribute("id", "0");
param.setAttribute("name", dtParam1);
param.setAttribute("value", dt1);
param1.setAttribute("id", "1");
param1.setAttribute("name", dtParam2);
param1.setAttribute("value", dt2);
//Jusqu'à param64
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty(OutputKeys.VERSION, "1.0");
// appliquer la transformation
String resultFile = "test.conf";
StreamResult XML = new StreamResult(resultFile);
t.transform(new DOMSource(root), XML);
} catch (DOMException | ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException abc) {
}
} |
Partager