您好我正在尝试将数据从我的查询数组推送到excel中,但只显示标题,但结果正在被推送。当我做一个console.log以查看是否会被推送时,它表示未定义。关于为什么的任何想法?
示例代码:
var excel_data=[];
excel_data.push=(['Source', 'Count of thing 1', 'Count of thing 2', 'Count of thing 3']);
var database = new database(config);
var query_array = ['select count(*) as count_of_thing1 from table1', 'select count(*) as count_of_thing2 from table2', 'select count(*) as count_of_thing3 from table3'];
query_array.forEach(q => {
database.query(q)
.then(rows => {
_.each(rows, function(row){
excel_data.push([row.count_of_thing1, row.count_of_thing2, row.count_of_thing3]);
});
})
var wb = XLSX.utils.book_new();
var ws_name = "Query_Results";
var wscols = [ {width: 15} ];
var wsrows = [];
var ws = XLSX.utils.aoa_to_sheet(excel_data, {cellDates:true});
ws['!cols'] = wscols;
ws['!rows'] = wsrows;
XLSX.utils.book_append_sheet(wb, ws, ws_name);
var filenames = [
['mysql.xlsx', {bookSST:true}],
['mysql.csv', {bookSST:true}],
];
filenames.forEach(function(r) {
XLSX.writeFile(wb, r[0], r[1]);
XLSX.readFile(r[0]);
});
});