@devmm/puredocs-excel 1.0.0 → 1.0.1

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.
package/dist/index.d.cts CHANGED
@@ -474,6 +474,8 @@ interface CellData {
474
474
  dataType?: 's' | 'n' | 'b' | 'str';
475
475
  rawValue?: string;
476
476
  formula?: string;
477
+ /** Spill range for a dynamic-array formula anchor, e.g. "A1:A3". */
478
+ arrayRef?: string;
477
479
  styleIndex: number;
478
480
  }
479
481
  declare class Cell {
@@ -511,6 +513,24 @@ declare class Cell {
511
513
  * Clears any cached value.
512
514
  */
513
515
  setFormula(formula: string): this;
516
+ /**
517
+ * Marks (or unmarks) this cell as a dynamic-array formula anchor. `spillRef`
518
+ * is the block the array spills over (e.g. "A1:C2"); pass null to revert to a
519
+ * plain scalar formula. Serialises as `<f t="array" ref="…">`.
520
+ */
521
+ setArrayRef(spillRef: string | null): this;
522
+ /** The dynamic-array spill range, or null if this is not an array anchor. */
523
+ getArrayRef(): string | null;
524
+ /**
525
+ * Sets the cached/computed result of this cell WITHOUT touching its formula.
526
+ *
527
+ * This is what a recalculation engine calls after evaluating the formula: it
528
+ * stores the value that XLSX serialises into `<v>` alongside the `<f>`. Unlike
529
+ * setValue(), it does NOT clear the formula, and strings are stored inline
530
+ * (t="str") the way Excel stores calculated string results — they are not
531
+ * added to the shared-string table.
532
+ */
533
+ setComputedValue(value: CellValue): this;
514
534
  /** Returns the formula text (without leading '='), or null if no formula. */
515
535
  getFormula(): string | null;
516
536
  /** True if this cell contains a formula. */
@@ -551,6 +571,7 @@ declare class Cell {
551
571
  children: Array<{
552
572
  tagName: string;
553
573
  textContent: string;
574
+ attributes?: Record<string, string>;
554
575
  }>;
555
576
  }, ref: string): CellData;
556
577
  }
