Good I have a problem in a code of java that I have with these two class when writing in the file it is eliminated what I had before somebody knows some solution not to overwrite the excel file in java, thanks and a greeting.
dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();
//comprobamos el usuario para poder leer el xml desde el servidor
comprobarusu();
HSSFWorkbook a = archivoexcel();
HSSFSheet hoja = a.createSheet("LOGSSample");
String id = "";
try {
dom = db.parse(ruta);
} catch (SAXException | IOException ex) {
Logger.getLogger(SacarLogs.class.getName()).log(Level.SEVERE, null, ex);
}
org.w3c.dom.Element rootElement = dom.getDocumentElement();
org.w3c.dom.NodeList nodeList = rootElement.getElementsByTagName("httpSample");
if (nodeList != null && nodeList.getLength() > 0) {
for (int i = 0; i < nodeList.getLength(); i++) {
HSSFRow filacabe = hoja.createRow(0);
HSSFCell celdaca = filacabe.createCell((short) 0);
HSSFCell celda2ca = filacabe.createCell((short) 1);
HSSFCell celda3ca = filacabe.createCell((short) 2);
HSSFCell celda4ca = filacabe.createCell((short) 3);
HSSFCell celda5ca = filacabe.createCell((short) 4);
HSSFCell celda6ca = filacabe.createCell((short) 5);
celdaca.setCellValue("Nombre test");
celda2ca.setCellValue("MENSAJE");
celda3ca.setCellValue("MENSAJE");
celda4ca.setCellValue("Entorno");
celda5ca.setCellValue("Hora");
celda6ca.setCellValue("FECHA");
HSSFRow fila = hoja.createRow(i + 1);
HSSFCell celda = fila.createCell((short) 0);
HSSFCell celda2 = fila.createCell((short) 1);
HSSFCell celda3 = fila.createCell((short) 2);
HSSFCell celda4 = fila.createCell((short) 3);
HSSFCell celda5 = fila.createCell((short) 4);
HSSFCell celda6 = fila.createCell((short) 5);
celda4.setCellValue(entorno);
celda5.setCellValue(hora);
celda6.setCellValue(fecha);
org.w3c.dom.Element element = (Element) nodeList.item(i);
if (element.hasAttribute("lb")) {
id = element.getAttribute("lb");
}
HSSFRichTextString texto = new HSSFRichTextString(id);
celda.setCellValue(texto);
String rm1 = "";
if (element.hasAttribute("rm")) {
rm1 = element.getAttribute("rm");
}
HSSFRichTextString nofail = new HSSFRichTextString(rm1);
celda3.setCellValue(nofail);
org.w3c.dom.NodeList nodeList2 = element.getElementsByTagName("assertionResult");
if (nodeList2 != null && nodeList2.getLength() > 0) {
for (int j = 0; j < nodeList2.getLength(); j++) {
org.w3c.dom.NodeList nodeList3 = element.getElementsByTagName("failureMessage");
if (nodeList3 != null && nodeList3.getLength() > 0) {
Node nodo = nodeList3.item(j);
if (nodo.getNodeName().equalsIgnoreCase("failureMessage") && nodo.getTextContent() != null) {
HSSFRichTextString mensajefallo = new HSSFRichTextString(nodo.getTextContent());
celda2.setCellValue(mensajefallo);
}
if (nodo.getTextContent().getBytes().length == 0) {
String rm = "";
if (element.hasAttribute("rm")) {
rm = element.getAttribute("rm");
}
HSSFRichTextString nomensajefallo = new HSSFRichTextString(rm);
celda2.setCellValue(nomensajefallo);
}
}
}
}
archivo(a, nombrearchivo);
File method
public void archivo(HSSFWorkbook file, String nombrearchivo) {
try {
File af = new File("C:\Users\l.cabota\Desktop\logs\logs\" + nombrearchivo + ".xls");
try (FileOutputStream elFichero = new FileOutputStream("C:\Users\l.cabota\Desktop\logs\logs\" + nombrearchivo + ".xls")) {
file.write(elFichero);
}
} catch (IOException e) {
}
}