dtjohnson / xlsx-populate

Excel XLSX parser/generator written in JavaScript with Node.js and browser support, jQuery/d3-style method chaining, encryption, and a focus on keeping existing workbook features and styles in tact.
MIT License
956 stars 183 forks source link

Can RichText preserve leading spaces? #228

Open bigNeoneo opened 5 years ago

bigNeoneo commented 5 years ago

Thx for this good tools firstly. below, I want a different style in one sentence. so I wrote this image but I got this image my leading spaces in RichText is missed. Can U help?

LesterLyu commented 5 years ago

I didn't think of that use case. Here is an temporary fix that should work (not tested):

const RichText = require('xlsx-Populate').RichText;
const cell = workbook.sheet(0).cell('A1');
cell.value(new RichText()).add('   leading space');
cell.value().get(0)._valueNode.attributes[xml:space'] = 'preserve';

If not, try to set cell.style('wrapText', true);