Read QExcell workbook theme colors
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
worksheetXmlToHyperlinks,
|
||||
worksheetXmlToMergedCells,
|
||||
xlsxStylesXmlToCellFormatTable,
|
||||
xlsxThemeXmlToColors,
|
||||
xlsxCellToText
|
||||
} from "./excellOffice";
|
||||
|
||||
@@ -374,6 +375,39 @@ describe("excellOffice OOXML helpers", () => {
|
||||
expect(styleTable[2]).toEqual({ textColor: "C0C0C0" });
|
||||
});
|
||||
|
||||
it("использует цвета из xl/theme/theme1.xml при импорте XLSX", async () => {
|
||||
const themeXml = `<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:themeElements><a:clrScheme name="Custom"><a:dk1><a:srgbClr val="000000"/></a:dk1><a:lt1><a:srgbClr val="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="222222"/></a:dk2><a:lt2><a:srgbClr val="EEEEEE"/></a:lt2><a:accent1><a:srgbClr val="123456"/></a:accent1></a:clrScheme></a:themeElements></a:theme>`;
|
||||
const zip = new JSZip();
|
||||
zip.file("xl/workbook.xml", `<workbook><sheets><sheet name="Theme" sheetId="1" r:id="rId1"/></sheets></workbook>`);
|
||||
zip.file(
|
||||
"xl/_rels/workbook.xml.rels",
|
||||
`<Relationships><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/></Relationships>`
|
||||
);
|
||||
zip.file("xl/theme/theme1.xml", themeXml);
|
||||
zip.file(
|
||||
"xl/styles.xml",
|
||||
`<styleSheet><fonts count="2"><font/><font><color theme="4"/><name val="Calibri"/></font></fonts><fills count="1"><fill><patternFill patternType="none"/></fill></fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/><xf numFmtId="0" fontId="1" fillId="0" borderId="0"/></cellXfs></styleSheet>`
|
||||
);
|
||||
zip.file(
|
||||
"xl/worksheets/sheet1.xml",
|
||||
`<worksheet><sheetData><row r="1"><c r="A1" s="1" t="inlineStr"><is><t>Themed</t></is></c></row></sheetData></worksheet>`
|
||||
);
|
||||
|
||||
expect(xlsxThemeXmlToColors({ "a:theme": { "a:themeElements": { "a:clrScheme": { "a:accent1": { "a:srgbClr": { val: "123456" } } } } } })[4]).toBe(
|
||||
"123456"
|
||||
);
|
||||
|
||||
const blob = await zip.generateAsync({
|
||||
type: "blob",
|
||||
mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
});
|
||||
const imported = await importXlsxFile(new File([blob], "Theme.xlsx", { type: blob.type }));
|
||||
|
||||
expect(imported.sheets[0].cellFormats).toEqual({
|
||||
A1: { textColor: "123456" }
|
||||
});
|
||||
});
|
||||
|
||||
it("преобразует XML листа в модель QExcell", () => {
|
||||
const cells = worksheetXmlToCells(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user