ooxml.js 2.6.19 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -266,10 +266,18 @@ function readRawCell(tc, context, rels, pkg) {
266
266
  blocks: readBodyBlocks(tc.children, context, rels, pkg)
267
267
  };
268
268
  }
269
+ function readRowHeightPt(tr) {
270
+ const trPr = require_typed_util.childrenWithTag(tr, "w:trPr")[0];
271
+ if (trPr === void 0) return;
272
+ const trHeight = require_typed_util.childrenWithTag(trPr, "w:trHeight")[0];
273
+ const val = trHeight === void 0 ? void 0 : require_typed_util.attr(trHeight, "w:val");
274
+ return val === void 0 ? void 0 : require_typed_shared_units.twipsToPt(Number(val));
275
+ }
269
276
  function readTable(tbl, context, rels, pkg) {
270
277
  const tblGrid = require_typed_util.childrenWithTag(tbl, "w:tblGrid")[0];
271
278
  const columnWidthsPt = tblGrid === void 0 ? [] : require_typed_util.childrenWithTag(tblGrid, "w:gridCol").map((col) => require_typed_shared_units.twipsToPt(Number(require_typed_util.attr(col, "w:w") ?? "0")));
272
- const rawRows = require_typed_util.childrenWithTag(tbl, "w:tr").map((tr) => require_typed_util.childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels, pkg)));
279
+ const trs = require_typed_util.childrenWithTag(tbl, "w:tr");
280
+ const rawRows = trs.map((tr) => require_typed_util.childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels, pkg)));
273
281
  const rowColumnIndices = rawRows.map((row) => {
274
282
  const indices = [];
275
283
  let col = 0;
@@ -282,23 +290,26 @@ function readTable(tbl, context, rels, pkg) {
282
290
  return {
283
291
  kind: "table",
284
292
  columnWidthsPt,
285
- rows: rawRows.map((row, rowIndex) => ({ cells: row.map((cell, cellIndex) => {
286
- if (cell.isVMergeContinuation) return { blocks: [] };
287
- const colIndex = rowColumnIndices[rowIndex][cellIndex];
288
- let rowSpan = 1;
289
- for (let r = rowIndex + 1; r < rawRows.length; r++) {
290
- const matchIndex = rowColumnIndices[r].indexOf(colIndex);
291
- if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
292
- rowSpan++;
293
- }
294
- return {
295
- blocks: cell.blocks,
296
- colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
297
- rowSpan: rowSpan > 1 ? rowSpan : void 0,
298
- background: cell.background,
299
- borders: cell.borders
300
- };
301
- }) }))
293
+ rows: rawRows.map((row, rowIndex) => ({
294
+ heightPt: readRowHeightPt(trs[rowIndex]),
295
+ cells: row.map((cell, cellIndex) => {
296
+ if (cell.isVMergeContinuation) return { blocks: [] };
297
+ const colIndex = rowColumnIndices[rowIndex][cellIndex];
298
+ let rowSpan = 1;
299
+ for (let r = rowIndex + 1; r < rawRows.length; r++) {
300
+ const matchIndex = rowColumnIndices[r].indexOf(colIndex);
301
+ if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
302
+ rowSpan++;
303
+ }
304
+ return {
305
+ blocks: cell.blocks,
306
+ colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
307
+ rowSpan: rowSpan > 1 ? rowSpan : void 0,
308
+ background: cell.background,
309
+ borders: cell.borders
310
+ };
311
+ })
312
+ }))
302
313
  };
303
314
  }
304
315
  function readBodyBlocks(nodes, context, rels, pkg) {
@@ -265,10 +265,18 @@ function readRawCell(tc, context, rels, pkg) {
265
265
  blocks: readBodyBlocks(tc.children, context, rels, pkg)
266
266
  };
267
267
  }
268
+ function readRowHeightPt(tr) {
269
+ const trPr = childrenWithTag(tr, "w:trPr")[0];
270
+ if (trPr === void 0) return;
271
+ const trHeight = childrenWithTag(trPr, "w:trHeight")[0];
272
+ const val = trHeight === void 0 ? void 0 : attr(trHeight, "w:val");
273
+ return val === void 0 ? void 0 : twipsToPt(Number(val));
274
+ }
268
275
  function readTable(tbl, context, rels, pkg) {
269
276
  const tblGrid = childrenWithTag(tbl, "w:tblGrid")[0];
270
277
  const columnWidthsPt = tblGrid === void 0 ? [] : childrenWithTag(tblGrid, "w:gridCol").map((col) => twipsToPt(Number(attr(col, "w:w") ?? "0")));
271
- const rawRows = childrenWithTag(tbl, "w:tr").map((tr) => childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels, pkg)));
278
+ const trs = childrenWithTag(tbl, "w:tr");
279
+ const rawRows = trs.map((tr) => childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels, pkg)));
272
280
  const rowColumnIndices = rawRows.map((row) => {
273
281
  const indices = [];
274
282
  let col = 0;
@@ -281,23 +289,26 @@ function readTable(tbl, context, rels, pkg) {
281
289
  return {
282
290
  kind: "table",
283
291
  columnWidthsPt,
284
- rows: rawRows.map((row, rowIndex) => ({ cells: row.map((cell, cellIndex) => {
285
- if (cell.isVMergeContinuation) return { blocks: [] };
286
- const colIndex = rowColumnIndices[rowIndex][cellIndex];
287
- let rowSpan = 1;
288
- for (let r = rowIndex + 1; r < rawRows.length; r++) {
289
- const matchIndex = rowColumnIndices[r].indexOf(colIndex);
290
- if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
291
- rowSpan++;
292
- }
293
- return {
294
- blocks: cell.blocks,
295
- colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
296
- rowSpan: rowSpan > 1 ? rowSpan : void 0,
297
- background: cell.background,
298
- borders: cell.borders
299
- };
300
- }) }))
292
+ rows: rawRows.map((row, rowIndex) => ({
293
+ heightPt: readRowHeightPt(trs[rowIndex]),
294
+ cells: row.map((cell, cellIndex) => {
295
+ if (cell.isVMergeContinuation) return { blocks: [] };
296
+ const colIndex = rowColumnIndices[rowIndex][cellIndex];
297
+ let rowSpan = 1;
298
+ for (let r = rowIndex + 1; r < rawRows.length; r++) {
299
+ const matchIndex = rowColumnIndices[r].indexOf(colIndex);
300
+ if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
301
+ rowSpan++;
302
+ }
303
+ return {
304
+ blocks: cell.blocks,
305
+ colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
306
+ rowSpan: rowSpan > 1 ? rowSpan : void 0,
307
+ background: cell.background,
308
+ borders: cell.borders
309
+ };
310
+ })
311
+ }))
301
312
  };
302
313
  }
303
314
  function readBodyBlocks(nodes, context, rels, pkg) {
@@ -194,28 +194,55 @@ function buildStylesPart(cellFormats) {
194
194
  }));
195
195
  children.push(require_xml_fragment.el("numFmts", { count: String(numFmtElements.length) }, numFmtElements));
196
196
  }
