Fix path issues in calc chain setup. Change calc chain rebuild. Update tests to work with new date functionality

This commit is contained in:
Michael Rothberg
2015-10-05 14:30:09 -04:00
committed by Michael Rothberg
parent fa326078b1
commit 05f5990807
3 changed files with 19 additions and 19 deletions
+7 -7
View File
@@ -54,7 +54,7 @@ module.exports = (function() {
self.calChainRel = self.workbookRels.find("Relationship[@Type='" + CALC_CHAIN_RELATIONSHIP + "']")
if (self.calChainRel) {
self.calcChainPath = path.join(self.prefix, self.calChainRel.attrib.Target)
self.calcChainPath = self.prefix + "/" + self.calChainRel.attrib.Target;
self.calcChain = etree.parse(self.archive.file(self.calcChainPath).asText()).getroot();
}
@@ -216,9 +216,11 @@ module.exports = (function() {
var sheetData = sheet.root.find("sheetData");
calcChain.findall('c').forEach(function(c) {
if (c.attrib.i == sheet.id){
//TODO: Revisit this - the if assumes each cell stores the sheet id in the c element, which is wrong - some cells have no i attrib.
// Having it always remove the tag no matter the sheet seems two work.
// if (c.attrib.i == sheet.id){
calcChain.remove(0,c);
}
// }
});
}
@@ -390,7 +392,7 @@ module.exports = (function() {
sheet.findall("tableParts/tablePart").forEach(function(tablePart) {
var relationshipId = tablePart.attrib['r:id'],
target = rels.find("Relationship[@Id='" + relationshipId + "']").attrib.Target,
tableFilename = sheetDirectory + "/" + target,
tableFilename = target.replace('..', self.prefix),
tableTree = etree.parse(self.archive.file(tableFilename).asText());
tables.push({
@@ -621,9 +623,7 @@ module.exports = (function() {
if(value instanceof Date) {
//In Excel date is a number of days since 01/01/1900
// timestamp in ms to days + number of days from 1900 to 1970
return Number( (value.getTime()/(1000*60*60*24)) + 25569 + 1); //+ 1 day because:
// Excel incorrectly regards 1900 as a leap year and allows February 29 to be entered as a date in this year.
// This is for compatibility with Lotus 1-2-3 which also had this bug
return Number( (value.getTime()/(1000*60*60*24)) + 25569);
} else if(typeof(value) === "number" || typeof(value) === "boolean") {
return Number(value).toString();
} else if(typeof(value) === "string") {
+9 -9
View File
@@ -98,7 +98,7 @@ describe("CRUD operations", function() {
sharedStrings.findall("./si")[
parseInt(sheet1.find("./sheetData/row/c[@r='B4']/v").text, 10)
].find("t").text
).toEqual("Extracted on 2013-01-02T00:00:00.000Z");
).toEqual("Extracted on 41276");
// revision placeholder - cell C4 changed from string to number
buster.expect(sheet1.find("./sheetData/row/c[@r='C4']").attrib.t).toEqual("n");
@@ -109,9 +109,9 @@ describe("CRUD operations", function() {
buster.expect(sheet1.find("./sheetData/row/c[@r='E6']").attrib.t).toEqual("d");
buster.expect(sheet1.find("./sheetData/row/c[@r='F6']").attrib.t).toEqual("d");
buster.expect(sheet1.find("./sheetData/row/c[@r='D6']/v").text).toEqual(new Date("2013-01-01").toISOString());
buster.expect(sheet1.find("./sheetData/row/c[@r='E6']/v").text).toEqual(new Date("2013-01-02").toISOString());
buster.expect(sheet1.find("./sheetData/row/c[@r='F6']/v").text).toEqual(new Date("2013-01-03").toISOString());
buster.expect(sheet1.find("./sheetData/row/c[@r='D6']/v").text).toEqual("41275");
buster.expect(sheet1.find("./sheetData/row/c[@r='E6']/v").text).toEqual("41276");
buster.expect(sheet1.find("./sheetData/row/c[@r='F6']/v").text).toEqual("41277");
// planData placeholder - added rows and cells
buster.expect(sheet1.find("./sheetData/row/c[@r='B7']").attrib.t).toEqual("s");
@@ -336,8 +336,8 @@ describe("CRUD operations", function() {
parseInt(sheet1.find("./sheetData/row/c[@r='B15']/v").text, 10)
].find("t").text
).toEqual("John");
buster.expect(sheet1.find("./sheetData/row/c[@r='C15']/v").text).toEqual(new Date("2013-01-01").toISOString());
buster.expect(sheet1.find("./sheetData/row/c[@r='D15']/v").text).toEqual(new Date("2013-01-02").toISOString());
buster.expect(sheet1.find("./sheetData/row/c[@r='C15']/v").text).toEqual("41275");
buster.expect(sheet1.find("./sheetData/row/c[@r='D15']/v").text).toEqual("41276");
buster.expect(sheet1.find("./sheetData/row/c[@r='E15']/v").text).toEqual("104");
// Row 16 contains a name and three dates
@@ -346,9 +346,9 @@ describe("CRUD operations", function() {
parseInt(sheet1.find("./sheetData/row/c[@r='B16']/v").text, 10)
].find("t").text
).toEqual("Bob");
buster.expect(sheet1.find("./sheetData/row/c[@r='C16']/v").text).toEqual(new Date("2013-01-01").toISOString());
buster.expect(sheet1.find("./sheetData/row/c[@r='D16']/v").text).toEqual(new Date("2013-01-02").toISOString());
buster.expect(sheet1.find("./sheetData/row/c[@r='E16']/v").text).toEqual(new Date("2013-01-03").toISOString());
buster.expect(sheet1.find("./sheetData/row/c[@r='C16']/v").text).toEqual("41275");
buster.expect(sheet1.find("./sheetData/row/c[@r='D16']/v").text).toEqual("41276");
buster.expect(sheet1.find("./sheetData/row/c[@r='E16']/v").text).toEqual("41277");
// Row 17 contains a name and no dates
buster.expect(
+3 -3
View File
@@ -415,7 +415,7 @@ describe("Helpers", function() {
it("can stringify dates", function() {
var t = new XlsxTemplate();
buster.expect(t.stringify(new Date("2013-01-01"))).toEqual("2013-01-01T00:00:00.000Z");
buster.expect(t.stringify(new Date("2013-01-01"))).toEqual(41275);
});
it("can stringify numbers", function() {
@@ -576,9 +576,9 @@ describe("Helpers", function() {
};
t.addSharedString(string);
buster.expect(t.substituteScalar(col, string, placeholder, substitution)).toEqual("2013-01-01T00:00:00.000Z");
buster.expect(t.substituteScalar(col, string, placeholder, substitution)).toEqual(41275);
buster.expect(col.attrib.t).toEqual("d");
buster.expect(val.text).toEqual("2013-01-01T00:00:00.000Z");
buster.expect(val.text).toEqual(41275);
buster.expect(t.sharedStrings).toEqual(["${foo}"]);
});