question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore newlines when read xlsx files

See original GitHub issue

Hello,

I’ve got an issue when I read an XLSX file with some newlines in cells.

image

After calling XLSX.read(file, {type:'binary'});, SheetJS returned to me 3 lines instead of 2 because it think that \r means a new Excel line.

I would like to replace \r by " " or just ignore it.

Currently behovior: …fax, “first line second line”, test… …fax, test…

Expected behavior: …fax, first line second line, test… …fax, test, test…

Thanks for you help

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
reviewhercommented, Aug 19, 2021

You read the workbook, then change the text:

var wb = XLSX.read(file, {type:'binary'});
wb.SheetNames.map(n => wb.Sheets[n]).forEach(ws => {
  var range = XLSX.utils.decode_range(ws["!ref"]);
  for(var R = range.s.r; R <= range.e.r; ++R) for(var C = range.s.c; C <= range.e.c; ++C) {
    var addr = XLSX.utils.encode_cell({r:R,c:C});
    if(!ws[addr] || ws[addr].t != "s") continue;
    ws[addr].v = ws[addr].v.replace(/\r/g, " ");
  }
});
0reactions
dcr31000commented, Aug 19, 2021

Thanks for your help but I don’t understand what to do with this piece of code… I don’t want to export but I want to read the sample file. So, before the XLSX.read(file, {type:'binary'}), I can’t loop through cells because It’s not parsed yet. And after the read function, it’s already broken.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Replace or ignore new line character when converting .ods ...
I'm using ssconvert in Gnumeric to convert a bunch of ODS files to CSV ...
Read more >
How to Remove Line Breaks in Excel (3 Easy Ways)
Remove Line Breaks Using Find and Replace · Click the Home tab · In the Editing group, click on 'Find & Select' ·...
Read more >
Removing Multi-Line Breaks (ALT+ENTER) in Variables from ...
I've read 41 Excel files into SAS (some xls, some xlsx), reformatted them, concatenated them into one SAS datafile, and am now trying...
Read more >
Add Find and Replace Line Breaks in Excel - Contextures
Select the cell · In the formula bar, click at the start of the second line · To remove the line break, press...
Read more >
Read xls and xlsx files — read_excel • readxl
Read xls and xlsx files read_excel() calls excel_format() to determine if path is xls or xlsx, based on the file extension and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found