diff --git a/packages/core/src/modules/cell.ts b/packages/core/src/modules/cell.ts index d7d6293..2988c71 100644 --- a/packages/core/src/modules/cell.ts +++ b/packages/core/src/modules/cell.ts @@ -738,10 +738,6 @@ export function updateCell( } curv ||= {}; const fontSize = curv.fs || 10; - delete curv.fs; - delete curv.f; - delete curv.v; - delete curv.m; if (!curv.ct) { curv.ct = {}; @@ -749,7 +745,14 @@ export function updateCell( } curv.ct.t = "inlineStr"; - curv.ct.s = convertSpanToShareString($input!.querySelectorAll("span")); + curv.ct.s = convertSpanToShareString( + $input!.querySelectorAll("span"), + curv + ); + delete curv.fs; + delete curv.f; + delete curv.v; + delete curv.m; curv.fs = fontSize; if (isCopyVal) { curv.ct.s = [ diff --git a/packages/core/src/modules/inline-string.ts b/packages/core/src/modules/inline-string.ts index df01abe..99ba47f 100644 --- a/packages/core/src/modules/inline-string.ts +++ b/packages/core/src/modules/inline-string.ts @@ -58,7 +58,7 @@ export function getInlineStringNoStyle(r: number, c: number, data: CellMatrix) { return ""; } -export function convertCssToStyleList(cssText: string) { +export function convertCssToStyleList(cssText: string, originCell: Cell) { if (_.isEmpty(cssText)) { return {}; } @@ -66,12 +66,12 @@ export function convertCssToStyleList(cssText: string) { const styleList: CellStyle = { // ff: locale_fontarray[0], // font family - fc: "#000000", // font color - fs: 10, // font size - cl: 0, // strike - un: 0, // underline - bl: 0, // blod - it: 0, // italic + fc: originCell.fc || "#000000", // font color + fs: originCell.fs || 10, // font size + cl: originCell.cl || 0, // strike + un: originCell.un || 0, // underline + bl: originCell.bl || 0, // blod + it: originCell.it || 0, // italic }; cssTextArray.forEach((s) => { s = s.toLowerCase(); @@ -80,16 +80,12 @@ export function convertCssToStyleList(cssText: string) { if (key === "font-weight") { if (value === "bold") { styleList.bl = 1; - } else { - styleList.bl = 0; } } if (key === "font-style") { if (value === "italic") { styleList.it = 1; - } else { - styleList.it = 0; } } @@ -130,14 +126,20 @@ export function convertCssToStyleList(cssText: string) { return styleList; } -// eslint-disable-next-line no-undef -export function convertSpanToShareString($dom: NodeListOf) { +export function convertSpanToShareString( + // eslint-disable-next-line no-undef + $dom: NodeListOf, + originCell: Cell +) { const styles: CellStyle[] = []; let preStyleList: Cell; let preStyleListString = null; for (let i = 0; i < $dom.length; i += 1) { const span = $dom[i]; - const styleList = convertCssToStyleList(span.style.cssText) as Cell; + const styleList = convertCssToStyleList( + span.style.cssText, + originCell + ) as Cell; const curStyleListString = JSON.stringify(styleList); // let v = span.innerHTML;