How to use the xlsx.utils 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 MikeBild / excel-couchdb-import / lib / parse.js View on Github external
doc.sheets = sheetNames.map(sheetName => {
    const sheet = file.Sheets[sheetName];
    const data = XLSX.utils.sheet_to_json(sheet, {
      raw: true,
      cellText: false
    }); // jshint ignore:line
    const headers = data.length ? Object.keys(data) : [];
    return {
      name: sheetName,
      headers: headers,
      rows: data.map(x => {
        Object.keys(x)
          .map(y => [y, !x[y].split ? x : x[y].split(';;').filter(x => !!x)])
          .forEach(values => {
            if (values[1].length > 1) x[values[0]] = values[1];
          });
        return Object.assign({}, x, { $doc_type: sheetName });
      })
    };
github Neveryu / vue-cms / src / views / excel / upload-excel.vue View on Github external
getHeaderRow(sheet) {
        const headers = []
        const range = XLSX.utils.decode_range(sheet['!ref'])
        let C
        const R = range.s.r /* start in the first row */
        for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */
          var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] /* find the cell in the first row */
          var hdr = 'UNKNOWN ' + C // <-- replace with your desired default
          if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
          headers.push(hdr)
        }
        return headers
      }
    }
github uncleLian / vue-blog / src / page / index / children / excel / importExcel.vue View on Github external
get_header_row(sheet) {
            const headers = []
            const range = XLSX.utils.decode_range(sheet['!ref'])
            let C
            const R = range.s.r /* start in the first row */
            for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */
                var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] /* find the cell in the first row */
                var hdr = 'UNKNOWN ' + C // <-- replace with your desired default
                if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
                headers.push(hdr)
            }
            return headers
        },
        generateDate(header, body) {
github imaxue / progress / liao / upload-excel组件 / ExcelUpload.vue View on Github external
get_header_row (sheet) {
      const headers = []
      const range = XLSX.utils.decode_range(sheet['!ref'])
      let C
      const R = range.s.r /* start in the first row */
      for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */
        var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] /* find the cell in the first row */
        var hdr = 'UNKNOWN ' + C // <-- replace with your desired default
        if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
        headers.push(hdr)
      }
      return headers
    }
  }
github digplan / json2xlsx / json2xlsx.js View on Github external
e: {
        c: 0,
        r: 0
      }
    };
    for (var R = 0; R != data.length; ++R) {
      for (var C = 0; C != data[R].length; ++C) {
        if (range.s.r > R) range.s.r = R;
        if (range.s.c > C) range.s.c = C;
        if (range.e.r < R) range.e.r = R;
        if (range.e.c < C) range.e.c = C;
        var cell = {
          v: data[R][C]
        };
        if (cell.v == null) continue;
        var cell_ref = xlsx.utils.encode_cell({
          c: C,
          r: R
        });

        if (typeof cell.v === 'number') cell.t = 'n';
        else if (typeof cell.v === 'boolean') cell.t = 'b';
        else if (cell.v instanceof Date) {
          cell.t = 'n';
          cell.z = xlsx.SSF._table[14];
          cell.v = datenum(cell.v);
        } else cell.t = 's';

        ws[cell_ref] = cell;
      }
    }
    if (range.s.c < 10000000) ws['!ref'] = xlsx.utils.encode_range(range);
github kriskbx / gitlab-time-tracker / src / output / xlsx.js View on Github external
makeMergeRequests() {
        let mergeRequests = [];
        mergeRequests.push(this.config.get('mergeRequestColumns'));
        this.report.mergeRequests.forEach(mergeRequest => mergeRequests.push(this.prepare(mergeRequest, this.config.get('mergeRequestColumns'))));

        this.xlsxMergeRequests = XLSX.utils.aoa_to_sheet(mergeRequests);
    }
github briansd9 / exile-diary / search.html View on Github external
function exportToExcel() {
        
        logger.info("Exporting Excel file");
        
        var wb = XLSX.utils.book_new();

        var mapSheet = XLSX.utils.json_to_sheet(exportData.mapList.data);
        mapSheet["!cols"] = [];
        Object.keys(exportData.mapList.colWidths).forEach(key => {
          mapSheet["!cols"].push({ wch: exportData.mapList.colWidths[key] + 5 });
        });
        XLSX.utils.book_append_sheet(wb, mapSheet, "Maps");
        
        
        if(exportData.itemList) {
          var itemSheet = XLSX.utils.json_to_sheet(exportData.itemList.data);
          itemSheet["!cols"] = [];
          Object.keys(exportData.itemList.colWidths).forEach(key => {
            itemSheet["!cols"].push({ wch: exportData.itemList.colWidths[key] + 5 });
          });
          itemSheet["!autofilter"] = { ref: "C1:D" + (exportData.itemList.data.length + 1) };
          XLSX.utils.book_append_sheet(wb, itemSheet, "Items");
        }
github bep713 / madden-franchise-editor / renderer / js / services / externalDataService.js View on Github external
return new Promise((resolve, reject) => {
    if (!options) { reject('Invalid arguments. Please call .exportTableData with (options, FranchiseFileTable)'); }
    
    let headers = table.offsetTable.map((offset) => {
      return offset.name;
    });

    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 SheetJS / j / j.js View on Github external
function get_cols(sheet/*:Worksheet*/) {
	var val, r, hdr, R, C;
	hdr = [];
	if(!sheet["!ref"]) return hdr;
	r = X.utils.decode_range(sheet["!ref"]);
	for (R = r.s.r, C = r.s.c; C <= r.e.c; ++C) {
		val = sheet[X.utils.encode_cell({c:C, r:R})];
		if(val == null) continue;
		hdr[C] = val.w !== undefined ? val.w : X.utils.format_cell ? X.utils.format_cell(val) : val.v;
	}
	return hdr;
}
github HalitTalha / mat-table-extensions / dist / cdk-table-exporter / esm5 / lib / services / exporters / xls-exporter.service.js View on Github external
function (worksheet, options) {
        /** @type {?} */
        var workBook = XLSX.utils.book_new();
        if (!options) {
            options = (/** @type {?} */ ({}));
        }
        this.correctType(options);
        XLSX.utils.book_append_sheet(workBook, worksheet, options.sheet);
        return XLSX.write(workBook, options);
    };
    /**