Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/xlsx/xform/sheet/worksheet-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ class WorkSheetXform extends BaseXform {
this.map.sheetProtection.render(xmlStream, sheetProtectionModel); // Note: must be after sheetData and before autoFilter
this.map.autoFilter.render(xmlStream, model.autoFilter);
this.map.mergeCells.render(xmlStream, model.mergeCells);
this.map.conditionalFormatting.render(xmlStream, model.conditionalFormattings);// Note: must be before dataValidations
this.map.dataValidations.render(xmlStream, model.dataValidations);

// For some reason hyperlinks have to be after the data validations
this.map.hyperlinks.render(xmlStream, model.hyperlinks);

this.map.conditionalFormatting.render(xmlStream, model.conditionalFormattings);
this.map.printOptions.render(xmlStream, printOptionsModel); // Note: must be before pageMargins
this.map.pageMargins.render(xmlStream, pageMarginsModel);
this.map.pageSetup.render(xmlStream, model.pageSetup);
Expand Down
11 changes: 10 additions & 1 deletion spec/unit/xlsx/xform/sheet/data/sheet.4.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,14 @@
},
"media": [],
"tables": [],
"conditionalFormattings": []
"conditionalFormattings": [{
"ref": "A1:E7",
"rules": [
{
"type": "expression",
"formulae": ["MOD(ROW()+COLUMN(),2)=0"],
"style": {"fill": {"type": "pattern", "pattern": "solid", "bgColor": {"argb": "FF00FF00"}}}
}
]
}]
}
19 changes: 19 additions & 0 deletions spec/unit/xlsx/xform/sheet/worksheet-xform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,23 @@ describe('WorksheetXform', () => {
expect(iDataValidations).not.to.equal(-1);
expect(iHyperlinks).to.be.greaterThan(iDataValidations);
});

it('conditionalFormattings must be before dataValidations', () => {
const xform = new WorksheetXform();
const model = require('./data/sheet.4.0.json');
const xmlStream = new XmlStream();
const options = {
styles: new StylesXform(true),
hyperlinks: [],
};
xform.prepare(model, options);
xform.render(xmlStream, model);

const {xml} = xmlStream;
const iConditionalFormatting = xml.indexOf('conditionalFormatting');
const iDataValidations = xml.indexOf('dataValidations');
expect(iConditionalFormatting).not.to.equal(-1);
expect(iDataValidations).not.to.equal(-1);
expect(iConditionalFormatting).to.be.lessThan(iDataValidations);
});
});