1

I have the following code to convert a JSON file to XML, first the conversion from the XLS file to JSON is performed, then JSON to XML, the code works for basic structures of excel files, when I try to convert a file that contains more information the Output when converting the file is as follows: <__EMPTY> header information </__EMPTY>, I am capturing the data from excel, but the header information is always empty, it should print something like this drmakigero </ name >, I attach my code with great respect, I am a bad programmer, I hope you can help me, greetings.

//xlsx a json
var XLSX = require("xlsx");
let jDatos = [];

let ExcelAJSON = () => {
  let excel = XLSX.readFile(
    "C:\\test.xlsx"
  );
  var nombreHoja = excel.SheetNames;
  let datos = XLSX.utils.sheet_to_json(excel.Sheets[nombreHoja[0]]);

  
 for (let i = 0; i < datos.length; i++) {
    let dato = datos[i];
    jDatos.push({ 
      ...dato,
    });
    //console.log(dato.__EMPTY);
  }
console.log(jDatos);
};

ExcelAJSON();

//json to xml
var xml2js = require('xml2js');
var builder =  new xml2js.Builder({
  trim: true,
  

});

jDatos1 = builder.buildObject(jDatos)
//console.log(jDatos1);

//guardar archivo con el strg creado
var fs = require('fs');
fs.writeFile('salida.xml',jDatos1, function (err) {
  if (err) throw err;
  console.log('Archivo Guardado');
});
Anatoly
  • 20,799
  • 3
  • 28
  • 42

0 Answers0