Skip to content

Commit ec4cd23

Browse files
authored
Merge pull request #584 from peakon/feature/decodeSharedStringEscapes
Decode the _x<4 hex chars>_ escape notation in shared strings
2 parents 99789f5 + a35b976 commit ec4cd23

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/xlsx/xform/strings/text-xform.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ utils.inherits(TextXform, BaseXform, {
2828
},
2929

3030
get model() {
31-
return this._text.join('');
31+
return this._text.join('').replace(/_x([0-9A-F]{4})_/g, function($0, $1) {
32+
return String.fromCharCode(parseInt($1, 16));
33+
});
3234
},
3335

3436
parseOpen: function(node) {
8.31 KB
Binary file not shown.

spec/integration/workbook-xlsx-reader.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,20 @@ describe('WorkbookReader', function() {
127127
});
128128
});
129129
});
130+
131+
describe('with a spreadsheet that contains a shared string with an escaped underscore', function() {
132+
before(function() {
133+
var testContext = this;
134+
var workbook = new Excel.Workbook();
135+
return workbook.xlsx.read(fs.createReadStream('./spec/integration/data/shared_string_with_escape.xlsx'))
136+
.then(function() {
137+
testContext.worksheet = workbook.getWorksheet();
138+
});
139+
});
140+
141+
it('should decode the underscore', function() {
142+
const cell = this.worksheet.getCell('A1');
143+
expect(cell.value).to.equal('_x000D_');
144+
});
145+
});
130146
});

0 commit comments

Comments
 (0)