Preserve QExcell font families

This commit is contained in:
Курнат Андрей
2026-06-01 07:23:32 +03:00
parent c2eaff87c6
commit f388489d2b
5 changed files with 67 additions and 12 deletions
+27 -4
View File
@@ -77,7 +77,7 @@ describe("excellOffice OOXML helpers", () => {
it("сохраняет базовое форматирование ячеек XLSX в XML листа", () => {
const cellFormats = {
A1: { bold: true, fontSize: 14, textColor: "0f5fae", fillColor: "fff2cc", horizontalAlign: "center" as const },
A1: { bold: true, fontSize: 14, fontFamily: "Arial", textColor: "0f5fae", fillColor: "fff2cc", horizontalAlign: "center" as const },
B2: { italics: true, underline: true, strike: true },
C3: { fillColor: "bad-color" }
};
@@ -112,6 +112,27 @@ describe("excellOffice OOXML helpers", () => {
expect(stylesXml).toContain("<strike/>");
});
it("записывает семейство шрифта ячейки XLSX в styles.xml", async () => {
const blob = await exportXlsxBlob({
id: "workbook",
title: "Font.xlsx",
updatedAt: "2026-06-01T00:00:00.000Z",
activeSheet: "sheet-1",
sheets: [
{
id: "sheet-1",
name: "Sheet 1",
cells: { A1: "Arial" },
cellFormats: { A1: { fontFamily: "Arial" } }
}
]
});
const zip = await JSZip.loadAsync(await blob.arrayBuffer());
const stylesXml = await zip.file("xl/styles.xml")?.async("string");
expect(stylesXml).toContain('<name val="Arial"/>');
});
it("читает базовое форматирование ячеек XLSX из styles.xml и XML листа", () => {
const styleTable = xlsxStylesXmlToCellFormatTable({
styleSheet: {
@@ -119,7 +140,7 @@ describe("excellOffice OOXML helpers", () => {
numFmt: { numFmtId: "164", formatCode: "dd.mm.yyyy" }
},
fonts: {
font: [{}, { b: {}, i: {}, u: {}, strike: {}, sz: { val: "14" }, color: { rgb: "FF0F5FAE" } }]
font: [{}, { b: {}, i: {}, u: {}, strike: {}, sz: { val: "14" }, name: { val: "Arial" }, color: { rgb: "FF0F5FAE" } }]
},
fills: {
fill: [{}, {}, { patternFill: { fgColor: { rgb: "FFFFF2CC" } } }]
@@ -140,6 +161,7 @@ describe("excellOffice OOXML helpers", () => {
underline: true,
strike: true,
fontSize: 14,
fontFamily: "Arial",
textColor: "0F5FAE",
fillColor: "FFF2CC",
horizontalAlign: "center",
@@ -167,6 +189,7 @@ describe("excellOffice OOXML helpers", () => {
underline: true,
strike: true,
fontSize: 14,
fontFamily: "Arial",
textColor: "0F5FAE",
fillColor: "FFF2CC",
horizontalAlign: "center",
@@ -371,7 +394,7 @@ describe("excellOffice OOXML helpers", () => {
mergedCells: [{ start: "A1", end: "C1" }],
hyperlinks: { A1: "https://example.com/budget" },
cellFormats: {
A1: { bold: true, strike: true, fontSize: 14, textColor: "0F5FAE", fillColor: "FFF2CC", horizontalAlign: "center" },
A1: { bold: true, strike: true, fontSize: 14, fontFamily: "Arial", textColor: "0F5FAE", fillColor: "FFF2CC", horizontalAlign: "center" },
AC20: { underline: true },
D20: { numberFormat: "dd.mm.yyyy" },
E20: { numberFormat: "0%" }
@@ -405,7 +428,7 @@ describe("excellOffice OOXML helpers", () => {
expect(imported.sheets[0].mergedCells).toEqual([{ start: "A1", end: "C1" }]);
expect(imported.sheets[0].hyperlinks).toEqual({ A1: "https://example.com/budget" });
expect(imported.sheets[0].cellFormats).toEqual({
A1: { bold: true, strike: true, fontSize: 14, textColor: "0F5FAE", fillColor: "FFF2CC", horizontalAlign: "center" },
A1: { bold: true, strike: true, fontSize: 14, fontFamily: "Arial", textColor: "0F5FAE", fillColor: "FFF2CC", horizontalAlign: "center" },
AC20: { underline: true },
D20: { numberFormat: "dd.mm.yyyy" },
E20: { numberFormat: "0%" }