|
1 | | -import { DEFAULT_STYLE } from "../../constants"; |
| 1 | +import { DEFAULT_NUMBER_STYLE, DEFAULT_STYLE } from "../../constants"; |
2 | 2 | import { Token, compile, tokenize } from "../../formulas"; |
3 | | -import { deepEquals } from "../../helpers"; |
| 3 | +import { deepEquals, isNumber } from "../../helpers"; |
4 | 4 | import { parseLiteral } from "../../helpers/cells"; |
5 | 5 | import { |
6 | 6 | concat, |
@@ -266,7 +266,7 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState { |
266 | 266 | for (const position of positions) { |
267 | 267 | const cell = this.getters.getCell(position)!; |
268 | 268 | const xc = toXC(position.col, position.row); |
269 | | - const style = this.removeDefaultStyleValues(cell.style); |
| 269 | + const style = this.extractCustomStyle(cell); |
270 | 270 | cells[xc] = { |
271 | 271 | style: Object.keys(style).length ? getItemId<Style>(style, styles) : undefined, |
272 | 272 | format: cell.format ? getItemId<Format>(cell.format, formats) : undefined, |
@@ -295,10 +295,14 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState { |
295 | 295 | this.export(data); |
296 | 296 | } |
297 | 297 |
|
298 | | - private removeDefaultStyleValues(style: Style | undefined): Style { |
299 | | - const cleanedStyle = { ...style }; |
300 | | - for (const property in DEFAULT_STYLE) { |
301 | | - if (cleanedStyle[property] === DEFAULT_STYLE[property]) { |
| 298 | + private extractCustomStyle(cell: Cell): Style { |
| 299 | + const cleanedStyle = { ...cell.style }; |
| 300 | + const defaultStyle = isNumber(cell.content, this.getters.getLocale()) |
| 301 | + ? DEFAULT_NUMBER_STYLE |
| 302 | + : DEFAULT_STYLE; |
| 303 | + for (const property in defaultStyle) { |
| 304 | + if (property === "align" && cell.isFormula) continue; |
| 305 | + if (cleanedStyle[property] === defaultStyle[property]) { |
302 | 306 | delete cleanedStyle[property]; |
303 | 307 | } |
304 | 308 | } |
|
0 commit comments