我需要你的帮助。从nodejs终端,我想下载一个excel文件并将数据json转换为xlsx enter image description here
答案 0 :(得分:0)
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
var xl = '';
if (ShowLabel) {
var row = "";
for (var index in arrData[0]) {
row += index + ',';
}
row = row.slice(0, -1);
xl += row + '\r\n';
}
for (var i = 0; i < arrData.length; i++) {
var row = "";
for (var index in arrData[i]) {
row += '"' + arrData[i][index] + '",';
}
row.slice(0, row.length - 1);
xl += row + '\r\n';
}
if (xl == '') {
this.alertService.error("Invalid data");
return;
}
var fileName = "file_";
fileName += ReportTitle.replace(/ /g, "_");
var uri = 'data:text/xlsx;application/vnd.openxmlformats;charset=utf-8,' + encodeURI(xl);
var link = document.createElement("a");
link.href = uri;
link.style.cssText = "visibility:hidden";
link.download = fileName+".xlsx";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
答案 1 :(得分:0)
帮助我使用节点js将数据json转换为xlsx文件 这段代码在我的系统linux中有效,而不是在windows和mac中工作 问题延伸
with external_work_history as (
select rr.*,
rsa1.rsal_title as country,
rsa2.rsal_title as function,
rsa3.rsal_title as industry
from (
select
user_id,
unnest(string_to_array(resume_attribute_00069_1, ',')) as company,
unnest(string_to_array(resume_attribute_00071_13, ',')) as country_val_id,
unnest(string_to_array(resume_attribute_00067_18_2, ',')) as end_date,
unnest(string_to_array(resume_attribute_00070_13, ',')) as function_val_id,
unnest(string_to_array(resume_attribute_00068_1, ',')) as position,
unnest(string_to_array(resume_attribute_00067_18_1, ',')) as start_date,
unnest(string_to_array(resume_attribute_00072_13, ',')) as industry_val_id
from import.vw_rpt_resume
) as rr
left join import.vw_rpt_resume_section_attribute_value_local rsa1
on rr.country_val_id = rsa1.rsal_value_id
left join import.vw_rpt_resume_section_attribute_value_local rsa2
on rr.function_val_id = rsa2.rsal_value_id
left join import.vw_rpt_resume_section_attribute_value_local rsa3
on rr.industry_val_id = rsa3.rsal_value_id
left join corp_companyuserprofile cup
on rr.user_id::int = cup.id
where
rsa1.culture_id::int = cup.language_id
and (rsa2.culture_id::int = cup.language_id and not rsa2.rsal_title is null)
-- and (rsa3.culture_id::int = cup.language_id and not rsa3.rsal_title is null)
)
select * from external_work_history;
user_id | company | country_val_id | end_date | function_val_id | position | start_date | industry_val_id | country | function | industry
---------+------------------------+----------------+------------+-----------------+--------------------------------------------------+------------+-----------------+--------------------------+--------------------+----------
9 | FFF Inc | 317 | 2013-07-31 | 322 | Tech Consulant | 2010-02-01 | | Spain | Quality |
9 | YYY SRL | 288 | 2014-12-31 | 321 | BA | 2013-08-01 | | United States of America | General Management |
43 | comp 1 | 313 | 11/11/2009 | 283 | Senior Consultant | 04/04/2003 | | Australia | Finance |
43 | Company 11 | 312 | 12/31/2012 | 283 | Manager | 12/01/2009 | | Taiwan | Finance |
43 | WWWRRR | 311 | 03/03/2003 | 283 | Junior Consultant | 02/02/1999 | | Angola | Finance |
541 | bla bla Hotel | 318 | 08/31/2011 | 321 | Branch Manager | 01/01/2008 | | Poland | General Management |
541 | SSS | 317 | 07/09/2013 | 323 | Marketing Manager | 12/07/2011 | | Spain | Marketing |
613 | Company 2 | 287 | 2008-03-28 | 322 | LABORATORY SAFETY OFFICER AND RESEARCH ASSISTANT | 2006-08-21 | | France | Quality |
613 | Company 2 | 287 | 2006-08-18 | 322 | LABORATORY TECHNOLOGIST | 2004-06-07 | | France | Quality |
613 | Company AAA | 286 | 2004-05-25 | 320 | Oncology Intern | 2003-07-07 | | Germany | Research |
603 | Corp 3 | 288 | 2016-06-30 | 320 | Medical Engineer | 2015-01-01 | | United States of America | Research |
603 | Corp 4 | 286 | 2014-12-31 | 320 | Project Manager | 2011-01-03 | | Germany | Research |
564 | Company 11 | 316 | 12/31/2013 | 322 | Senior Manager - Lab | 06/01/2009 | | Slovenia | Quality |
564 | QQQ comp | 316 | 05/31/2009 | 322 | Senior Lab Analyst | 02/01/2001 | | Slovenia | Quality |