Preserve QExcell text wrapping
This commit is contained in:
+25
-5
@@ -850,8 +850,16 @@ export function xlsxStylesXmlToCellFormatTable(stylesXml?: unknown): Array<CellF
|
||||
const fontFormat = fonts[numberAttribute(record.fontId)];
|
||||
const fillFormat = fills[numberAttribute(record.fillId)];
|
||||
const numberFormat = normalizedNumberFormat(numberFormats[numberAttribute(record.numFmtId)]);
|
||||
const horizontalAlign = normalizedHorizontalAlign(String(childRecord(record, "alignment").horizontal || ""));
|
||||
return normalizedCellFormat({ ...fontFormat, ...fillFormat, ...(horizontalAlign ? { horizontalAlign } : {}), ...(numberFormat ? { numberFormat } : {}) }) ?? undefined;
|
||||
const alignment = childRecord(record, "alignment");
|
||||
const horizontalAlign = normalizedHorizontalAlign(String(alignment.horizontal || ""));
|
||||
const wrapText = booleanAttribute(alignment.wrapText);
|
||||
return normalizedCellFormat({
|
||||
...fontFormat,
|
||||
...fillFormat,
|
||||
...(horizontalAlign ? { horizontalAlign } : {}),
|
||||
...(wrapText ? { wrapText: true } : {}),
|
||||
...(numberFormat ? { numberFormat } : {})
|
||||
}) ?? undefined;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -894,9 +902,15 @@ function buildStylesXml(styleRegistry = createCellStyleRegistry([])) {
|
||||
|
||||
const applyFont = fontId > 0 ? ' applyFont="1"' : "";
|
||||
const applyFill = fillId > 0 ? ' applyFill="1"' : "";
|
||||
const applyAlignment = format.horizontalAlign ? ' applyAlignment="1"' : "";
|
||||
const applyAlignment = format.horizontalAlign || format.wrapText ? ' applyAlignment="1"' : "";
|
||||
const applyNumberFormat = numFmtId > 0 ? ' applyNumberFormat="1"' : "";
|
||||
const alignmentXml = format.horizontalAlign ? `<alignment horizontal="${format.horizontalAlign}"/>` : "";
|
||||
const alignmentAttributes = [
|
||||
format.horizontalAlign ? `horizontal="${format.horizontalAlign}"` : "",
|
||||
format.wrapText ? 'wrapText="1"' : ""
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
const alignmentXml = alignmentAttributes ? `<alignment ${alignmentAttributes}/>` : "";
|
||||
return `<xf numFmtId="${numFmtId}" fontId="${fontId}" fillId="${fillId}" borderId="0" xfId="0"${applyFont}${applyFill}${applyAlignment}${applyNumberFormat}>${alignmentXml}</xf>`;
|
||||
});
|
||||
|
||||
@@ -936,7 +950,7 @@ function cellFormatKey(format: CellFormat | undefined) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return `${normalized.bold ? "1" : "0"}|${normalized.italics ? "1" : "0"}|${normalized.underline ? "1" : "0"}|${normalized.strike ? "1" : "0"}|${normalized.fontSize ?? ""}|${normalized.fontFamily ?? ""}|${normalized.textColor ?? ""}|${normalized.fillColor ?? ""}|${normalized.horizontalAlign ?? ""}|${normalized.numberFormat ?? ""}`;
|
||||
return `${normalized.bold ? "1" : "0"}|${normalized.italics ? "1" : "0"}|${normalized.underline ? "1" : "0"}|${normalized.strike ? "1" : "0"}|${normalized.fontSize ?? ""}|${normalized.fontFamily ?? ""}|${normalized.textColor ?? ""}|${normalized.fillColor ?? ""}|${normalized.horizontalAlign ?? ""}|${normalized.wrapText ? "1" : "0"}|${normalized.numberFormat ?? ""}`;
|
||||
}
|
||||
|
||||
function fontStyleKey(format: CellFormat) {
|
||||
@@ -962,6 +976,7 @@ function normalizedCellFormat(format: CellFormat | undefined): CellFormat | null
|
||||
...(textColor ? { textColor } : {}),
|
||||
...(fillColor ? { fillColor } : {}),
|
||||
...(horizontalAlign ? { horizontalAlign } : {}),
|
||||
...(format?.wrapText ? { wrapText: true } : {}),
|
||||
...(numberFormat ? { numberFormat } : {})
|
||||
};
|
||||
|
||||
@@ -1034,6 +1049,11 @@ function normalizedHorizontalAlign(value?: string) {
|
||||
return normalized === "left" || normalized === "center" || normalized === "right" ? normalized : "";
|
||||
}
|
||||
|
||||
function booleanAttribute(value: unknown) {
|
||||
const normalized = String(value ?? "").trim().toLowerCase();
|
||||
return normalized === "1" || normalized === "true";
|
||||
}
|
||||
|
||||
function normalizedNumberFormat(value?: string) {
|
||||
const raw = value?.trim() ?? "";
|
||||
if (!raw || raw.toLowerCase() === "general") {
|
||||
|
||||
Reference in New Issue
Block a user