最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add a breakline inside a cell with Excel4node module in NodeJs - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Mar 10, 2020 at 11:53 matthias_h 11.4k9 gold badges23 silver badges40 bronze badges asked Mar 9, 2020 at 17:07 AlTheLazyMonkeyAlTheLazyMonkey 1,2421 gold badge10 silver badges22 bronze badges 0
Add a comment  | 

6 Answers 6

Reset to default 7

My friendo

Have you tried this way?

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

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

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

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"');

I use this to insert breaklines

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

I've tried alignment and it works

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

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)

  1. 暂无评论