197
- children.push(require_xml_fragment.el("fonts", { count: "1" }, [require_xml_fragment.el("font", {}, [require_xml_fragment.el("sz", { val: "11" }), require_xml_fragment.el("name", { val: "Calibri" })])]), require_xml_fragment.el("fills", { count: "2" }, [require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "none" })]), require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "gray125" })])]), require_xml_fragment.el("borders", { count: "1" }, [require_xml_fragment.el("border", {}, [
198
- require_xml_fragment.el("left"),
199
- require_xml_fragment.el("right"),
200
- require_xml_fragment.el("top"),
201
- require_xml_fragment.el("bottom"),
202
- require_xml_fragment.el("diagonal")
203
- ])]), require_xml_fragment.el("cellStyleXfs", { count: "1" }, [require_xml_fragment.el("xf", {
197
+ const fillElements = cellFormats.fillDeclarations().map((fill) => {
198
+ if (fill.patternType === "solid") {
199
+ const rgb = fill.rgb ?? "000000";
200
+ return require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "solid" }, [require_xml_fragment.el("fgColor", { rgb: `FF${rgb}` }), require_xml_fragment.el("bgColor", { indexed: "64" })])]);
201
+ }
202
+ return require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: fill.patternType })]);
203
+ });
204
+ const borderElements = cellFormats.borderDeclarations().map((border) => {
205
+ const edgeElements = [];
206
+ for (const edge of [
207
+ "left",
208
+ "right",
209
+ "top",
210
+ "bottom"
211
+ ]) {
212
+ const present = border.edges[edge];
213
+ if (present !== void 0) edgeElements.push(require_xml_fragment.el(edge, { style: present.style }, [require_xml_fragment.el("color", { rgb: `FF${present.rgb}` })]));
214
+ else edgeElements.push(require_xml_fragment.el(edge));
215
+ }
216
+ edgeElements.push(require_xml_fragment.el("diagonal"));
217
+ return require_xml_fragment.el("border", {}, edgeElements);
218
+ });
219
+ children.push(require_xml_fragment.el("fonts", { count: "1" }, [require_xml_fragment.el("font", {}, [require_xml_fragment.el("sz", { val: "11" }), require_xml_fragment.el("name", { val: "Calibri" })])]), require_xml_fragment.el("fills", { count: String(fillElements.length) }, fillElements), require_xml_fragment.el("borders", { count: String(borderElements.length) }, borderElements), require_xml_fragment.el("cellStyleXfs", { count: "1" }, [require_xml_fragment.el("xf", {
204
220
  numFmtId: "0",
205
221
  fontId: "0",
206
222
  fillId: "0",
207
223
  borderId: "0"
208
224
  })]));
