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.

Rich text formatting is not rendered when using the Streaming I/O

See original GitHub issue

Hello there,

In my application I’m building an Excel document row by row and stream each row when it’s done. One cell has rich formatting - some words have specific colours. I think I’m doing the right thing but in the Excel document the cell has the value [Object object]. I guess this is the toString() of the object instead of the correct rendering.

Here is a little example that is failing for me:

var fs = require('fs');
var exceljs = require('exceljs');

var stream = fs.createWriteStream('richtTextStream.xlsx');
var wb = new exceljs.stream.xlsx.WorkbookWriter({'stream': stream, 'useStyles': true});
var ws = wb.addWorksheet('rich');
var row = ws.getRow(2);
var cell = row.getCell(2);

cell.value = {
  richText: [
    {
      font: {color: {argb: '99E391'}},
      text: 'This part '
    },
    {
      font: {color: {argb: 'FF6565'}},
      text: ' and that one.'
    }
  ]
};

row.commit();
ws.commit();
wb.commit();

If I use a non streaming workbook and write the file using wb.xlsx.writeFile() then I can see the correct formatting.

Any idea what is going on? Is there some missing rendering logic in the Streaming I/O?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Kylircommented, Jan 10, 2018

Thanks for the suggestion! I used this 'useSharedStrings': true option and I can see rich text formatting.

But it is still not working: if you have multiple rows with rich text formatting all the cells will have the value of the first cell.

The following script illustrates what I’m saying:

const fs = require('fs');
const exceljs = require('exceljs');

let stream = fs.createWriteStream('richtTextStream.xlsx');
let wb = new exceljs.stream.xlsx.WorkbookWriter({'stream': stream, 'useStyles': true, 'useSharedStrings': true});
let ws = wb.addWorksheet('rich');

let row = ws.getRow(2);
let cell = row.getCell(2);

cell.value = {
  richText: [
    { font: {color: {argb: '99E391'}}, text: 'This part ' },
    { font: {color: {argb: 'FF6565'}}, text: ' and that one.'}
  ]
};
row.commit();

let row2 = ws.getRow(3);
let cell2 = row2.getCell(2);
cell2.value = {
  richText: [
    { font: {color: {argb: '9199E3'}}, text: 'Something different ' },
    { font: {color: {argb: 'FF6565'}}, text: ' with the same colors.' }
  ]
};
row2.commit();

ws.commit();
wb.commit();

The excel document generated will have 2 rows with the same content:

This part and that one
This part and that one
0reactions
valentinomicudaj1commented, Dec 21, 2020

I ran into the same problem with all the richText cells have the same value as the first richText cell, any workaround or any news of a possible fix? Version: 4.2.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# populate RichTextBox with stream -- File Format is not Valid
I am trying to put an .rtf stream into a RichTextBox using this code: ... render the document but the resulting string was...
Read more >
Contentful Strategies: How To Render RichText - YouTube
Creating and adjusting new fields in your content model is easy with Contentful's RichText editor. Follow along as Stefon highlights the ...
Read more >
Enable or disable full rich-text formatting in a rich text box
Right-click the rich text box for which you want to enable or disable full rich-text formatting, and then click Rich Text Box Properties...
Read more >
Rich Text Format (RTF) Version 1.5 Specification - Biblioscape
(Converters that communicate with Microsoft Word for Windows or Microsoft Word for the Macintosh should expect 8-bit characters.) There is no set maximum...
Read more >
Handle Rich Text in React - Documentation - Prismic
Learn how to work with rich text in React. Prismic provides the tools to write, save, query, and render rich text content in...
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