Skip to content

Commit

Permalink
Merge pull request #81 from appcraft/master
Browse files Browse the repository at this point in the history
fix wrongly replacing text in shared strings
  • Loading branch information
kant2002 committed Aug 9, 2018
2 parents bd302ea + 306ea34 commit 781bcab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,7 @@ module.exports = (function() {
} else {
var newString = string.replace(placeholder.placeholder, self.stringify(substitution));
cell.attrib.t = "s";
self.replaceString(string, newString);
return newString;
return self.insertCellValue(cell, newString)
}

};
Expand Down
5 changes: 4 additions & 1 deletion test/crud-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ describe("CRUD operations", function() {
for (let sheetNumber = 1; sheetNumber <= 2; sheetNumber++) {
// Set up some placeholder values matching the placeholders in the template
var values = {
page: 'page: ' + sheetNumber
page: 'page: ' + sheetNumber,
sheetNumber
};

// Perform substitution
Expand All @@ -868,6 +869,8 @@ describe("CRUD operations", function() {
buster.expect(sheet2).toBeDefined();
buster.expect(getSharedString(sharedStrings, sheet1, "A1")).toEqual("page: 1");
buster.expect(getSharedString(sharedStrings, sheet2, "A1")).toEqual("page: 2");
buster.expect(getSharedString(sharedStrings, sheet1, "A2")).toEqual("Page 1");
buster.expect(getSharedString(sharedStrings, sheet2, "A2")).toEqual("Page 2");

fs.writeFileSync('test/output/multple-sheets-arrays.xlsx', newData, 'binary');
done();
Expand Down
12 changes: 6 additions & 6 deletions test/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,8 @@ describe("Helpers", function() {
t.addSharedString(string);
buster.expect(t.substituteScalar(col, string, placeholder, substitution)).toEqual("foo: bar");
buster.expect(col.attrib.t).toEqual("s");
buster.expect(val.text).toEqual("0");
buster.expect(t.sharedStrings).toEqual(["foo: bar"]);
buster.expect(val.text).toEqual("1");
buster.expect(t.sharedStrings).toEqual(["foo: ${foo}", "foo: bar"]);
});

it("can substitute parts of strings with booleans", function() {
Expand All @@ -666,8 +666,8 @@ describe("Helpers", function() {
t.addSharedString(string);
buster.expect(t.substituteScalar(col, string, placeholder, substitution)).toEqual("foo: 0");
buster.expect(col.attrib.t).toEqual("s");
buster.expect(val.text).toEqual("0");
buster.expect(t.sharedStrings).toEqual(["foo: 0"]);
buster.expect(val.text).toEqual("1");
buster.expect(t.sharedStrings).toEqual(["foo: ${foo}", "foo: 0"]);
});

it("can substitute parts of strings with numbers", function() {
Expand All @@ -694,8 +694,8 @@ describe("Helpers", function() {
t.addSharedString(string);
buster.expect(t.substituteScalar(col, string, placeholder, substitution)).toEqual("foo: 10");
buster.expect(col.attrib.t).toEqual("s");
buster.expect(val.text).toEqual("0");
buster.expect(t.sharedStrings).toEqual(["foo: 10"]);
buster.expect(val.text).toEqual("1");
buster.expect(t.sharedStrings).toEqual(["foo: ${foo}", "foo: 10"]);
});


Expand Down
Binary file modified test/templates/multple-sheets-arrays.xlsx
Binary file not shown.

0 comments on commit 781bcab

Please sign in to comment.