Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

javascript - Javascript XLS解析功能会跳过空单元格(Javascript XLS parsing function skips empty cells)

On a web page, I need to load XLS Excel files and display the data into an HTML table.

(在网页上,我需要加载XLS Excel文件并将数据显示到HTML表中。)

I can't use XLSX files, only XLS ones.

(我不能使用XLSX文件,只能使用XLS文件。)

To parse the file, I use XLS.utils.sheet_to_row_object_array function but it skips empty cells so the data is displayed in wrong columns.

(为了解析文件,我使用XLS.utils.sheet_to_row_object_array函数,但是它跳过了空单元格,因此数据显示在错误的列中。)

And I absolutely need to take empty cells into consideration.

(我绝对需要考虑空单元格。)

How can I correct this?

(我该如何纠正?)

  ask by Arno translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am not sure which version you are using, but js-xls was merged into js-xlsx just FYI.

(我不确定您使用的是哪个版本,但是js-xls仅出于仅供参考而合并到了js-xlsx 。)

If you update you should use sheet_to_json instead of sheet_to_row_object_array

(如果更新,则应使用sheet_to_json而不是sheet_to_row_object_array)

And the solution is you just need to specify the default value.

(解决方案是您只需要指定默认值即可。)

XLSX.utils.sheet_to_row_object_array(wb.Sheets[sheet_name_list[0]], {defval: ""})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...