[英]Node.JS: export data from mysql to excel using alasql
I'm writing a script to export data from mysql to excel using Node.JS and alasql . 我正在编写一个脚本,使用Node.JS和alasql将数据从mysql导出到excel。 I can see examples in doing this .
我可以看到这样做的例子 。
var mystyle = {
headers:true,
column: {style:{Font:{Bold:"1"}}},
rows: {1:{style:{Font:{Color:"#FF0077"}}}},
cells: {1:{1:{
style: {Font:{Color:"#00FFFF"}}
}}}
};
alasql('SELECT * INTO XLSXML("restest280b.xls",?) FROM ?',[mystyle,data]);
However, there is no documentation about what the variable data
is and how I should construct it, particular in my case using recordset from mysql? 但是,没有关于变量
data
是什么以及如何构造变量的文档,特别是在使用mysql记录集的情况下?
conn.query(SQL, function(err, rows, fields) {
ALASQL('SELECT * INTO XLSXML("restest280b.xlsx",?) FROM ?',[mystyle,rows]);
})
I tried to use mysql recordset directly. 我试图直接使用mysql记录集。 It wrote a file but can't be opened in excel.
它写了一个文件,但是不能在excel中打开。
Here data
is a array or JSON objects, for example: 这里的
data
是一个数组或JSON对象,例如:
var rows = [{a:1, b:10, c:'One'}, {a:2, b:20, c:'Two'} ];
alasql('SELECT * INTO XLSXML("restest280b.xlsx",?) FROM ?',[mystyle,rows]);
If you use node-mysql package, your code should work. 如果您使用node-mysql软件包,则您的代码应该可以工作。
XLSXML() function generates XML file, and usually Windows version of MS Excel produce a warning. XLSXML()函数生成XML文件,通常Windows版本的MS Excel会产生警告。 You can aliminate it if you will use XLSX() function with js-xlsx library:
如果将XLSX()函数与js-xlsx库一起使用,则可以消除它:
var rows = [{a:1, b:10, c:'One'}, {a:2, b:20, c:'Two'} ];
alasql('SELECT * INTO XLSX("restest280b.xlsx") FROM ?',[rows]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.