Preserve QExcell font sizes
This commit is contained in:
+17
-4
@@ -936,12 +936,12 @@ function cellFormatKey(format: CellFormat | undefined) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return `${normalized.bold ? "1" : "0"}|${normalized.italics ? "1" : "0"}|${normalized.underline ? "1" : "0"}|${normalized.textColor ?? ""}|${normalized.fillColor ?? ""}|${normalized.horizontalAlign ?? ""}|${normalized.numberFormat ?? ""}`;
|
||||
return `${normalized.bold ? "1" : "0"}|${normalized.italics ? "1" : "0"}|${normalized.underline ? "1" : "0"}|${normalized.fontSize ?? ""}|${normalized.textColor ?? ""}|${normalized.fillColor ?? ""}|${normalized.horizontalAlign ?? ""}|${normalized.numberFormat ?? ""}`;
|
||||
}
|
||||
|
||||
function fontStyleKey(format: CellFormat) {
|
||||
return format.bold || format.italics || format.underline || format.textColor
|
||||
? `${format.bold ? "1" : "0"}|${format.italics ? "1" : "0"}|${format.underline ? "1" : "0"}|${format.textColor ?? ""}`
|
||||
return format.bold || format.italics || format.underline || format.fontSize || format.textColor
|
||||
? `${format.bold ? "1" : "0"}|${format.italics ? "1" : "0"}|${format.underline ? "1" : "0"}|${format.fontSize ?? ""}|${format.textColor ?? ""}`
|
||||
: "";
|
||||
}
|
||||
|
||||
@@ -950,10 +950,12 @@ function normalizedCellFormat(format: CellFormat | undefined): CellFormat | null
|
||||
const fillColor = normalizeFillColor(format?.fillColor);
|
||||
const horizontalAlign = normalizedHorizontalAlign(format?.horizontalAlign);
|
||||
const numberFormat = normalizedNumberFormat(format?.numberFormat);
|
||||
const fontSize = normalizedFontSize(format?.fontSize);
|
||||
const normalized: CellFormat = {
|
||||
...(format?.bold ? { bold: true } : {}),
|
||||
...(format?.italics ? { italics: true } : {}),
|
||||
...(format?.underline ? { underline: true } : {}),
|
||||
...(fontSize ? { fontSize } : {}),
|
||||
...(textColor ? { textColor } : {}),
|
||||
...(fillColor ? { fillColor } : {}),
|
||||
...(horizontalAlign ? { horizontalAlign } : {}),
|
||||
@@ -966,11 +968,13 @@ function normalizedCellFormat(format: CellFormat | undefined): CellFormat | null
|
||||
function fontXmlToCellFormat(font: unknown): CellFormat {
|
||||
const record = asRecord(font);
|
||||
const textColor = normalizeFillColor(String(childRecord(record, "color").rgb || ""));
|
||||
const fontSize = normalizedFontSize(numberAttribute(childRecord(record, "sz").val));
|
||||
return (
|
||||
normalizedCellFormat({
|
||||
bold: hasXmlElement(record, "b"),
|
||||
italics: hasXmlElement(record, "i"),
|
||||
underline: hasXmlElement(record, "u"),
|
||||
...(fontSize ? { fontSize } : {}),
|
||||
...(textColor ? { textColor } : {})
|
||||
}) ?? {}
|
||||
);
|
||||
@@ -989,7 +993,7 @@ function baseFontXml() {
|
||||
function formatFontXml(format: CellFormat) {
|
||||
const flags = `${format.bold ? "<b/>" : ""}${format.italics ? "<i/>" : ""}${format.underline ? "<u/>" : ""}`;
|
||||
const color = format.textColor ? `<color rgb="FF${format.textColor}"/>` : '<color theme="1"/>';
|
||||
return `<font>${flags}<sz val="11"/>${color}<name val="Calibri"/><family val="2"/></font>`;
|
||||
return `<font>${flags}<sz val="${format.fontSize ?? 11}"/>${color}<name val="Calibri"/><family val="2"/></font>`;
|
||||
}
|
||||
|
||||
function formatFillXml(fillColor: string) {
|
||||
@@ -1005,6 +1009,15 @@ function normalizeFillColor(value?: string) {
|
||||
return /^[0-9A-F]{6}$/.test(raw) ? raw : "";
|
||||
}
|
||||
|
||||
function normalizedFontSize(value?: number) {
|
||||
if (!Number.isFinite(value) || !value || value <= 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const normalized = Math.round(value * 2) / 2;
|
||||
return normalized === 11 ? undefined : normalized;
|
||||
}
|
||||
|
||||
function normalizedHorizontalAlign(value?: string) {
|
||||
const normalized = value?.trim().toLowerCase() ?? "";
|
||||
return normalized === "left" || normalized === "center" || normalized === "right" ? normalized : "";
|
||||
|
||||
Reference in New Issue
Block a user