简体   繁体   English

为Excel工作表生成字符串

[英]Generate string for excel sheet

I'm trying to generate a string, which can be pasted in excel and will be arranged correctly as a table 我正在尝试生成一个字符串,可以将其粘贴到excel中,并将其正确地布置为表格

I'm using tabs to separate columns and CRLF to separate rows 我正在使用tabs来分隔列,并使用CRLF来分隔行

 import values from 'lodash/values' const toExcelString = matrix => matrix .map(row => values(row).join('\\t')) .join(`\\r\\n`) 

Generates this string: 生成此字符串:

 2016-12-01 00:00:00 0 3000 0 0 0 0 3000 2017-01-03 00:00:00 1 0 0 196.66 113.92 310.58 2803.34 2017-02-01 00:00:00 2 0 0 217.03 93.55 310.58 2586.31 2017-03-01 00:00:00 3 0 0 227.25 83.33 310.58 2359.06 2017-04-03 00:00:00 4 0 0 221 89.58 310.58 2138.06 2017-05-01 00:00:00 5 0 0 241.69 68.89 310.58 1896.37 2017-06-01 00:00:00 6 0 0 242.93 67.65 310.58 1653.44 2017-07-03 00:00:00 7 0 0 249.7 60.88 310.58 1403.74 2017-08-01 00:00:00 8 0 0 263.74 46.84 310.58 1140 2017-09-01 00:00:00 9 0 0 269.91 40.67 310.58 870.09 2017-10-02 00:00:00 10 0 0 279.54 31.04 310.58 590.55 2017-11-01 00:00:00 11 0 0 290.19 20.39 310.58 300.36 2017-12-01 00:00:00 12 0 0 300.36 10.37 310.73 0 

But when I paste it in excel (2016) it appears as one cell. 但是当我将其粘贴到excel(2016)中时,它显示为一个单元格。 What am I doing wrong? 我究竟做错了什么?

I also tried to add CRLF in the and, and using String.fromCharCode in stead of \\t and \\r\\n 我还尝试在和中添加CRLF ,并使用String.fromCharCode代替\\t\\r\\n

Also I'm using copy-to-clipboard library. 另外我正在使用复制到剪贴板库。

Are you sure it's not your excel settings that is causing the issues? 您确定不是您的Excel设置导致了问题吗?

Check out this link: http://www.wikihow.com/Copy-Paste-Tab-Delimited-Text-Into-Excel 查看此链接: http : //www.wikihow.com/Copy-Paste-Tab-Delimited-Text-Into-Excel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM