How to add a breakline inside a cell with Excel4node module in NodeJs

2.7k Views Asked by At

I need to insert a multiline cell with module excel4node, in documentation I didn't found anything about this. I tried to insert the escape sequence "\n" but it didn't work. This is my code:

var xl = require('excel4node');
var wb = new xl.Workbook();
var ws = wb.addWorksheet('Sheet 1');

ws.cell(1, 1).string('first line \n second line');

And this is the result inside the cell:

first line \n second line

Somebody knows how it's possible to insert a multiline cell? Which char must I use?

6

There are 6 best solutions below

0
Zoz On BEST ANSWER

My friendo

Have you tried this way?

ws.cell(1, 1).formula('="first line"&CHAR(10)&"second line"');
0
Dragneel Larcade On

I've encountered this problem some time ago. I resolved with:

ws.cell(1, 1).formula('="first line"&CHAR(10)&"second line"');
0
Dalfstep On

Helped a colleague yesterday who was having the same issue, after a while we came up with this solution.

ws.cell(1, 1).formula('="first line"&CHAR(10)&"second line"');
0
Daniel Rojas Rodriguez On

I use this to insert breaklines

ws.cell(row, col).string('text to print \n another line').style({ alignment: { wrapText: true});
0
sonjasan On

There are many ways. I hope this could help. By this code, you can also format a specific line

var complexstring = [
  'line1\n',
  {
    bold: true,
    size: 7,
    name: 'Arial',
    italics: true,
    value: 'line2'
  }
]
ws.cell(4, 2).string(complexstring)
0
Alexander  Bladyko On

I've tried alignment and it works

const style = ws.createStyle({
  alignment: {
    wrapText: true,
  },
})
ws.cell(4, 2).string('new\nline').style(style)