How to use the xlsx.utils.json_to_sheet 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 HalitTalha / mat-table-extensions / dist / cdk-table-exporter / fesm5 / cdk-table-exporter.js View on Github external
function (rows, options) {
        if (!rows) {
            throw new Error('Empty json array is provided, rows parameter is mandatory!');
        }
        /** @type {?} */
        var worksheet = utils.json_to_sheet(rows, {
            skipHeader: true // we don't want to see object properties as our headers
        });
        this.writeToFile(worksheet, options);
    };
    /**
github danielwii / asuna-node-server / src / modules / import-export / import-export.service.ts View on Github external
async exportModel(tableName: string) {
    const repository = await this.getRepository(tableName);
    const schemas = await this.getSchemas(repository);
    const json = [];
    schemas.forEach(value => {
      const temp = [];
      temp[value.config.info.name] = null;
      json.push(temp);
    });
    const ss = utils.json_to_sheet(json); // 通过工具将json转表对象
    // const keys = Object.keys(ss).sort(); // 排序 [需要注意,必须从A1开始]
    // 构建 workbook 对象
    const workbook = {
      // 定义 作文档
      SheetNames: ['sheet1'], // 定义表明
      Sheets: {
        sheet1: { ...ss, }, // 表对象[注意表明]
      },
    };
    const buf = write(workbook, { type: 'buffer', bookType: 'xlsx' });
    return buf;
  }
}
github HalitTalha / mat-table-extensions / dist / cdk-table-exporter / fesm2015 / cdk-table-exporter.js View on Github external
export(rows, options) {
        if (!rows) {
            throw new Error('Empty json array is provided, rows parameter is mandatory!');
        }
        /** @type {?} */
        const worksheet = utils.json_to_sheet(rows, {
            skipHeader: true // we don't want to see object properties as our headers
        });
        this.writeToFile(worksheet, options);
    }
    /**
github danielwii / asuna-node-server / src / modules / import-export / import-export.service.ts View on Github external
exportExcel(json: any[]): any {
    const ss = utils.json_to_sheet(json); // 通过工具将json转表对象'
    const keys = Object.keys(ss).sort(); // 排序 [需要注意,必须从A1开始]
    // 构建 workbook 对象
    const workbook = {
      // 定义 作文档
      SheetNames: ['sheet1'], // 定义表明
      Sheets: {
        sheet1: { ...ss, }, // 表对象[注意表明]
      },
    };
    const buf = write(workbook, { type: 'buffer', bookType: 'xlsx' });
    return buf;
  }
github n8n-io / n8n / packages / nodes-base / nodes / SpreadsheetFile.node.ts View on Github external
return this.prepareOutputData(newItems);
		} else if (operation === 'toFile') {
			// Write the workflow data to spreadsheet file
			const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string;
			const fileFormat = this.getNodeParameter('fileFormat', 0) as string;
			const options = this.getNodeParameter('options', 0, {}) as IDataObject;

			// Get the json data of the items and flatten it
			let item: INodeExecutionData;
			const itemData: IDataObject[] = [];
			for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
				item = items[itemIndex];
				itemData.push(flattenObject(item.json));
			}

			const ws = xlsxUtils.json_to_sheet(itemData);

			const wopts: WritingOptions = {
				bookSST: false,
				type: 'buffer'
			};

			if (fileFormat === 'csv') {
				wopts.bookType = 'csv';
			} else if (fileFormat === 'html') {
				wopts.bookType = 'html';
			} else if (fileFormat === 'rtf') {
				wopts.bookType = 'rtf';
			} else if (fileFormat === 'ods') {
				wopts.bookType = 'ods';
			} else if (fileFormat === 'xls') {
				wopts.bookType = 'xlml';
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 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 apache / zeppelin / zeppelin-web-angular / src / app / pages / workspace / notebook / paragraph / result / result.component.ts View on Github external
exportFile(type: 'csv' | 'tsv'): void {
    if (this.tableData && this.tableData.rows) {
      const wb = utils.book_new();
      let ws: WorkSheet;
      ws = utils.json_to_sheet(this.tableData.rows);
      utils.book_append_sheet(wb, ws, 'Sheet1');
      writeFile(wb, `export.${type}`, {
        bookType: 'csv',
        FS: type === 'tsv' ? '\t' : ','
      } as WritingOptions);
    }
  }