4

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?

matthias_h
  • 11,356
  • 9
  • 22
  • 40
AlTheLazyMonkey
  • 1,190
  • 1
  • 8
  • 20

6 Answers6

7

My friendo

Have you tried this way?

ws.cell(1, 1).formula('="first line"&CHAR(10)&"second line"');
Zoz
  • 86
  • 2
3

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

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

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"');
DharmanBot
  • 1,066
  • 2
  • 6
  • 10
Dalfstep
  • 41
  • 3
3

I use this to insert breaklines

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

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)
Josef
  • 2,869
  • 2
  • 22
  • 23
sonjasan
  • 49
  • 5
0

I've tried alignment and it works

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