[英]js-xlsx how to rearrange columns?
I am using js-xlsx
to create an excel file.我正在使用js-xlsx
创建一个 excel 文件。 After doing .json_to_sheet
I am getting my sheet not with the wanted columns order.完成.json_to_sheet
后,我得到的工作表没有按想要的列顺序排列。 for example, I am getting the following order:例如,我收到以下订单:
100 | 200 | 300| 400| a | b | c
when 100, 200, 300, 400, a, b, c
are my columns header.当100, 200, 300, 400, a, b, c
是我的列 header 时。
I what to get the following order:我得到以下命令:
a | b | c | 100 | 200 | 300| 400
when a | b | c
当a | b | c
a | b | c
a | b | c
are always constant and the number of the other columns are changing. a | b | c
始终不变,其他列的数量在变化。
How can I rearrange the columns order?如何重新排列列顺序?
NOTE: When used numbers as header the xlsx
rearrange the columns such that the headers start whit numbers are first and then all the rest.注意:当使用数字作为 header 时, xlsx
会重新排列列,以使标题以数字开头,然后是所有 rest。 When the headers don't start with numbers you can just order the columns in the JSON
you save.当标题不以数字开头时,您只需对您保存的JSON
中的列进行排序。 One solution is to add a space ' '
before the number and it fixes the problem.一种解决方案是在数字前添加一个空格' '
,它可以解决问题。 but I don't want a space before the number.但我不想在数字前有空格。
// by default generates 'a,b,c\n1,2,3\n'
XLSX.utils.sheet_to_csv(XLSX.utils.json_to_sheet([{a:1,b:2,c:3}]))
// pass header:['c','a','b'] to reorder: 'c,a,b\n3,1,2\n'
XLSX.utils.sheet_to_csv(XLSX.utils.json_to_sheet([{a:1,b:2,c:3}], {header:['c','a','b']}))
// pass header:['c','b','a'] to reorder: 'c,b,a\n3,2,1\n'
XLSX.utils.sheet_to_csv(XLSX.utils.json_to_sheet([{a:1,b:2,c:3}], {header:['c','b','a']}))
I found this on github issue #738 Check if you can make something out of this.我在 github 问题 #738 上找到了这个,检查你是否可以从中做点什么。 (Something with the 'header' part) (带有“标题”部分的东西)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.