Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
};
/**
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;
}
}
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);
}
/**
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;
}
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';
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}`);
}
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}`);
}
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);
}
}