heading1CellsInfo = {
let heading1XfId = null;
let stylesDoc = parseXml(stylesXml);
let cellStyles = stylesDoc.getElementsByTagName("cellStyle");
for (let i = 0; i < cellStyles.length; i++) {
let cellStyle = cellStyles[i];
let name = cellStyle.getAttribute("name");
let xfId = cellStyle.getAttribute("xfId");
if (name === "Heading 1") {
heading1XfId = xfId;
}
}
if (heading1XfId == null) return null;
let heading1Styles = {};
let cellXfs = stylesDoc
.getElementsByTagName("cellXfs")
.item(0)
.getElementsByTagName("xf");
for (let i = 0; i < cellXfs.length; i++) {
let xf = cellXfs[i];
if (xf.getAttribute("xfId") === heading1XfId) {
heading1Styles["" + i] = 1;
}
}
let result = [];
for (let sheet of sheets) {
let sheetFileName = "xl/" + sheet.filename;
if (z.filenames.includes(sheetFileName)) {
let sheetDoc = parseXml(await z.file(sheetFileName).text());
let hasA1Heading1 = false;
let otherHeading1 = false;
let cells = sheetDoc.getElementsByTagName("c");
for (let i = 0; i < cells.length; i++) {
let cell = cells[i];
if (
cell.hasAttribute("r") &&
cell.hasAttribute("s") &&
cell.getAttribute("s") in heading1Styles
) {
if (cell.getAttribute("r") === "A1") {
hasA1Heading1 = true;
} else {
otherHeading1 = cell.getAttribute("r");
}
}
}
let problems = "";
if (!hasA1Heading1) problems += "(Cell A1 does not have Heading 1 style)";
if (otherHeading1)
problems +=
" (At least one cell other than A1 has Heading 1 style: cell " +
otherHeading1 +
")";
if (problems) result.push({ sheet, problems });
}
}
return result;
}