How to use the xlsx.writeFile function in xlsx

To help you get started, we’ve selected a few xlsx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ssuperczynski / ngx-easy-table / src / app / demo / exports / exports.component.ts View on Github external
exportToExcel(): void {
    try {
      /* generate worksheet */
      const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(this.data);

      /* generate workbook and add the worksheet */
      const wb: XLSX.WorkBook = XLSX.utils.book_new();
      XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');

      /* save to file */
      XLSX.writeFile(wb, 'file.xlsx');
    } catch (err) {
      console.error('export error', err);
    }
  }
github Raoul1996 / egg-xlsx / utils / koasub.js View on Github external
function get_file(file) {
  const wb = make_book();
  /* write using XLSX.writeFile */
  XLSX.writeFile(wb, file);
  process.send('wrote to ' + file + '\n');
}
github laoqiren / excel-class / index.js View on Github external
workbook = {
                        SheetNames: [...new Set(excel.SheetNames)],
                        Sheets: Object.assign(excel.Sheets,{
                            [sheetName]: Object.assign({},{'!ref':ref},newSheet)
                        })
                    }
                } else {
                    workbook = {
                        SheetNames: [sheetName],
                        Sheets: {
                            [sheetName]: Object.assign({},{'!ref':ref},newSheet)
                        }
                    }
                }
                try {
                    XLSX.writeFile(workbook,this.excel)
                } catch(err){
                    if(err){
                        console.error(err)
                        reject();
                    }
                }
                resolve();
                console.log('写入excel表格成功!')
            });
        })
github digplan / json2xlsx / json2xlsx.js View on Github external
var wb = fs.existsSync(filename) ? xlsx.readFile(filename) : new Workbook();

    for (ws_name in o) {
      var sheetdispname = sheetname || ws_name;
      var twodarr = o[ws_name];
      if (!twodarr[0]) continue;

      wb.SheetNames.push(sheetdispname);
      if (!twodarr[0].push)
        twodarr = convertObjArray(twodarr);
      var ws = sheet_from_array_of_arrays(twodarr);
      wb.Sheets[sheetdispname] = ws;
      if (process.env.debug)
        console.log(filename, '/', sheetdispname);
    }
    xlsx.writeFile(wb, filename);
  }
github SheetJS / sheetjs / types / doc.ts View on Github external
const write_opts: XLSX.WritingOptions = {
	type: "buffer",
	cellDates: false,
	bookSST: false,
	bookType: "xlsx",
	sheet: "Sheet1",
	compression: false,
	Props: {
		Author: "Someone",
		Company: "SheetJS LLC"
	}
};

const wb1 = XLSX.readFile("sheetjs.xls", read_opts);
XLSX.writeFile(wb1, "sheetjs.new.xlsx", write_opts);

read_opts.type = "binary";
const wb2 = XLSX.read("1,2,3\n4,5,6", read_opts);
write_opts.type = "binary";
const out2 = XLSX.write(wb2, write_opts);

read_opts.type = "buffer";
const wb3 = XLSX.read(fs.readFileSync("sheetjs.xlsx"), read_opts);
write_opts.type = "base64";
const out3 = XLSX.write(wb3, write_opts);
write_opts.type = "array";
const out4 = XLSX.write(wb3, write_opts);

const ws1 = XLSX.utils.aoa_to_sheet([
    "SheetJS".split(""),
    [1,2,3,4,5,6,7],
github protobi / workbook / example.js View on Github external
]).mergeCells("Main", {
      "s": {"c": 0, "r": 0 },
      "e": {"c": 2, "r": 0 }
    })
    .setColWidthChars('Main', 1,72)
    .finalize();

//workbook.Sheets['Main']['!cols']=[{wch:24}]

var OUTFILE = '/tmp/wb.xlsx';
var OUTFILE1 = '/tmp/wb1.xlsx';
XLSX.writeFile(workbook, OUTFILE);
console.log("Results written to " + OUTFILE)

var workbook1 = XLSX.readFile(OUTFILE, {cellStyles: true, cellNF: true});
XLSX.writeFile(workbook1, OUTFILE1);
console.log("Results written to " + OUTFILE1)
github bep713 / madden-franchise-editor / renderer / js / services / externalDataService.js View on Github external
});

    const data = table.records.map((record) => {
      return record._fields.map((field) => { return field._value; });
    });

    let wb = xlsx.utils.book_new();

    const ws = xlsx.utils.json_to_sheet([headers].concat(data), {
      'skipHeader': true
    });

    xlsx.utils.book_append_sheet(wb, ws);

    try {
      xlsx.writeFile(wb, options.outputFilePath);
    }
    catch (err) {
      reject(err);
    }

    resolve();
  });
};
github 417511458 / jbone / jbone-cms / jbone-cms-admin / src / libs / excel.js View on Github external
export const export_array_to_excel = ({key, data, title, filename, autoWidth}) => {
    const wb = XLSX.utils.book_new();
    const arr = json_to_array(key, data);
    arr.unshift(title);
    const ws = XLSX.utils.aoa_to_sheet(arr);
    if(autoWidth){
        auto_width(ws, arr);
    }
    XLSX.utils.book_append_sheet(wb, ws, filename);
    XLSX.writeFile(wb, filename + '.xlsx');
}
github apache / zeppelin / zeppelin-web-angular / src / app / visualizations / table / table-visualization.component.ts View on Github external
exportFile(type: 'csv' | 'xlsx', all = true) {
    const wb = utils.book_new();
    let ws: WorkSheet;
    if (all) {
      ws = utils.json_to_sheet(this.rows);
    } else {
      ws = utils.json_to_sheet(this.nzTable.data);
    }
    utils.book_append_sheet(wb, ws, 'Sheet1');
    writeFile(wb, `export.${type}`);
  }
github medialab / ricardo_data / importApp / src / utils / fileExporter.js View on Github external
case 'csv':
    default: {
      const csvString = csvFormatRows(array)
      file = new File(
        [csvString],
        `${fileName}.${ext}`,
        { type: 'text/csv;charset=utf-8' }
      )
      FileSaver.saveAs(file)
      break
    }
    case 'xlsx': {
      const sheet = XLSX.utils.aoa_to_sheet(array, {header});
      const wb = XLSX.utils.book_new();
      XLSX.utils.book_append_sheet(wb, sheet, 'SheetJS');
      XLSX.writeFile(wb, `${fileName}.${ext}`);
      break
    }
  }
}