@@ -674,6 +695,10 @@ declare class Worksheet {
674
695
  getRange(rangeReference: string): Range;
675
696
  /** Gets the raw value of a cell (for formula evaluation). */
676
697
  getCellValue(reference: string): unknown;
698
+ /** Formula text (without leading '=') of a cell, or null if it has none. */
699
+ getCellFormula(reference: string): string | null;
700
+ /** Spill range (e.g. "A1:A3") of a dynamic-array anchor, or null. Supports A1#. */
701
+ getSpillRange(reference: string): string | null;
677
702
  /**
678
703
  * Returns the 1-based extent of populated cells (largest row and column that
679
704
  * contain data). Returns zeros for an empty sheet. Useful for snapshotting a
@@ -689,6 +714,10 @@ declare class Worksheet {
689
714
  autoFitColumn(columnIndex: number): void;
690
715
  /** Sets the height of a row (1-based index). */
691
716
  setRowHeight(rowIndex: number, height: number): void;
717
+ /** Shows or hides a row (1-based index). Hidden rows affect SUBTOTAL(101-111). */
718
+ setRowHidden(rowIndex: number, hidden?: boolean): void;
719
+ /** True if the given 1-based row is hidden. */
720
+ isRowHidden(rowIndex: number): boolean;
692
721
  /** Merges cells in the given range (e.g. "A1:B2"). */
693
722
  mergeCells(rangeReference: string): void;
694
723
  /** Removes a merge for the given range reference. */
@@ -726,6 +755,56 @@ declare class Worksheet {
726
755
  loadFromXml(xml: string): void;
727
756
  }
728
757
 
758
+ /**
759
+ * Defined names (named ranges) for a workbook.
760
+ *
761
+ * A defined name maps an identifier (e.g. "TaxRate", "SalesData") to a
762
+ * refers-to expression (e.g. "Sheet1!$A$1", "Sheet1!$A$1:$B$10", "0.2*100").
763
+ * Names may be workbook-global or scoped to a single worksheet.
764
+ *
765
+ * This module only models and stores the data (and serialises it to OOXML).
766
+ * Resolution/evaluation of the refers-to expression is the responsibility of
767
+ * the formula engine (@devmm/puredocs-excel-formula), which reads names through
768
+ * Workbook.getDefinedName().
769
+ */
770
+ /** A single defined name. */
771
+ interface DefinedName {
772
+ /** The name identifier. Case-insensitive when resolved. */
773
+ readonly name: string;
774
+ /** The refers-to expression, WITHOUT a leading '='. */
775
+ readonly refersTo: string;
776
+ /**
777
+ * Worksheet name this name is scoped to, or undefined for a workbook-global
778
+ * name. Excel resolves a sheet-scoped name ahead of a global name of the
779
+ * same identifier when a formula on that sheet references it.
780
+ */
781
+ readonly scope?: string;
782
+ }
783
+ /**
784
+ * In-memory store for a workbook's defined names, with Excel scoping semantics.
785
+ * Kept separate from Workbook so the storage rules live in one place.
786
+ */
787
+ declare class DefinedNameManager {
788
+ #private;
789
+ /** All defined names, in insertion order. */
790
+ get all(): readonly DefinedName[];
791
+ get size(): number;
792
+ /**
793
+ * Adds or replaces a defined name. A name is uniquely identified by the pair
794
+ * (identifier, scope): the same identifier may exist once globally and once
795
+ * per worksheet. The leading '=' of refersTo is stripped.
796
+ */
797
+ define(name: string, refersTo: string, scope?: string): void;
798
+ /** Removes a defined name by identifier and scope. Returns true if removed. */
799
+ remove(name: string, scope?: string): boolean;
800
+ /**
801
+ * Resolves a name to its refers-to expression following Excel scoping:
802
+ * a name scoped to `sheetName` takes precedence over the workbook-global
803
+ * name of the same identifier. Returns undefined if no name matches.
804
+ */
805
+ resolve(name: string, sheetName?: string): string | undefined;
806
+ }
807
+
729
808
  declare class Workbook {
730
809
  #private;
731
810
  private constructor();
@@ -760,6 +839,30 @@ declare class Workbook {
760
839
  * Returns a worksheet by name. Throws if not found.
761
840
  */
762
841
  getWorksheet(name: string): Worksheet;
842
+ /**
843
+ * Defines (or replaces) a named range.
844
+ *
845
+ * @param name The name identifier (case-insensitive when resolved).
846
+ * @param refersTo The refers-to expression, e.g. "Sheet1!$A$1:$B$10". A
847
+ * leading '=' is optional and stripped.
848
+ * @param options `scope` restricts the name to a single worksheet; omit for
849
+ * a workbook-global name.
850
+ */
851
+ defineName(name: string, refersTo: string, options?: {
852
+ scope?: string;
853
+ }): void;
854
+ /**
855
+ * Resolves a defined name to its refers-to expression (without leading '=').
856
+ * Follows Excel scoping: a name scoped to `sheetName` wins over the global
857
+ * name of the same identifier. Returns undefined if no name matches.
858
+ *
859
+ * This is the seam the formula engine calls to resolve NamedRangeNode.
860
+ */
861
+ getDefinedName(name: string, sheetName?: string): string | undefined;
862
+ /** Removes a defined name. Returns true if a matching name was removed. */
863
+ removeName(name: string, scope?: string): boolean;
864
+ /** All defined names in the workbook, in insertion order. */
865
+ get definedNames(): readonly DefinedName[];
763
866
  /**
764
867
  * Serialises the workbook to a Uint8Array (xlsx binary).
765
868
  * Mirrors workbook.SaveAs(stream) in C#.
@@ -1013,4 +1116,4 @@ declare function setXmlEntry(entries: ZipInput, path: string, xml: string): void
1013
1116
  */
1014
1117
  declare function setBinaryEntry(entries: ZipInput, path: string, bytes: Uint8Array): void;
1015
1118
 
1016
- export { CONTENT_TYPES, Cell, type CellData, CellStyle, type CellValue, type ColorXmlAttrs, type DrawingDependentPart, type DrawingProvider, ExcelAlignment, ExcelBorder, ExcelBorderEdge, ExcelBorderStyle, ExcelColor, ExcelFill, ExcelFont, type ExcelFontOptions, ExcelHorizontalAlignment, ExcelNumberFormat, ExcelPatternType, ExcelReadingOrder, ExcelUnderline, ExcelVerticalAlignRun, ExcelVerticalAlignment, NS, type ParsedCellRef, REL_TYPES, Range, type SheetVisibility, StyleManager, WORKSHEET_DRAWING_REL_ID, Workbook, Worksheet, type XmlAttrs, XmlBuilder, type XmlElement, type ZipEntries, type ZipInput, buildDrawingXml, buildRelsXml, cellRefFromRowCol, columnLetter, columnNumber, decodeUtf8, encodeUtf8, escapeXml, fromOADate, getAttr, getElementsByTagName, isDateFormatCode, isDateFormatId, listEntries, parseCellRef, parseRangeRef, parseXml, readXmlEntry, requireXmlEntry, setBinaryEntry, setXmlEntry, toOADate, unzipXlsx, xml, zipXlsx };
1119
+ export { CONTENT_TYPES, Cell, type CellData, CellStyle, type CellValue, type ColorXmlAttrs, type DefinedName, DefinedNameManager, type DrawingDependentPart, type DrawingProvider, ExcelAlignment, ExcelBorder, ExcelBorderEdge, ExcelBorderStyle, ExcelColor, ExcelFill, ExcelFont, type ExcelFontOptions, ExcelHorizontalAlignment, ExcelNumberFormat, ExcelPatternType, ExcelReadingOrder, ExcelUnderline, ExcelVerticalAlignRun, ExcelVerticalAlignment, NS, type ParsedCellRef, REL_TYPES, Range, type SheetVisibility, StyleManager, WORKSHEET_DRAWING_REL_ID, Workbook, Worksheet, type XmlAttrs, XmlBuilder, type XmlElement, type ZipEntries, type ZipInput, buildDrawingXml, buildRelsXml, cellRefFromRowCol, columnLetter, columnNumber, decodeUtf8, encodeUtf8, escapeXml, fromOADate, getAttr, getElementsByTagName, isDateFormatCode, isDateFormatId, listEntries, parseCellRef, parseRangeRef, parseXml, readXmlEntry, requireXmlEntry, setBinaryEntry, setXmlEntry, toOADate, unzipXlsx, xml, zipXlsx };
package/dist/index.d.ts CHANGED
@@ -474,6 +474,8 @@ interface CellData {
474
474
  dataType?: 's' | 'n' | 'b' | 'str';
475
475
  rawValue?: string;
476
476
  formula?: string;
477
+ /** Spill range for a dynamic-array formula anchor, e.g. "A1:A3". */
478
+ arrayRef?: string;
477
479
  styleIndex: number;
478
480
  }
479
481
  declare class Cell {
@@ -511,6 +513,24 @@ declare class Cell {
511
513
  * Clears any cached value.
512
514
  */
513
515
  setFormula(formula: string): this;
516
+ /**
517
+ * Marks (or unmarks) this cell as a dynamic-array formula anchor. `spillRef`
518
+ * is the block the array spills over (e.g. "A1:C2"); pass null to revert to a
519
+ * plain scalar formula. Serialises as `<f t="array" ref="…">`.
520
+ */
521
+ setArrayRef(spillRef: string | null): this;
522
+ /** The dynamic-array spill range, or null if this is not an array anchor. */
523
+ getArrayRef(): string | null;
524
+ /**
525
+ * Sets the cached/computed result of this cell WITHOUT touching its formula.
526
+ *
527
+ * This is what a recalculation engine calls after evaluating the formula: it
528
+ * stores the value that XLSX serialises into `<v>` alongside the `<f>`. Unlike
529
+ * setValue(), it does NOT clear the formula, and strings are stored inline
530
+ * (t="str") the way Excel stores calculated string results — they are not
531
+ * added to the shared-string table.
532
+ */
533
+ setComputedValue(value: CellValue): this;
514
534
  /** Returns the formula text (without leading '='), or null if no formula. */
515
535
  getFormula(): string | null;
516
536
  /** True if this cell contains a formula. */
@@ -551,6 +571,7 @@ declare class Cell {
551
571
  children: Array<{
552
572
  tagName: string;
553
573
  textContent: string;
574
+ attributes?: Record<string, string>;
554
575
  }>;
555
576
  }, ref: string): CellData;
556
577
  }
@@ -674,6 +695,10 @@ declare class Worksheet {
674
695
  getRange(rangeReference: string): Range;
675
696
  /** Gets the raw value of a cell (for formula evaluation). */
676
697
  getCellValue(reference: string): unknown;
698
+ /** Formula text (without leading '=') of a cell, or null if it has none. */
699
+ getCellFormula(reference: string): string | null;
700
+ /** Spill range (e.g. "A1:A3") of a dynamic-array anchor, or null. Supports A1#. */
701
+ getSpillRange(reference: string): string | null;
677
702
  /**
678
703
  * Returns the 1-based extent of populated cells (largest row and column that
679
704
  * contain data). Returns zeros for an empty sheet. Useful for snapshotting a
@@ -689,6 +714,10 @@ declare class Worksheet {
689
714
  autoFitColumn(columnIndex: number): void;
690
715
  /** Sets the height of a row (1-based index). */
691
716
  setRowHeight(rowIndex: number, height: number): void;
717
+ /** Shows or hides a row (1-based index). Hidden rows affect SUBTOTAL(101-111). */
718
+ setRowHidden(rowIndex: number, hidden?: boolean): void;
719
+ /** True if the given 1-based row is hidden. */
720
+ isRowHidden(rowIndex: number): boolean;
692
721
  /** Merges cells in the given range (e.g. "A1:B2"). */
693
722
  mergeCells(rangeReference: string): void;
694
723
  /** Removes a merge for the given range reference. */
@@ -726,6 +755,56 @@ declare class Worksheet {
726
755
  loadFromXml(xml: string): void;
727
756
  }
728
757
 
758
+ /**
759
+ * Defined names (named ranges) for a workbook.
760
+ *
761
+ * A defined name maps an identifier (e.g. "TaxRate", "SalesData") to a
762
+ * refers-to expression (e.g. "Sheet1!$A$1", "Sheet1!$A$1:$B$10", "0.2*100").
763
+ * Names may be workbook-global or scoped to a single worksheet.
764
+ *
765
+ * This module only models and stores the data (and serialises it to OOXML).
766
+ * Resolution/evaluation of the refers-to expression is the responsibility of
767
+ * the formula engine (@devmm/puredocs-excel-formula), which reads names through
768
+ * Workbook.getDefinedName().
769
+ */
770
+ /** A single defined name. */
771
+ interface DefinedName {
772
+ /** The name identifier. Case-insensitive when resolved. */
773
+ readonly name: string;
774
+ /** The refers-to expression, WITHOUT a leading '='. */
775
+ readonly refersTo: string;
776
+ /**
777
+ * Worksheet name this name is scoped to, or undefined for a workbook-global
778
+ * name. Excel resolves a sheet-scoped name ahead of a global name of the
779
+ * same identifier when a formula on that sheet references it.
780
+ */
781
+ readonly scope?: string;
782
+ }
783
+ /**
784
+ * In-memory store for a workbook's defined names, with Excel scoping semantics.
785
+ * Kept separate from Workbook so the storage rules live in one place.
786
+ */
787
+ declare class DefinedNameManager {
788
+ #private;
789
+ /** All defined names, in insertion order. */
790
+ get all(): readonly DefinedName[];
791
+ get size(): number;
792
+ /**
793
+ * Adds or replaces a defined name. A name is uniquely identified by the pair
794
+ * (identifier, scope): the same identifier may exist once globally and once
795
+ * per worksheet. The leading '=' of refersTo is stripped.
796
+ */
797
+ define(name: string, refersTo: string, scope?: string): void;
798
+ /** Removes a defined name by identifier and scope. Returns true if removed. */
799
+ remove(name: string, scope?: string): boolean;
800
+ /**
801
+ * Resolves a name to its refers-to expression following Excel scoping:
802
+ * a name scoped to `sheetName` takes precedence over the workbook-global
803
+ * name of the same identifier. Returns undefined if no name matches.
804
+ */
805
+ resolve(name: string, sheetName?: string): string | undefined;
806
+ }
807
+
729
808
  declare class Workbook {
730
809
  #private;
731
810
  private constructor();
@@ -760,6 +839,30 @@ declare class Workbook {
760
839
  * Returns a worksheet by name. Throws if not found.
761
840
  */
762
841
  getWorksheet(name: string): Worksheet;
842
+ /**
843
+ * Defines (or replaces) a named range.
844
+ *
845
+ * @param name The name identifier (case-insensitive when resolved).
846
+ * @param refersTo The refers-to expression, e.g. "Sheet1!$A$1:$B$10". A
847
+ * leading '=' is optional and stripped.
848
+ * @param options `scope` restricts the name to a single worksheet; omit for
849
+ * a workbook-global name.
850
+ */
851
+ defineName(name: string, refersTo: string, options?: {
852
+ scope?: string;
853
+ }): void;
854
+ /**
855
+ * Resolves a defined name to its refers-to expression (without leading '=').
856
+ * Follows Excel scoping: a name scoped to `sheetName` wins over the global
857
+ * name of the same identifier. Returns undefined if no name matches.
858
+ *
859
+ * This is the seam the formula engine calls to resolve NamedRangeNode.
860
+ */
861
+ getDefinedName(name: string, sheetName?: string): string | undefined;
862
+ /** Removes a defined name. Returns true if a matching name was removed. */
863
+ removeName(name: string, scope?: string): boolean;
864
+ /** All defined names in the workbook, in insertion order. */
865
+ get definedNames(): readonly DefinedName[];
763
866
  /**
764
867
  * Serialises the workbook to a Uint8Array (xlsx binary).
765
868
  * Mirrors workbook.SaveAs(stream) in C#.
@@ -1013,4 +1116,4 @@ declare function setXmlEntry(entries: ZipInput, path: string, xml: string): void
1013
1116
  */
1014
1117
  declare function setBinaryEntry(entries: ZipInput, path: string, bytes: Uint8Array): void;
1015
1118
 
1016
- export { CONTENT_TYPES, Cell, type CellData, CellStyle, type CellValue, type ColorXmlAttrs, type DrawingDependentPart, type DrawingProvider, ExcelAlignment, ExcelBorder, ExcelBorderEdge, ExcelBorderStyle, ExcelColor, ExcelFill, ExcelFont, type ExcelFontOptions, ExcelHorizontalAlignment, ExcelNumberFormat, ExcelPatternType, ExcelReadingOrder, ExcelUnderline, ExcelVerticalAlignRun, ExcelVerticalAlignment, NS, type ParsedCellRef, REL_TYPES, Range, type SheetVisibility, StyleManager, WORKSHEET_DRAWING_REL_ID, Workbook, Worksheet, type XmlAttrs, XmlBuilder, type XmlElement, type ZipEntries, type ZipInput, buildDrawingXml, buildRelsXml, cellRefFromRowCol, columnLetter, columnNumber, decodeUtf8, encodeUtf8, escapeXml, fromOADate, getAttr, getElementsByTagName, isDateFormatCode, isDateFormatId, listEntries, parseCellRef, parseRangeRef, parseXml, readXmlEntry, requireXmlEntry, setBinaryEntry, setXmlEntry, toOADate, unzipXlsx, xml, zipXlsx };
1119
+ export { CONTENT_TYPES, Cell, type CellData, CellStyle, type CellValue, type ColorXmlAttrs, type DefinedName, DefinedNameManager, type DrawingDependentPart, type DrawingProvider, ExcelAlignment, ExcelBorder, ExcelBorderEdge, ExcelBorderStyle, ExcelColor, ExcelFill, ExcelFont, type ExcelFontOptions, ExcelHorizontalAlignment, ExcelNumberFormat, ExcelPatternType, ExcelReadingOrder, ExcelUnderline, ExcelVerticalAlignRun, ExcelVerticalAlignment, NS, type ParsedCellRef, REL_TYPES, Range, type SheetVisibility, StyleManager, WORKSHEET_DRAWING_REL_ID, Workbook, Worksheet, type XmlAttrs, XmlBuilder, type XmlElement, type ZipEntries, type ZipInput, buildDrawingXml, buildRelsXml, cellRefFromRowCol, columnLetter, columnNumber, decodeUtf8, encodeUtf8, escapeXml, fromOADate, getAttr, getElementsByTagName, isDateFormatCode, isDateFormatId, listEntries, parseCellRef, parseRangeRef, parseXml, readXmlEntry, requireXmlEntry, setBinaryEntry, setXmlEntry, toOADate, unzipXlsx, xml, zipXlsx };