Add QExcell cell text colors

This commit is contained in:
Курнат Андрей
2026-06-01 06:19:24 +03:00
parent 08fe16bdf6
commit 9c48e1d8b1
6 changed files with 51 additions and 13 deletions
+10 -5
View File
@@ -933,22 +933,24 @@ function cellFormatKey(format: CellFormat | undefined) {
return "";
}
return `${normalized.bold ? "1" : "0"}|${normalized.italics ? "1" : "0"}|${normalized.underline ? "1" : "0"}|${normalized.fillColor ?? ""}|${normalized.numberFormat ?? ""}`;
return `${normalized.bold ? "1" : "0"}|${normalized.italics ? "1" : "0"}|${normalized.underline ? "1" : "0"}|${normalized.textColor ?? ""}|${normalized.fillColor ?? ""}|${normalized.numberFormat ?? ""}`;
}
function fontStyleKey(format: CellFormat) {
return format.bold || format.italics || format.underline
? `${format.bold ? "1" : "0"}|${format.italics ? "1" : "0"}|${format.underline ? "1" : "0"}`
return format.bold || format.italics || format.underline || format.textColor
? `${format.bold ? "1" : "0"}|${format.italics ? "1" : "0"}|${format.underline ? "1" : "0"}|${format.textColor ?? ""}`
: "";
}
function normalizedCellFormat(format: CellFormat | undefined): CellFormat | null {
const textColor = normalizeFillColor(format?.textColor);
const fillColor = normalizeFillColor(format?.fillColor);
const numberFormat = normalizedNumberFormat(format?.numberFormat);
const normalized: CellFormat = {
...(format?.bold ? { bold: true } : {}),
...(format?.italics ? { italics: true } : {}),
...(format?.underline ? { underline: true } : {}),
...(textColor ? { textColor } : {}),
...(fillColor ? { fillColor } : {}),
...(numberFormat ? { numberFormat } : {})
};
@@ -958,11 +960,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 || ""));
return (
normalizedCellFormat({
bold: hasXmlElement(record, "b"),
italics: hasXmlElement(record, "i"),
underline: hasXmlElement(record, "u")
underline: hasXmlElement(record, "u"),
...(textColor ? { textColor } : {})
}) ?? {}
);
}
@@ -979,7 +983,8 @@ function baseFontXml() {
function formatFontXml(format: CellFormat) {
const flags = `${format.bold ? "<b/>" : ""}${format.italics ? "<i/>" : ""}${format.underline ? "<u/>" : ""}`;
return `<font>${flags}<sz val="11"/><color theme="1"/><name val="Calibri"/><family val="2"/></font>`;
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>`;
}
function formatFillXml(fillColor: string) {