Skip to content

Commit

Permalink
Merge pull request #1310 from Alanscut/issue_1299
Browse files Browse the repository at this point in the history
Fix cell.text return an empty object when cell is empty
  • Loading branch information
alubbe committed Jun 2, 2020
2 parents 4a3ccf0 + 33e84bb commit 41f5bbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/xlsx/xform/strings/shared-string-xform.js
Expand Up @@ -31,10 +31,13 @@ class SharedStringXform extends BaseXform {
render(xmlStream, model) {
xmlStream.openNode(this.tag);
if (model && model.hasOwnProperty('richText') && model.richText) {
const {r} = this.map;
model.richText.forEach(text => {
r.render(xmlStream, text);
});
if (model.richText.length) {
model.richText.forEach(text => {
this.map.r.render(xmlStream, text);
});
} else {
this.map.t.render(xmlStream, '');
}
} else if (model !== undefined && model !== null) {
this.map.t.render(xmlStream, model);
}
Expand Down
14 changes: 13 additions & 1 deletion spec/unit/xlsx/xform/strings/shared-string-xform.spec.js
@@ -1,4 +1,4 @@
const testXformHelper = require('./../test-xform-helper');
const testXformHelper = require('../test-xform-helper');

const SharedStringXform = verquire('xlsx/xform/strings/shared-string-xform');

Expand Down Expand Up @@ -52,6 +52,18 @@ const expectations = [
},
tests: ['render', 'renderIn', 'parse'],
},
{
title: 'richText is empty',
create() {
return new SharedStringXform();
},
preparedModel: {
richText: [],
},
xml: '<si><t></t></si>',
parsedModel: '',
tests: ['parse'],
},
{
title: 'text + phonetic',
create() {
Expand Down

0 comments on commit 41f5bbe

Please sign in to comment.