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.

Issue with writing newlines

See original GitHub issue

I’m having an issue writing \n to cells. It’s stripping them from the file. I’m using version 0.4.2.

When I monkey patch exceljs to use the entities module, it works correctly.

This is not a permanent fix, just demonstrating how to patch it.

var utils = require('exceljs/lib/utils/utils');
utils.xmlEncode = require('entities').encodeXML;

Looking at the xmlEncode function it does look like it’s wrong, it’s not allowing \n (0x0A) through.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
stephengardnercommented, Sep 12, 2017

I’m on 0.5.1 and this issue isn’t fixed… Edit – okay, you really do still have to use style: { alignment: { wrapText: true } } when creating the column

That will work…

8reactions
holly-weissercommented, Jun 21, 2017

Ok, I think I’ve got a solution working for new lines.

@Rycochet, can you PR the change you posted above, that lets the new line through? Nvm, I PR’d it.

With that change, I had to do two other things:

  1. When constructing the WorkbookWriter, I needed to use the useSharedStrings and useStyles properties:

this.workbook = new Excel.stream.xlsx.WorkbookWriter({ useSharedStrings: true, useStyles: true });

  1. When creating the workbook columns, I had to set the wrapText style property to true:

{ header: columnName, key: columnKey, width: 10, style: { alignment: { wrapText: true } } }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing string to a file on a new line every time - Stack Overflow
Use "\n": file.write("My String\n"). See the Python manual for reference.
Read more >
How do you write in a new line on a text file in Python? - Quora
If you are writing a text file, then you are writing strings. Just include a newline character '\n' at the end of the...
Read more >
8.8. Writing files — Python for Everybody - Runestone Academy
We must make sure to manage the ends of lines as we write to the file by explicitly inserting the newline character when...
Read more >
Write a string to a file on a new line every time in Python
To write a string to a file on a new line every time, open the file in writing mode. Append a newline (`\n`)...
Read more >
Reading \n from file doesn't result new line - Forums - IBM
If you really have the to characters "\n" inside your text file (and you are not only writing it this way to highlight...
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