209
- const xfElements = cellFormats.cellFormats().map((numFmtId) => {
225
+ const xfElements = cellFormats.cellFormatRecords().map((record) => {
210
226
  const attrs = {
211
- numFmtId: String(numFmtId),
227
+ numFmtId: String(record.numFmtId),
212
228
  fontId: "0",
213
- fillId: "0",
214
- borderId: "0",
229
+ fillId: String(record.fillId),
230
+ borderId: String(record.borderId),
215
231
  xfId: "0"
216
232
  };
217
- if (numFmtId !== 0) attrs.applyNumberFormat = require_typed_xlsx_util.writeXmlBool(true);
218
- return require_xml_fragment.el("xf", attrs);
233
+ if (record.numFmtId !== 0) attrs.applyNumberFormat = require_typed_xlsx_util.writeXmlBool(true);
234
+ if (record.fillId !== require_typed_xlsx_styles.RESERVED_FILL_INDICES.none) attrs.applyFill = require_typed_xlsx_util.writeXmlBool(true);
235
+ if (record.borderId !== require_typed_xlsx_styles.RESERVED_BORDER_INDICES.empty) attrs.applyBorder = require_typed_xlsx_util.writeXmlBool(true);
236
+ const xfChildren = [];
237
+ if (record.alignment !== void 0) {
238
+ attrs.applyAlignment = require_typed_xlsx_util.writeXmlBool(true);
239
+ const alignmentAttrs = {};
240
+ if (record.alignment.horizontal !== void 0) alignmentAttrs.horizontal = record.alignment.horizontal;
241
+ if (record.alignment.vertical === "top") alignmentAttrs.vertical = "top";
242
+ else if (record.alignment.vertical === "middle") alignmentAttrs.vertical = "center";
243
+ xfChildren.push(require_xml_fragment.el("alignment", alignmentAttrs));
244
+ }
245
+ return require_xml_fragment.el("xf", attrs, xfChildren);
219
246
  });
220
247
  children.push(require_xml_fragment.el("cellXfs", { count: String(xfElements.length) }, xfElements));
221
248
  children.push(require_xml_fragment.el("cellStyles", { count: "1" }, [require_xml_fragment.el("cellStyle", {
@@ -332,7 +359,17 @@ function renderTemporal(serial, iso, format, isFormulaResult, sharedStrings) {
332
359
  function buildCellElement(cell, sharedStrings, cellFormats) {
333
360
  const children = [];
334
361
  const rendered = renderCellValue(cell.value, cell.formula !== void 0, sharedStrings);
335
- const styleIndex = rendered?.format === void 0 ? 0 : cellFormats.intern(rendered.format);
362
+ const decoration = cell.background !== void 0 || cell.borders !== void 0 || cell.alignment !== void 0 || cell.verticalAlignment !== void 0 ? {
363
+ background: cell.background,
364
+ borders: cell.borders,
365
+ alignment: cell.alignment,
366
+ verticalAlignment: cell.verticalAlignment
367
+ } : void 0;
368
+ const format = rendered?.format;
369
+ const styleIndex = format === void 0 && decoration === void 0 ? 0 : cellFormats.intern(format ?? {
370
+ kind: "builtin",
371
+ id: 0
372
+ }, decoration);
336
373
  const attrs = {
337
374
  r: require_typed_xlsx_a1.cellReference(cell.row, cell.column),
338
375
  s: String(styleIndex)
@@ -8,7 +8,7 @@ import { BOOLEAN_NUMBER_FORMAT, DATE_NUMBER_FORMAT, DATE_TIME_NUMBER_FORMAT, PER
8
8
  import { pageSizeToPaperSizeCode, ptToUniversalMeasure, writeXmlBool } from "./util.js";
9
9
  import { DEFAULT_HEADER_FOOTER_MARGIN_PT } from "./print-settings.js";
10
10
  import { isoDateTimeToSerial, isoDateToSerial, isoTimeToSerial } from "./serial.js";
11
- import { CellFormatTable } from "./styles.js";
11
+ import { CellFormatTable, RESERVED_BORDER_INDICES, RESERVED_FILL_INDICES } from "./styles.js";
12
12
  import { ptToColumnWidthChars } from "./units.js";
13
13
  //#region src/typed/xlsx/build.ts
14
14
  const SML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
@@ -193,28 +193,55 @@ function buildStylesPart(cellFormats) {
193
193
  }));
194
194
  children.push(el("numFmts", { count: String(numFmtElements.length) }, numFmtElements));
195
195
  }
196
- children.push(el("fonts", { count: "1" }, [el("font", {}, [el("sz", { val: "11" }), el("name", { val: "Calibri" })])]), el("fills", { count: "2" }, [el("fill", {}, [el("patternFill", { patternType: "none" })]), el("fill", {}, [el("patternFill", { patternType: "gray125" })])]), el("borders", { count: "1" }, [el("border", {}, [
197
- el("left"),
198
- el("right"),
199
- el("top"),
200
- el("bottom"),
201
- el("diagonal")
202
- ])]), el("cellStyleXfs", { count: "1" }, [el("xf", {
196
+ const fillElements = cellFormats.fillDeclarations().map((fill) => {
197
+ if (fill.patternType === "solid") {
198
+ const rgb = fill.rgb ?? "000000";
199
+ return el("fill", {}, [el("patternFill", { patternType: "solid" }, [el("fgColor", { rgb: `FF${rgb}` }), el("bgColor", { indexed: "64" })])]);
200
+ }
201
+ return el("fill", {}, [el("patternFill", { patternType: fill.patternType })]);
202
+ });
203
+ const borderElements = cellFormats.borderDeclarations().map((border) => {
204
+ const edgeElements = [];
205
+ for (const edge of [
206
+ "left",
207
+ "right",
208
+ "top",
209
+ "bottom"
210
+ ]) {
211
+ const present = border.edges[edge];
212
+ if (present !== void 0) edgeElements.push(el(edge, { style: present.style }, [el("color", { rgb: `FF${present.rgb}` })]));
213
+ else edgeElements.push(el(edge));
214
+ }
215
+ edgeElements.push(el("diagonal"));
216
+ return el("border", {}, edgeElements);
217
+ });
218
+ children.push(el("fonts", { count: "1" }, [el("font", {}, [el("sz", { val: "11" }), el("name", { val: "Calibri" })])]), el("fills", { count: String(fillElements.length) }, fillElements), el("borders", { count: String(borderElements.length) }, borderElements), el("cellStyleXfs", { count: "1" }, [el("xf", {
203
219
  numFmtId: "0",
204
220
  fontId: "0",
205
221
  fillId: "0",
206
222
  borderId: "0"
207
223
  })]));
208
- const xfElements = cellFormats.cellFormats().map((numFmtId) => {
224
+ const xfElements = cellFormats.cellFormatRecords().map((record) => {
209
225
  const attrs = {
210
- numFmtId: String(numFmtId),
226
+ numFmtId: String(record.numFmtId),
211
227
  fontId: "0",
212
- fillId: "0",
213
- borderId: "0",
228
+ fillId: String(record.fillId),
229
+ borderId: String(record.borderId),
214
230
  xfId: "0"
215
231
  };
216
- if (numFmtId !== 0) attrs.applyNumberFormat = writeXmlBool(true);
217
- return el("xf", attrs);
232
+ if (record.numFmtId !== 0) attrs.applyNumberFormat = writeXmlBool(true);
233
+ if (record.fillId !== RESERVED_FILL_INDICES.none) attrs.applyFill = writeXmlBool(true);
234
+ if (record.borderId !== RESERVED_BORDER_INDICES.empty) attrs.applyBorder = writeXmlBool(true);
235
+ const xfChildren = [];
236
+ if (record.alignment !== void 0) {
237
+ attrs.applyAlignment = writeXmlBool(true);
238
+ const alignmentAttrs = {};
239
+ if (record.alignment.horizontal !== void 0) alignmentAttrs.horizontal = record.alignment.horizontal;
240
+ if (record.alignment.vertical === "top") alignmentAttrs.vertical = "top";
241
+ else if (record.alignment.vertical === "middle") alignmentAttrs.vertical = "center";
242
+ xfChildren.push(el("alignment", alignmentAttrs));
243
+ }
244
+ return el("xf", attrs, xfChildren);
218
245
  });
219
246
  children.push(el("cellXfs", { count: String(xfElements.length) }, xfElements));
220
247
  children.push(el("cellStyles", { count: "1" }, [el("cellStyle", {
@@ -331,7 +358,17 @@ function renderTemporal(serial, iso, format, isFormulaResult, sharedStrings) {
331
358
  function buildCellElement(cell, sharedStrings, cellFormats) {
332
359
  const children = [];
333
360
  const rendered = renderCellValue(cell.value, cell.formula !== void 0, sharedStrings);
334
- const styleIndex = rendered?.format === void 0 ? 0 : cellFormats.intern(rendered.format);
361
+ const decoration = cell.background !== void 0 || cell.borders !== void 0 || cell.alignment !== void 0 || cell.verticalAlignment !== void 0 ? {
362
+ background: cell.background,
363
+ borders: cell.borders,
364
+ alignment: cell.alignment,
365
+ verticalAlignment: cell.verticalAlignment
366
+ } : void 0;
367
+ const format = rendered?.format;
368
+ const styleIndex = format === void 0 && decoration === void 0 ? 0 : cellFormats.intern(format ?? {
369
+ kind: "builtin",
370
+ id: 0
371
+ }, decoration);
335
372
  const attrs = {
336
373
  r: cellReference(cell.row, cell.column),
337
374
  s: String(styleIndex)
@@ -98,16 +98,21 @@ function deriveDisplayText(value) {
98
98
  }
99
99
  const DEFAULT_CELL_STYLE_INDEX = 0;
100
100
  const PLAIN_NUMBER = { kind: "number" };
101
- function readNumericFormatContext(pkg) {
101
+ function readCellFormatContext(pkg) {
102
102
  return {
103
- classes: require_typed_xlsx_styles.readCellFormatCodes(pkg).map((code) => code === void 0 ? PLAIN_NUMBER : require_typed_xlsx_number_format.classifyNumberFormat(code)),
103
+ entries: require_typed_xlsx_styles.readCellStyles(pkg),
104
104
  date1904: require_typed_xlsx_serial.readDate1904(pkg)
105
105
  };
106
106
  }
107
- function numberFormatOf(cell, context) {
107
+ function entryOf(cell, context) {
108
108
  const raw = require_typed_util.attr(cell, "s");
109
109
  const index = raw === void 0 ? DEFAULT_CELL_STYLE_INDEX : Number.parseInt(raw, 10);
110
- return (Number.isInteger(index) ? context.classes[index] : void 0) ?? PLAIN_NUMBER;
110
+ return Number.isInteger(index) ? context.entries[index] : void 0;
111
+ }
112
+ function numberFormatOf(cell, context) {
113
+ const entry = entryOf(cell, context);
114
+ if (entry?.numberFormatCode === void 0) return PLAIN_NUMBER;
115
+ return require_typed_xlsx_number_format.classifyNumberFormat(entry.numberFormatCode);
111
116
  }
112
117
  function resolveNumericValue(num, cell, context) {
113
118
  const format = numberFormatOf(cell, context);
@@ -231,13 +236,13 @@ function readCellValue(cell, sharedStrings, numericFormats) {
231
236
  displayText: deriveDisplayText(value)
232
237
  };
233
238
  }
234
- function readCell(cell, sharedStrings, numericFormats) {
239
+ function readCell(cell, sharedStrings, context) {
235
240
  const reference = require_typed_util.attr(cell, "r");
236
241
  const position = reference === void 0 ? void 0 : require_typed_xlsx_a1.parseCellReference(reference);
237
242
  if (position === void 0) return;
238
243
  const formulaEl = require_typed_util.childrenWithTag(cell, "f")[0];
239
244
  const formula = formulaEl === void 0 ? void 0 : require_typed_util.textContent(formulaEl);
240
- const resolved = readCellValue(cell, sharedStrings, numericFormats);
245
+ const resolved = readCellValue(cell, sharedStrings, context);
241
246
  if (resolved === void 0) {
242
247
  if (formula === void 0) return;
243
248
  return {
@@ -255,6 +260,13 @@ function readCell(cell, sharedStrings, numericFormats) {
255
260
  displayText: resolved.displayText
256
261
  };
257
262
  if (formula !== void 0) cellEntry.formula = formula;
263
+ const entry = entryOf(cell, context);
264
+ if (entry !== void 0) {
265
+ if (entry.background !== void 0) cellEntry.background = entry.background;
266
+ if (entry.borders !== void 0) cellEntry.borders = entry.borders;
267
+ if (entry.alignment !== void 0) cellEntry.alignment = entry.alignment;
268
+ if (entry.verticalAlignment !== void 0) cellEntry.verticalAlignment = entry.verticalAlignment;
269
+ }
258
270
  return cellEntry;
259
271
  }
260
272
  function applyMergedRanges(worksheet, cells) {
@@ -274,18 +286,18 @@ function applyMergedRanges(worksheet, cells) {
274
286
  if (rowSpan > 1) anchor.rowSpan = rowSpan;
275
287
  }
276
288
  }
277
- function readCells(worksheet, sharedStrings, numericFormats) {
289
+ function readCells(worksheet, sharedStrings, context) {
278
290
  const sheetData = require_typed_util.childrenWithTag(worksheet, "sheetData")[0];
279
291
  if (sheetData === void 0) return [];
280
292
  const cells = [];
281
293
  for (const row of require_typed_util.childrenWithTag(sheetData, "row")) for (const cell of require_typed_util.childrenWithTag(row, "c")) {
282
- const read = readCell(cell, sharedStrings, numericFormats);
294
+ const read = readCell(cell, sharedStrings, context);
283
295
  if (read !== void 0) cells.push(read);
284
296
  }
285
297
  applyMergedRanges(worksheet, cells);
286
298
  return cells;
287
299
  }
288
- function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, numericFormats) {
300
+ function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, context) {
289
301
  const worksheet = require_typed_util.rootElement(pkg.parts[entry.path]);
290
302
  if (worksheet === void 0) return {
291
303
  name: entry.name,
@@ -297,7 +309,7 @@ function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, n
297
309
  };
298
310
  return {
299
311
  name: entry.name,
300
- cells: readCells(worksheet, sharedStrings, numericFormats),
312
+ cells: readCells(worksheet, sharedStrings, context),
301
313
  columns: readColumns(worksheet),
302
314
  rows: readRows(worksheet),
303
315
  images: [],
@@ -315,8 +327,8 @@ function fallbackEmptyWorksheet() {
315
327
  function readXlsxContent(pkg) {
316
328
  const sharedStrings = require_typed_xlsx_shared_strings.loadSharedStrings(pkg);
317
329
  const definedNamesBySheet = require_typed_xlsx_defined_names.readDefinedNamesBySheet(pkg);
318
- const numericFormats = readNumericFormatContext(pkg);
319
- const sheets = resolveSheetEntries(pkg).map((entry, sheetIndex) => readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, numericFormats));
330
+ const context = readCellFormatContext(pkg);
331
+ const sheets = resolveSheetEntries(pkg).map((entry, sheetIndex) => readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, context));
320
332
  return {
321
333
  kind: "spreadsheet",
322
334
  formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
@@ -7,7 +7,7 @@ import { classifyNumberFormat } from "./number-format.js";
7
7
  import { readXmlBool } from "./util.js";
8
8
  import { readPrintSettings } from "./print-settings.js";
9
9
  import { readDate1904, serialToIsoDate, serialToIsoDateTime, serialToIsoTime } from "./serial.js";
10
- import { readCellFormatCodes } from "./styles.js";
10
+ import { readCellStyles } from "./styles.js";
11
11
  import { columnWidthCharsToPt } from "./units.js";
12
12
  import { CONTENT_FORMAT_VERSION } from "document-schema.js";
13
13
  //#region src/typed/xlsx/content.ts
@@ -97,16 +97,21 @@ function deriveDisplayText(value) {
97
97
  }
98
98
  const DEFAULT_CELL_STYLE_INDEX = 0;
99
99
  const PLAIN_NUMBER = { kind: "number" };
100
- function readNumericFormatContext(pkg) {
100
+ function readCellFormatContext(pkg) {
101
101
  return {
102
- classes: readCellFormatCodes(pkg).map((code) => code === void 0 ? PLAIN_NUMBER : classifyNumberFormat(code)),
102
+ entries: readCellStyles(pkg),
103
103
  date1904: readDate1904(pkg)
104
104
  };
105
105
  }
106
- function numberFormatOf(cell, context) {
106
+ function entryOf(cell, context) {
107
107
  const raw = attr(cell, "s");
108
108
  const index = raw === void 0 ? DEFAULT_CELL_STYLE_INDEX : Number.parseInt(raw, 10);
109
- return (Number.isInteger(index) ? context.classes[index] : void 0) ?? PLAIN_NUMBER;
109
+ return Number.isInteger(index) ? context.entries[index] : void 0;
110
+ }
111
+ function numberFormatOf(cell, context) {
112
+ const entry = entryOf(cell, context);
113
+ if (entry?.numberFormatCode === void 0) return PLAIN_NUMBER;
114
+ return classifyNumberFormat(entry.numberFormatCode);
110
115
  }
111
116
  function resolveNumericValue(num, cell, context) {
112
117
  const format = numberFormatOf(cell, context);
@@ -230,13 +235,13 @@ function readCellValue(cell, sharedStrings, numericFormats) {
230
235
  displayText: deriveDisplayText(value)
231
236
  };
232
237
  }
233
- function readCell(cell, sharedStrings, numericFormats) {
238
+ function readCell(cell, sharedStrings, context) {
234
239
  const reference = attr(cell, "r");
235
240
  const position = reference === void 0 ? void 0 : parseCellReference(reference);
236
241
  if (position === void 0) return;
237
242
  const formulaEl = childrenWithTag(cell, "f")[0];
238
243
  const formula = formulaEl === void 0 ? void 0 : textContent(formulaEl);
239
- const resolved = readCellValue(cell, sharedStrings, numericFormats);
244
+ const resolved = readCellValue(cell, sharedStrings, context);
240
245
  if (resolved === void 0) {
241
246
  if (formula === void 0) return;
242
247
  return {
@@ -254,6 +259,13 @@ function readCell(cell, sharedStrings, numericFormats) {
254
259
  displayText: resolved.displayText
255
260
  };
256
261
  if (formula !== void 0) cellEntry.formula = formula;
262
+ const entry = entryOf(cell, context);
263
+ if (entry !== void 0) {
264
+ if (entry.background !== void 0) cellEntry.background = entry.background;
265
+ if (entry.borders !== void 0) cellEntry.borders = entry.borders;
266
+ if (entry.alignment !== void 0) cellEntry.alignment = entry.alignment;
267
+ if (entry.verticalAlignment !== void 0) cellEntry.verticalAlignment = entry.verticalAlignment;
268
+ }
257
269
  return cellEntry;
258
270
  }
259
271
  function applyMergedRanges(worksheet, cells) {
@@ -273,18 +285,18 @@ function applyMergedRanges(worksheet, cells) {
273
285
  if (rowSpan > 1) anchor.rowSpan = rowSpan;
274
286
  }
275
287
  }
276
- function readCells(worksheet, sharedStrings, numericFormats) {
288
+ function readCells(worksheet, sharedStrings, context) {
277
289
  const sheetData = childrenWithTag(worksheet, "sheetData")[0];
278
290
  if (sheetData === void 0) return [];
279
291
  const cells = [];
280
292
  for (const row of childrenWithTag(sheetData, "row")) for (const cell of childrenWithTag(row, "c")) {
281
- const read = readCell(cell, sharedStrings, numericFormats);
293
+ const read = readCell(cell, sharedStrings, context);
282
294
  if (read !== void 0) cells.push(read);
283
295
  }
284
296
  applyMergedRanges(worksheet, cells);
285
297
  return cells;
286
298
  }
287
- function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, numericFormats) {
299
+ function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, context) {
288
300
  const worksheet = rootElement(pkg.parts[entry.path]);
289
301
  if (worksheet === void 0) return {
290
302
  name: entry.name,
@@ -296,7 +308,7 @@ function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, n
296
308
  };
297
309
  return {
298
310
  name: entry.name,
299
- cells: readCells(worksheet, sharedStrings, numericFormats),
311
+ cells: readCells(worksheet, sharedStrings, context),
300
312
  columns: readColumns(worksheet),
301
313
  rows: readRows(worksheet),
302
314
  images: [],
@@ -314,8 +326,8 @@ function fallbackEmptyWorksheet() {
314
326
  function readXlsxContent(pkg) {
315
327
  const sharedStrings = loadSharedStrings(pkg);
316
328
  const definedNamesBySheet = readDefinedNamesBySheet(pkg);
317
- const numericFormats = readNumericFormatContext(pkg);
318
- const sheets = resolveSheetEntries(pkg).map((entry, sheetIndex) => readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, numericFormats));
329
+ const context = readCellFormatContext(pkg);
330
+ const sheets = resolveSheetEntries(pkg).map((entry, sheetIndex) => readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, context));
319
331
  return {
320
332
  kind: "spreadsheet",
321
333
  formatVersion: CONTENT_FORMAT_VERSION,