Skip to content

Commit 0bf835c

Browse files
fix: cell.style.fill problems old pr 1573
1 parent 11b4640 commit 0bf835c

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

lib/doc/cell.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class Cell {
349349
}
350350

351351
if (value.style) {
352-
this.style = value.style;
352+
this.style = _.cloneDeep(value.style);
353353
} else {
354354
this.style = {};
355355
}
@@ -862,8 +862,7 @@ class FormulaValue {
862862
if (!this._translatedFormula && this.model.sharedFormula) {
863863
const {worksheet} = this.cell;
864864
const master = worksheet.findCell(this.model.sharedFormula);
865-
this._translatedFormula =
866-
master && slideFormula(master.formula, master.address, this.model.address);
865+
this._translatedFormula = master && slideFormula(master.formula, master.address, this.model.address);
867866
}
868867
return this._translatedFormula;
869868
}

lib/utils/under-dash.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,34 @@ const _ = {
179179
}
180180
return target;
181181
},
182+
183+
cloneDeep: function cloneDeep(value, preserveUndefined) {
184+
if (preserveUndefined === undefined) {
185+
preserveUndefined = true;
186+
}
187+
let clone;
188+
if (value === null) {
189+
return null;
190+
}
191+
if (value instanceof Date) {
192+
return value;
193+
}
194+
if (value instanceof Array) {
195+
clone = [];
196+
} else if (typeof value === 'object') {
197+
clone = {};
198+
} else {
199+
return value;
200+
}
201+
_.each(value, (_value, name) => {
202+
if (_value !== undefined) {
203+
clone[name] = cloneDeep(_value, preserveUndefined);
204+
} else if (preserveUndefined) {
205+
clone[name] = undefined;
206+
}
207+
});
208+
return clone;
209+
},
182210
};
183211

184212
module.exports = _;

spec/integration/workbook/workbook.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,13 @@ describe('Workbook', () => {
639639
const ws2 = wb2.getWorksheet('duplicateTest');
640640

641641
expect(ws2.getCell('A2').value).to.equal('OneInfo');
642-
expect(ws2.getCell('A2').style).to.equal(ws2.getCell('A1').style);
642+
expect(ws2.getCell('A2').style).to.deep.equal(
643+
ws2.getCell('A1').style
644+
);
643645
expect(ws2.getCell('A3').value).to.equal('OneInfo');
644-
expect(ws2.getCell('A3').style).to.equal(ws2.getCell('A1').style);
646+
expect(ws2.getCell('A3').style).to.deep.equal(
647+
ws2.getCell('A1').style
648+
);
645649
expect(ws2.getCell('A4').value).to.be.null();
646650
});
647651
});

spec/unit/utils/under-dash.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,51 @@ describe('under-dash', () => {
7676
}
7777
});
7878
});
79+
80+
describe('cloneDeep', () => {
81+
it('should be null', () => {
82+
const clone = _.cloneDeep(null);
83+
84+
expect(clone).to.be.equal(null);
85+
});
86+
it('should be date', () => {
87+
const myDate = new Date(Date.UTC(2017, 11, 15, 17, 0, 0, 0));
88+
const cloneDate = _.cloneDeep(myDate);
89+
90+
expect(cloneDate).to.deep.equal(myDate);
91+
});
92+
it('should be string', () => {
93+
const clone = _.cloneDeep('string');
94+
95+
expect(clone).to.equal('string');
96+
});
97+
it('should be array', () => {
98+
const origin = [1, 2, [3, undefined, [5]]];
99+
const clone = _.cloneDeep(origin);
100+
101+
expect(clone).to.deep.equal(origin);
102+
103+
origin.push(6);
104+
105+
expect(clone).not.to.deep.equal(origin);
106+
});
107+
it('should be object', () => {
108+
const origin = {
109+
name: 'test',
110+
goods: [1, 2, 3, [4]],
111+
theme: {
112+
font: 'red',
113+
size: 12,
114+
border: undefined,
115+
},
116+
};
117+
const clone = _.cloneDeep(origin);
118+
119+
expect(clone).to.deep.equal(origin);
120+
121+
origin.theme.size = 13;
122+
123+
expect(clone).not.to.deep.equal(origin);
124+
});
125+
});
79126
});

0 commit comments

Comments
 (0)