UNPKG

excelize-wasm

Version:

A pure WebAssembly / Javascript port of Go Excelize library that allow you to write to and read from XLAM / XLSM / XLSX / XLTM / XLTX files

1,562 lines (1,483 loc) 178 kB
// Copyright 2022 - 2026 The excelize-wasm Authors. All rights reserved. Use of // this source code is governed by a BSD-style license that can be found in // the LICENSE file. // // Package excelize providing a set of functions that allow you to write to and // read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and // writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. // Supports complex components by high compatibility. // // Type definitions for excelize-wasm declare module 'excelize-wasm' { /** * AppProperties directly maps the document application properties. */ export type AppProperties = { Application?: string; ScaleCrop?: boolean; DocSecurity?: number; Company?: string; LinksUpToDate?: boolean; HyperlinksChanged?: boolean; AppVersion?: string; }; /** * This section defines the currently supported country code types * enumeration for apply number format. */ export enum CultureName { CultureNameUnknown, CultureNameEnUS, CultureNameJaJP, CultureNameKoKR, CultureNameZhCN, CultureNameZhTW, } /** * This section defines the cell value types enumeration. */ export enum CellType { CellTypeUnset, CellTypeBool, CellTypeDate, CellTypeError, CellTypeFormula, CellTypeInlineString, CellTypeNumber, CellTypeSharedString, } /** * FormControlType is the type of supported form controls. */ export enum FormControlType { FormControlNote, FormControlButton, FormControlOptionButton, FormControlSpinButton, FormControlCheckBox, FormControlGroupBox, FormControlLabel, FormControlScrollBar, } /** * LineDashType defines the currently supported line dash types enumeration. */ export enum LineDashType { LineDashUnset, LineDashSolid, LineDashDot, LineDashDash, LineDashLgDash, LineDashSashDot, LineDashLgDashDot, LineDashLgDashDotDot, LineDashSysDash, LineDashSysDot, LineDashSysDashDot, LineDashSysDashDotDot, } /** * LineType defines the currently supported line types enumeration. */ export enum LineType { LineUnset, LineSolid, LineNone, LineAutomatic, } /** * Options define the options for o`pen and reading spreadsheet. * * MaxCalcIterations specifies the maximum iterations for iterative * calculation, the default value is 0. * * Password specifies the password of the spreadsheet in plain text. * * RawCellValue specifies if apply the number format for the cell value or get * the raw value. * * UnzipSizeLimit specifies the unzip size limit in bytes on open the * spreadsheet, this value should be greater than or equal to * UnzipXMLSizeLimit, the default size limit is 16GB. * * UnzipXMLSizeLimit specifies the memory limit on unzipping worksheet and * shared string table in bytes, worksheet XML will be extracted to system * temporary directory when the file size is over this value, this value * should be less than or equal to UnzipSizeLimit, the default value is * 16MB. * * TmpDir specifies the temporary directory for creating temporary files, if * the value is empty, the system default temporary directory will be used. * * ShortDatePattern specifies the short date number format code. In the * spreadsheet applications, date formats display date and time serial numbers * as date values. Date formats that begin with an asterisk (*) respond to * changes in regional date and time settings that are specified for the * operating system. Formats without an asterisk are not affected by operating * system settings. The ShortDatePattern used for specifies apply date formats * that begin with an asterisk. * * LongDatePattern specifies the long date number format code. * * LongTimePattern specifies the long time number format code. * * CultureInfo specifies the country code for applying built-in language * number format code these effect by the system's local language settings. */ export type Options = { MaxCalcIterations?: number; Password?: string; RawCellValue?: boolean; UnzipSizeLimit?: number; UnzipXMLSizeLimit?: number; TmpDir?: string; ShortDatePattern?: string; LongDatePattern?: string; LongTimePattern?: string; CultureInfo?: CultureName; }; /** * Border directly maps the border settings of the cells. */ export type Border = { Type?: string; Color?: string; Style?: number; }; /** * Fill directly maps the fill settings of the cells. */ export type Fill = { Type?: string; Pattern?: number; Color?: string[]; Shading?: number; Transparency?: number; }; /** * Font directly maps the font settings of the fonts. */ export type Font = { Bold?: boolean; Italic?: boolean; Underline?: string; Family?: string; Size?: number; Strike?: boolean; Color?: string; ColorIndexed?: number; ColorTheme?: number; ColorTint?: number; VertAlign?: string; }; /** * Alignment directly maps the alignment settings of the cells. */ export type Alignment = { Horizontal?: string; Indent?: number; JustifyLastLine?: boolean; ReadingOrder?: number; RelativeIndent?: number; ShrinkToFit?: boolean; TextRotation?: number; Vertical?: string; WrapText?: boolean; }; /** * Protection directly maps the protection settings of the cells. */ export type Protection = { Hidden?: boolean; Locked?: boolean; }; /** * Style directly maps the style settings of the cells. */ export type Style = { Border?: Border[]; Fill?: Fill; Font?: Font; Alignment?: Alignment; Protection?: Protection; NumFmt?: number; DecimalPlaces?: number; CustomNumFmt?: string; NegRed?: boolean; }; /** * Selection directly maps the settings of the worksheet selection. */ export type Selection = { SQRef?: string; ActiveCell?: string; Pane?: string; }; /** * Panes directly maps the settings of the panes. */ export type Panes = { Freeze?: boolean; Split?: boolean; XSplit?: number; YSplit?: number; TopLeftCell?: string; ActivePane?: string; Selection?: Selection[]; }; /** * ConditionalFormatOptions directly maps the conditional format settings of * the cells. */ export type ConditionalFormatOptions = { Type?: string; AboveAverage?: boolean; Percent?: boolean; Format?: number; Criteria?: string; Value?: string; MinType?: string; MidType?: string; MaxType?: string; MinValue?: string; MidValue?: string; MaxValue?: string; MinColor?: string; MidColor?: string; MaxColor?: string; BarColor?: string; BarBorderColor?: string; BarDirection?: string; BarOnly?: boolean; BarSolid?: boolean; IconStyle?: string; ReverseIcons?: boolean; IconsOnly?: boolean; StopIfTrue?: boolean; }; /** * CustomProperty directly maps the custom property of the workbook. The value * date type may be one of the following: number, boolean, string or null. */ export type CustomProperty = { Name: string; Value?: boolean | number | string | null; }; /** * Shape directly maps the format settings of the shape. */ export type Shape = { Cell: string; Type?: string; Macro?: string; Width?: number; Height?: number; Format?: GraphicOptions; Fill?: Fill; Line?: LineOptions; Paragraph?: RichTextRun[]; }; /** * SlicerOptions represents the settings of the slicer. * * Name specifies the slicer name, should be an existing field name of the * given table or pivot table, this setting is required. * * Cell specifies the left top cell coordinates the position for inserting the * slicer, this setting is required. * * TableSheet specifies the worksheet name of the table or pivot table, this * setting is required. * * TableName specifies the name of the table or pivot table, this setting is * required. * * Caption specifies the caption of the slicer, this setting is optional. * * Macro used for set macro for the slicer, the workbook extension should be * XLSM or XLTM. * * Width specifies the width of the slicer, this setting is optional. * * Height specifies the height of the slicer, this setting is optional. * * DisplayHeader specifies if display header of the slicer, this setting is * optional, the default setting is display. * * ItemDesc specifies descending (Z-A) item sorting, this setting is optional, * and the default setting is false (represents ascending). * * Format specifies the format of the slicer, this setting is optional. * * SelectedItems option is used to specify the default selected items in a * slicer. It is currently only supported for slicers in pivot tables. The * selected items must fall within the range of items selected in the pivot * table. If the pivot table is created using the AddPivotTable function, the * same field must also have its selected item range specified at the time the * pivot table is created. */ export type SlicerOptions = { Name: string; Cell: string; TableSheet: string; TableName: string; Caption?: string; Macro?: string; Width?: number; Height?: number; DisplayHeader?: boolean; ItemDesc?: boolean; Format?: GraphicOptions; SelectedItems?: string[]; }; /** * SparklineOptions directly maps the settings of the sparkline. */ export type SparklineOptions = { Location?: string[]; Range?: string[]; Max?: number; CustMax?: number; Min?: number; CustMin?: number; Type?: string; Weight?: number; DateAxis?: boolean; Markers?: boolean; High?: boolean; Low?: boolean; First?: boolean; Last?: boolean; Negative?: boolean; Axis?: boolean; Hidden?: boolean; Reverse?: boolean; Style?: number; SeriesColor?: string; NegativeColor?: string; MarkersColor?: string; FirstColor?: string; LastColor?: string; HightColor?: string; LowColor?: string; EmptyCells?: string; }; /** * GraphicOptions directly maps the format settings of the picture. */ export type GraphicOptions = { AltText?: string; Name?: string; PrintObject?: boolean; Locked?: boolean; LockAspectRatio?: boolean; AutoFit?: boolean; AutoFitIgnoreAspect?: boolean; OffsetX?: number; OffsetY?: number; ScaleX?: number; ScaleY?: number; Hyperlink?: string; HyperlinkType?: string; Positioning?: string; }; /** * TableOptions directly maps the format settings of the table. */ export type TableOptions = { Range: string; Name?: string; StyleName?: string; ShowFirstColumn?: boolean; ShowLastColumn?: boolean; ShowRowStripes?: boolean; ShowColumnStripes?: boolean; }; /** * AutoFilterOptions directly maps the auto filter settings. */ export type AutoFilterOptions = { Column?: string; Expression?: string; }; /** * FormControl directly maps the form controls information. */ export type FormControl = { Cell: string; Macro?: string; Width?: number; Height?: number; Checked?: boolean; CurrentVal?: number; MinVal?: number; MaxVal?: number; IncChange?: number; PageChange?: number; Horizontally?: boolean; CellLink?: string; Text?: string; Paragraph?: RichTextRun[]; Type?: FormControlType; Format?: GraphicOptions; }; /** * LineOptions directly maps the format settings of the line. */ export type LineOptions = { Type?: LineType; Dash?: LineDashType; Fill?: Fill; Smooth?: boolean; Width?: number; }; /* * ChartNumFmt directly maps the number format settings of the chart. */ export type ChartNumFmt = { CustomNumFmt?: string; SourceLinked?: boolean; }; /* * ChartTitle directly maps the format settings of the chart title. */ export type ChartTitle = { Fill?: Fill; Border?: LineOptions; Paragraph?: RichTextRun[]; Font?: Font; Formula?: string; OffsetX?: number; OffsetY?: number; Width?: number; Height?: number; Overlay?: boolean; }; /** * ChartAxis directly maps the format settings of the chart axis. */ export type ChartAxis = { None?: boolean; DropLines?: boolean; HighLowLines?: boolean; MajorGridLines?: boolean; MinorGridLines?: boolean; MajorUnit?: number; TickLabelPosition?: ChartTickLabelPositionType; TickLabelSkip?: number; ReverseOrder?: boolean; Secondary?: boolean; Maximum?: number; Minimum?: number; Alignment?: Alignment; Font?: Font; LogBase?: number; NumFmt?: ChartNumFmt; Title?: ChartTitle; }; /** * ChartDimension directly maps the dimension of the chart. */ export type ChartDimension = { Width?: number; Height?: number; }; /** * ChartUpDownBar directly maps the format settings of the stock chart up bars * and down bars. */ export type ChartUpDownBar = { Fill?: Fill; Border?: LineOptions; }; /** * ChartPlotArea directly maps the format settings of the plot area. */ export type ChartPlotArea = { SecondPlotValues?: number; ShowBubbleSize?: boolean; ShowCatName?: boolean; ShowDataTable?: boolean; ShowDataTableKeys?: boolean; ShowLeaderLines?: boolean; ShowPercent?: boolean; ShowSerName?: boolean; ShowVal?: boolean; Fill?: Fill; UpBars?: ChartUpDownBar; DownBars?: ChartUpDownBar; NumFmt?: ChartNumFmt; }; /** * ChartType defines the currently supported chart types enumeration. */ export enum ChartType { Area, AreaStacked, AreaPercentStacked, Area3D, Area3DStacked, Area3DPercentStacked, Bar, BarStacked, BarPercentStacked, Bar3DClustered, Bar3DStacked, Bar3DPercentStacked, Bar3DConeClustered, Bar3DConeStacked, Bar3DConePercentStacked, Bar3DPyramidClustered, Bar3DPyramidStacked, Bar3DPyramidPercentStacked, Bar3DCylinderClustered, Bar3DCylinderStacked, Bar3DCylinderPercentStacked, Col, ColStacked, ColPercentStacked, Col3D, Col3DClustered, Col3DStacked, Col3DPercentStacked, Col3DCone, Col3DConeClustered, Col3DConeStacked, Col3DConePercentStacked, Col3DPyramid, Col3DPyramidClustered, Col3DPyramidStacked, Col3DPyramidPercentStacked, Col3DCylinder, Col3DCylinderClustered, Col3DCylinderStacked, Col3DCylinderPercentStacked, Doughnut, Line, Line3D, Pie, Pie3D, PieOfPie, BarOfPie, Radar, Scatter, Surface3D, WireframeSurface3D, Contour, WireframeContour, Bubble, Bubble3D, StockHighLowClose, StockOpenHighLowClose, } /** * ChartDataLabelPositionType is the type of chart data labels position. */ export enum ChartDataLabelPositionType { ChartDataLabelsPositionUnset, ChartDataLabelsPositionBestFit, ChartDataLabelsPositionBelow, ChartDataLabelsPositionCenter, ChartDataLabelsPositionInsideBase, ChartDataLabelsPositionInsideEnd, ChartDataLabelsPositionLeft, ChartDataLabelsPositionOutsideEnd, ChartDataLabelsPositionRight, ChartDataLabelsPositionAbove, } /** * ChartTickLabelPositionType is the type of supported chart tick label * position types. */ export enum ChartTickLabelPositionType { ChartTickLabelNextToAxis, ChartTickLabelHigh, ChartTickLabelLow, ChartTickLabelNone, } /** * Chart directly maps the format settings of the chart. */ export type Chart = { Type: ChartType; Series?: ChartSeries[]; Format?: GraphicOptions; Dimension?: ChartDimension; Legend?: ChartLegend; Title?: ChartTitle; VaryColors?: boolean; XAxis?: ChartAxis; YAxis?: ChartAxis; PlotArea?: ChartPlotArea; Fill?: Fill; Border?: LineOptions; ShowBlanksAs?: string; BubbleSize?: number; HoleSize?: number; GapWidth?: number; Overlap?: number; }; /** * ChartLegend directly maps the format settings of the chart legend. */ export type ChartLegend = { Position?: string ShowLegendKey?: boolean; Font?: Font; }; /** * ChartMarker directly maps the format settings of the chart marker. */ export type ChartMarker = { Border?: LineOptions; Fill?: Fill; Symbol?: string; Size?: number; }; /* * ChartDataLabel directly maps the format settings of the chart labels. */ export type ChartDataLabel = { Alignment?: Alignment; Font?: Font; Fill?: Fill; }; /** * ChartDataPoint directly maps the format settings of the chart data point * for doughnut, pie and 3D pie charts. */ export type ChartDataPoint = { Index: number; Fill: Fill; }; /** * ChartSeries directly maps the format settings of the chart series. */ export type ChartSeries = { Name?: string; Categories?: string; Values?: string; Sizes?: string; Fill?: Fill; Legend?: ChartLegend; Line?: LineOptions; Marker?: ChartMarker; DataLabel?: ChartDataLabel; DataLabelPosition?: ChartDataLabelPositionType; DataPoint?: ChartDataPoint[]; }; /** * HeaderFooterImagePositionType is the type of header and footer image * position. */ export enum HeaderFooterImagePositionType { HeaderFooterImagePositionLeft, HeaderFooterImagePositionCenter, HeaderFooterImagePositionRight, } /** * IgnoredErrorsType is the type of ignored errors. */ export enum IgnoredErrorsType { IgnoredErrorsEvalError, IgnoredErrorsTwoDigitTextYear, IgnoredErrorsNumberStoredAsText, IgnoredErrorsFormula, IgnoredErrorsFormulaRange, IgnoredErrorsUnlockedFormula, IgnoredErrorsEmptyCellReference, IgnoredErrorsListDataValidation, IgnoredErrorsCalculatedColumn, } /** * HeaderFooterImageOptions defines the settings for an image to be accessible * from the worksheet header and footer options. */ export type HeaderFooterImageOptions = { Position?: HeaderFooterImagePositionType; File: Uint8Array; IsFooter?: boolean; FirstPage?: boolean; Extension: string; Width?: string; Height?: string; }; /** * PivotTableOptions directly maps the format settings of the pivot table. * * PivotTableStyleName: The built-in pivot table style names * * PivotStyleLight1 - PivotStyleLight28 * PivotStyleMedium1 - PivotStyleMedium28 * PivotStyleDark1 - PivotStyleDark28 */ export type PivotTableOptions = { DataRange?: string; PivotTableRange?: string; Name?: string; Rows?: PivotTableField[]; Columns?: PivotTableField[]; Data?: PivotTableField[]; Filter?: PivotTableField[]; RowGrandTotals?: boolean; ColGrandTotals?: boolean; ShowDrill?: boolean; UseAutoFormatting?: boolean; PageOverThenDown?: boolean; MergeItem?: boolean; ClassicLayout?: boolean; CompactData ?: boolean; ShowError?: boolean; ShowRowHeaders?: boolean; ShowColHeaders?: boolean; ShowRowStripes?: boolean; ShowColStripes?: boolean; ShowLastColumn?: boolean; FieldPrintTitles?: boolean; ItemPrintTitles?: boolean; PivotTableStyleName?: string; }; /** * PivotTableShowValuesAsType defines the calculation type enumeration. */ export enum PivotTableShowValuesAsType { PivotTableShowValuesAsNoCalculation, PivotTableShowValuesAsPercentOfGrandTotal, PivotTableShowValuesAsPercentOfColumnTotal, PivotTableShowValuesAsPercentOfRowTotal, PivotTableShowValuesAsPercentOf, PivotTableShowValuesAsPercentOfParentRowTotal, PivotTableShowValuesAsPercentOfParentColumnTotal, PivotTableShowValuesAsPercentOfParentTotal, PivotTableShowValuesAsDifferenceFrom, PivotTableShowValuesAsPercentDifferenceFrom, PivotTableShowValuesAsRunningTotalIn, PivotTableShowValuesAsPercentRunningTotalIn, PivotTableShowValuesAsRankSmallestToLargest, PivotTableShowValuesAsRankLargestToSmallest, PivotTableShowValuesAsIndex, } /** * PivotTableShowValuesAs directly maps the show value as settings of the * pivot table. */ export type PivotTableShowValuesAs = { Type?: PivotTableShowValuesAsType; BaseField?: string; BaseItem?: string; }; /** * PivotTableField directly maps the field settings of the pivot table. * * Name specifies the name of the data field. Maximum 255 characters * are allowed in data field name, excess characters will be truncated. * * Subtotal specifies the aggregation function that applies to this data * field. The default value is sum. The possible values for this attribute * are: * * Average * Count * CountNums * Max * Min * Product * StdDev * StdDevp * Sum * Var * Varp * * NumFmt specifies the number format ID of the data field, this filed only * accepts built-in number format ID and does not support custom number format * expression currently. * * SelectedItems specifies the default selected items in a pivot table field. * The selected items must be values within the cell range referenced by that * field. * * ShowValuesAs specifies the calculation type for showing values in a pivot * table values fields. The possible values for the Type field of ShowValuesAs * are: * * ```typescript * PivotTableShowValuesAsNoCalculation * PivotTableShowValuesAsPercentOfGrandTotal * PivotTableShowValuesAsPercentOfColumnTotal * PivotTableShowValuesAsPercentOfRowTotal * PivotTableShowValuesAsPercentOf * PivotTableShowValuesAsPercentOfParentRowTotal * PivotTableShowValuesAsPercentOfParentColumnTotal * PivotTableShowValuesAsPercentOfParentTotal * PivotTableShowValuesAsDifferenceFrom * PivotTableShowValuesAsPercentDifferenceFrom * PivotTableShowValuesAsRunningTotalIn * PivotTableShowValuesAsPercentRunningTotalIn * PivotTableShowValuesAsRankSmallestToLargest * PivotTableShowValuesAsRankLargestToSmallest * PivotTableShowValuesAsIndex * ``` * * Note that the base field and base item settings of ShowValuesAs are only * required for some calculation types, the calculation types requires base * field settings are: * * ```typescript * PivotTableShowValuesAsPercentOf * PivotTableShowValuesAsPercentOfParentTotal * PivotTableShowValuesAsDifferenceFrom * PivotTableShowValuesAsPercentDifferenceFrom * PivotTableShowValuesAsRunningTotalIn * PivotTableShowValuesAsPercentRunningTotalIn * PivotTableShowValuesAsRankSmallestToLargest * PivotTableShowValuesAsRankLargestToSmallest * ``` * * The supported calculation types requires base item settings are: * * ```typescript * PivotTableShowValuesAsPercentOf * PivotTableShowValuesAsDifferenceFrom * PivotTableShowValuesAsPercentDifferenceFrom * ``` */ export type PivotTableField = { Compact?: boolean; Data?: string; Name?: string; Outline?: boolean; ShowAll?: boolean; InsertBlankRow?: boolean; Subtotal?: string; DefaultSubtotal?: boolean; NumFmt?: number; SelectedItems?: string[]; ShowValuesAs?: PivotTableShowValuesAs; }; /** * Comment directly maps the comment information. */ export type Comment = { Author?: string; AuthorID?: number; Cell: string; Text?: string; Width?: number; Height?: number; Paragraph?: RichTextRun[]; }; /** * PictureInsertType defines the type of the picture has been inserted into * the worksheet. */ export enum PictureInsertType { PictureInsertTypePlaceOverCells, PictureInsertTypePlaceInCell, PictureInsertTypeDISPIMG, } /** * Picture maps the format settings of the picture. */ export type Picture = { Extension: string; File: Uint8Array; Format: GraphicOptions; InsertType: PictureInsertType; }; /** * DataValidation directly maps the a single item of data validation defined * on a range of the worksheet. */ export type DataValidation = { AllowBlank?: boolean; Error?: string; ErrorStyle?: string; ErrorTitle?: string; Operator?: string Prompt?: string; PromptTitle?: string; ShowDropDown?: boolean; ShowErrorMessage?: boolean; ShowInputMessage?: boolean; Sqref?: string; Type?: string; Formula1?: string; Formula2?: string; }; /** * RichTextRun directly maps the settings of the rich text run. */ export type RichTextRun = { Font?: Font; Text?: string; }; /** * FormulaOptions can be passed to SetCellFormula to use other formula types. */ export type FormulaOptions = { Ref?: string; Type?: string; }; /** * HyperlinkOpts can be passed to SetCellHyperlink to set optional hyperlink * attributes (e.g. display value). */ export type HyperlinkOpts = { Display?: string; Tooltip?: string; }; /** * SheetProtectionOptions directly maps the settings of worksheet protection. */ export type SheetProtectionOptions = { AlgorithmName?: string; AutoFilter?: boolean; DeleteColumns?: boolean; DeleteRows?: boolean; EditObjects?: boolean; EditScenarios?: boolean; FormatCells?: boolean; FormatColumns?: boolean; FormatRows?: boolean; InsertColumns?: boolean; InsertHyperlinks?: boolean; InsertRows?: boolean; Password?: string; PivotTables?: boolean; SelectLockedCells?: boolean; SelectUnlockedCells?: boolean; Sort?: boolean; }; /** * DefinedName directly maps the name for a cell or cell range on a * worksheet. */ export type DefinedName = { Name?: string; Comment?: string; RefersTo?: string; Scope?: string; }; /** * DocProperties directly maps the document core properties. */ export type DocProperties = { Category?: string; ContentStatus?: string; Created?: string; Creator?: string; Description?: string; Identifier?: string; Keywords?: string; LastModifiedBy?: string; Modified?: string; Revision?: string; Subject?: string; Title?: string; Language?: string; Version?: string; }; /** * HeaderFooterOptions directly maps the settings of header and footer. */ export type HeaderFooterOptions = { AlignWithMargins?: boolean; DifferentFirst?: boolean; DifferentOddEven?: boolean; ScaleWithDoc?: boolean; OddHeader?: string; OddFooter?: string; EvenHeader?: string; EvenFooter?: string; FirstHeader?: string; FirstFooter?: string; }; /** * MergeCell define a merged cell data. */ export interface MergeCell { /** * GetCellValue returns merged cell value. */ GetCellValue: () => string; /** * GetStartAxis returns the top left cell reference of merged range, for * example: "C2". */ GetStartAxis: () => string; /** * GetEndAxis returns the bottom right cell reference of merged range, for * example: "D4". */ GetEndAxis: () => string; } /** * PageLayoutOptions directly maps the settings of page layout. */ export type PageLayoutOptions = { // Size defines the paper size of the worksheet. Size?: number; // Orientation defines the orientation of page layout for a worksheet. Orientation?: string; // FirstPageNumber specified the first printed page number. If no value is // specified, then 'automatic' is assumed. FirstPageNumber?: number; // AdjustTo defines the print scaling. This attribute is restricted to value // ranging from 10 (10%) to 400 (400%). This setting is overridden when // fitToWidth and/or fitToHeight are in use. AdjustTo?: number; // FitToHeight specified the number of vertical pages to fit on. FitToHeight?: number; // FitToWidth specified the number of horizontal pages to fit on. FitToWidth?: number; // BlackAndWhite specified print black and white. BlackAndWhite?: boolean; // PageOrder specifies the ordering of multiple pages. Values accepted: // overThenDown and downThenOver PageOrder?: string; }; /** * PageLayoutMarginsOptions directly maps the settings of page layout margins. */ export type PageLayoutMarginsOptions = { Bottom?: number; Footer?: number; Header?: number; Left?: number; Right?: number; Top?: number; Horizontally?: boolean; Vertically?: boolean; }; /* * SheetPropsOptions directly maps the settings of sheet view. */ export type SheetPropsOptions = { // Specifies a stable name of the sheet, which should not change over time, // and does not change from user input. This name should be used by code // to reference a particular sheet. CodeName?: string; // EnableFormatConditionsCalculation indicating whether the conditional // formatting calculations shall be evaluated. If set to false, then the // min/max values of color scales or data bars or threshold values in Top N // rules shall not be updated. Essentially the conditional // formatting "calc" is off. EnableFormatConditionsCalculation?: boolean; // Published indicating whether the worksheet is published. Published?: boolean; // AutoPageBreaks indicating whether the sheet displays Automatic Page // Breaks. AutoPageBreaks?: boolean; // FitToPage indicating whether the Fit to Page print option is enabled. FitToPage?: boolean; // TabColorIndexed represents the indexed color value. TabColorIndexed?: number; // TabColorRGB represents the standard Alpha Red Green Blue color value. TabColorRGB?: string; // TabColorTheme represents the zero-based index into the collection, // referencing a particular value expressed in the Theme part. TabColorTheme?: number; // TabColorTint specifies the tint value applied to the color. TabColorTint?: number; // OutlineSummaryBelow indicating whether summary rows appear below detail // in an outline, when applying an outline. OutlineSummaryBelow?: boolean; // OutlineSummaryRight indicating whether summary columns appear to the // right of detail in an outline, when applying an outline. OutlineSummaryRight?: boolean; // BaseColWidth specifies the number of characters of the maximum digit // width of the normal style's font. This value does not include margin // padding or extra padding for grid lines. It is only the number of // characters. BaseColWidth?: number; // DefaultColWidth specifies the default column width measured as the // number of characters of the maximum digit width of the normal style's // font. DefaultColWidth?: number; // DefaultRowHeight specifies the default row height measured in point // size. Optimization so we don't have to write the height on all rows. // This can be written out if most rows have custom height, to achieve the // optimization. DefaultRowHeight?: number; // CustomHeight specifies the custom height. CustomHeight?: boolean; // ZeroHeight specifies if rows are hidden. ZeroHeight?: boolean; // ThickTop specifies if rows have a thick top border by default. ThickTop?: boolean; // ThickBottom specifies if rows have a thick bottom border by default. ThickBottom?: boolean; }; export type ViewOptions = { // DefaultGridColor indicating that the consuming application should use // the default grid lines color(system dependent). Overrides any color // specified in colorId. DefaultGridColor?: boolean; // RightToLeft indicating whether the sheet is in 'right to left' display // mode. When in this mode, Column A is on the far right, Column B; is one // column left of Column A, and so on. Also, information in cells is // displayed in the Right to Left format. RightToLeft?: boolean; // ShowFormulas indicating whether this sheet should display formulas. ShowFormulas?: boolean; // ShowGridLines indicating whether this sheet should display grid lines. ShowGridLines?: boolean; // ShowRowColHeaders indicating whether the sheet should display row and // column headings. ShowRowColHeaders?: boolean; // ShowRuler indicating this sheet should display ruler. ShowRuler?: boolean; // ShowZeros indicating whether to "show a zero in cells that have zero // value". When using a formula to reference another cell which is empty, // the referenced value becomes 0 when the flag is true. (Default setting // is true.) ShowZeros?: boolean; // TopLeftCell specifies a location of the top left visible cell Location // of the top left visible cell in the bottom right pane (when in // Left-to-Right mode). TopLeftCell: string; // View indicating how sheet is displayed, by default it uses empty string // available options: normal, pageLayout, pageBreakPreview View: string; // ZoomScale specifies a window zoom magnification for current view // representing percent values. This attribute is restricted to values // ranging from 10 to 400. Horizontal & Vertical scale together. ZoomScale?: number; }; /** * CalcPropsOptions defines the collection of properties the application uses * to record calculation status and details. */ export type CalcPropsOptions = { CalcID?: number; CalcMode?: string; FullCalcOnLoad?: boolean; RefMode?: string; Iterate?: boolean; IterateCount?: number; IterateDelta?: number; FullPrecision?: boolean; CalcCompleted?: boolean; CalcOnSave?: boolean; ConcurrentCalc?: boolean; ConcurrentManualCount?: number; ForceFullCalc?: boolean; }; /** * WorkbookPropsOptions directly maps the settings of workbook proprieties. */ export type WorkbookPropsOptions = { Date1904?: boolean; FilterPrivacy?: boolean; CodeName?: string; }; /** * WorkbookProtectionOptions directly maps the settings of workbook * protection. */ export type WorkbookProtectionOptions = { AlgorithmName?: string; Password?: string; LockStructure?: boolean; LockWindows?: boolean; }; /** * CellNameToCoordinates converts alphanumeric cell name to [X, Y] * coordinates or returns an error. * @param cell The cell reference */ export function CellNameToCoordinates(cell: string): { col: number, row: number, error: string | null } /** * ColumnNameToNumber provides a function to convert Excel sheet column name * (case-insensitive) to int. The function returns an error if column name * incorrect. * @param name The column name */ export function ColumnNameToNumber(name: string): { col: number, error: string | null } /** * ColumnNumberToName provides a function to convert the integer to Excel * sheet column title. * @param num The column name */ export function ColumnNumberToName(num: number): { col: string, error: string | null } /** * CoordinatesToCellName converts [X, Y] coordinates to alpha-numeric cell * name or returns an error. * @param col The column number * @param row The row number * @param abs Specifies the absolute cell references */ export function CoordinatesToCellName(col: number, row: number, abs?: boolean): { cell: string, error: string | null } /** * HSLToRGB converts an HSL triple to a RGB triple. * @param h Hue * @param s Saturation * @param l Lightness */ export function HSLToRGB(h: number, s: number, l: number): { r: number, g: number, b: number, error: string | null } /** * JoinCellName joins cell name from column name and row number. * @param col The column name * @param row The row number */ export function JoinCellName(col: string, row: number): { cell: string, error: string | null } /** * RGBToHSL converts an RGB triple to a HSL triple. * @param r Red * @param g Green * @param b Blue */ export function RGBToHSL(r: number, g: number, b: number): { h: number, s: number, l: number, error: string | null } /** * SplitCellName splits cell name to column name and row number. * @param cell The cell reference */ export function SplitCellName(cell: string): { col: string, row: number, error: string | null } /** * ThemeColor applied the color with tint value. * @param baseColor Base color in hex format * @param tint A mixture of a color with white */ export function ThemeColor(baseColor: string, tint: number): { color: string, error: string | null } /** * NewFile provides a function to create new file by default template. * @param opts The options for open and reading spreadsheet */ export function NewFile(opts?: Options): NewFile; /** * OpenReader read data stream from buffer and return a populated spreadsheet * file. * @param r The contents buffer of the file * @param opts The options for open and reading spreadsheet */ export function OpenReader(r: Uint8Array, opts?: Options): NewFile; /** * @constructor */ export class NewFile { /** * AddChart provides the method to add chart in a sheet by given chart * format set (such as offset, scale, aspect ratio setting and print * settings) and properties set. For example, create 3D clustered column * chart with data Sheet1!$E$1:$L$15: * * ```typescript * const { init } = require('excelize-wasm'); * const fs = require('fs'); * * init('./node_modules/excelize-wasm/excelize.wasm.gz').then((excelize) => { * const f = excelize.NewFile(); * if (f.error) { * console.log(f.error); * return; * } * [ * [null, 'Apple', 'Orange', 'Pear'], * ['Small', 2, 3, 3], * ['Normal', 5, 2, 4], * ['Large', 6, 7, 8], * ].forEach((row, idx) => { * const ret1 = excelize.CoordinatesToCellName(1, idx + 1); * if (ret1.error) { * console.log(ret1.error); * return; * } * const res2 = f.SetSheetRow('Sheet1', ret1.cell, row); * if (res2.error) { * console.log(res2.error); * return; * } * }); * const ret3 = f.AddChart('Sheet1', 'E1', { * Type: excelize.Col3DClustered, * Series: [ * { * Name: 'Sheet1!$A$2', * Categories: 'Sheet1!$B$1:$D$1', * Values: 'Sheet1!$B$2:$D$2', * }, * { * Name: 'Sheet1!$A$3', * Categories: 'Sheet1!$B$1:$D$1', * Values: 'Sheet1!$B$3:$D$3', * }, * { * Name: 'Sheet1!$A$4', * Categories: 'Sheet1!$B$1:$D$1', * Values: 'Sheet1!$B$4:$D$4', * }, * ], * Title: { Paragraph: [{ Text: 'Fruit 3D Clustered Column Chart' }] }, * }); * if (ret3.error) { * console.log(ret3.error); * return; * } * // Save spreadsheet by the given path. * const { buffer, error } = f.WriteToBuffer(); * if (error) { * console.log(error); * return; * } * fs.writeFile('Book1.xlsx', buffer, 'binary', (error) => { * if (error) { * console.log(error); * } * }); * }); * ``` * * The following shows the type of chart supported by excelize: * * ID | Enumeration | Chart * ----+-----------------------------+------------------------------ * 0 | Area | 2D area chart * 1 | AreaStacked | 2D stacked area chart * 2 | AreaPercentStacked | 2D 100% stacked area chart * 3 | Area3D | 3D area chart * 4 | Area3DStacked | 3D stacked area chart * 5 | Area3DPercentStacked | 3D 100% stacked area chart * 6 | Bar | 2D clustered bar chart * 7 | BarStacked | 2D stacked bar chart * 8 | BarPercentStacked | 2D 100% stacked bar chart * 9 | Bar3DClustered | 3D clustered bar chart * 10 | Bar3DStacked | 3D stacked bar chart * 11 | Bar3DPercentStacked | 3D 100% stacked bar chart * 12 | Bar3DConeClustered | 3D cone clustered bar chart * 13 | Bar3DConeStacked | 3D cone stacked bar chart * 14 | Bar3DConePercentStacked | 3D cone percent bar chart * 15 | Bar3DPyramidClustered | 3D pyramid clustered bar chart * 16 | Bar3DPyramidStacked | 3D pyramid stacked bar chart * 17 | Bar3DPyramidPercentStacked | 3D pyramid percent stacked bar chart * 18 | Bar3DCylinderClustered | 3D cylinder clustered bar chart * 19 | Bar3DCylinderStacked | 3D cylinder stacked bar chart * 20 | Bar3DCylinderPercentStacked | 3D cylinder percent stacked bar chart * 21 | Col | 2D clustered column chart * 22 | ColStacked | 2D stacked column chart * 23 | ColPercentStacked | 2D 100% stacked column chart * 24 | Col3DClustered | 3D clustered column chart * 25 | Col3D | 3D column chart * 26 | Col3DStacked | 3D stacked column chart * 27 | Col3DPercentStacked | 3D 100% stacked column chart * 28 | Col3DCone | 3D cone column chart * 29 | Col3DConeClustered | 3D cone clustered column chart * 30 | Col3DConeStacked | 3D cone stacked column chart * 31 | Col3DConePercentStacked | 3D cone percent stacked column chart * 32 | Col3DPyramid | 3D pyramid column chart * 33 | Col3DPyramidClustered | 3D pyramid clustered column chart * 34 | Col3DPyramidStacked | 3D pyramid stacked column chart * 35 | Col3DPyramidPercentStacked | 3D pyramid percent stacked column chart * 36 | Col3DCylinder | 3D cylinder column chart * 37 | Col3DCylinderClustered | 3D cylinder clustered column chart * 38 | Col3DCylinderStacked | 3D cylinder stacked column chart * 39 | Col3DCylinderPercentStacked | 3D cylinder percent stacked column chart * 40 | Doughnut | doughnut chart * 41 | Line | line chart * 42 | Line3D | 3D line chart * 43 | Pie | pie chart * 44 | Pie3D | 3D pie chart * 45 | PieOfPie | pie of pie chart * 46 | BarOfPie | bar of pie chart * 47 | Radar | radar chart * 48 | Scatter | scatter chart * 49 | Surface3D | 3D surface chart * 50 | WireframeSurface3D | 3D wireframe surface chart * 51 | Contour | contour chart * 52 | WireframeContour | wireframe contour chart * 53 | Bubble | bubble chart * 54 | Bubble3D | 3D bubble chart * 55 | StockHighLowClose | High-Low-Close stock chart * 56 | StockOpenHighLowClose | Open-High-Low-Close stock chart * * In Excel a chart series is a collection of information that defines which * data is plotted such as values, axis labels and formatting. * * The series options that can be set are: * * Name * Categories * Values * Fill * Legend * Line * Marker * DataLabel * DataLabelPosition * DataPoint * * Name: Set the name for the series. The name is displayed in the chart * legend and in the formula bar. The 'Name' property is optional and if it * isn't supplied it will default to Series 1..n. The name can also be a * formula such as Sheet1!$A$1 * * Categories: This sets the chart category labels. The category is more or * less the same as the X axis. In most chart types the 'Categories' * property is optional and the chart will just assume a sequential series * from 1..n. * * Values: This is the most important property of a series and is the only * mandatory option for every chart object. This option links the chart with * the worksheet data that it displays. * * Sizes: This sets the bubble size in a data series. The 'Sizes' property * is optional and the default value was same with 'Values'. * * Fill: This set the format for the data series fill. The 'Fill' property * is optional. * * Legend: This set the font of legend text for a data series. The 'Legend' * property is optional. * * Line: This sets the line format of the line chart. The 'Line' property is * optional and if it isn't supplied it will default style. The options that * can be set are width and color. The range of width is 0.25pt - 999pt. If * the value of width is outside the range, the default width of the line is * 2pt. * * Marker: This sets the marker of the line chart and scatter chart. The * range of optional field 'Size' is 2-72 (default value is 5). The * enumeration value of optional field 'Symbol' are (default value is * 'auto'): * * circle * dash * diamond * dot * none * picture * plus * square * star * triangle * x * auto * * DataLabel: This sets the format of the chart series data label. * * DataLabelPosition: This sets the position of the chart series data label. * * DataPoint: This sets the format for individual data points in a doughnut, * pie or 3D pie chart series. The 'DataPoint' property is optional. * * Set properties of the chart legend by 'Legend' field with 'ChartLegend' * data type. The options that can be set are: * * Position * ShowLegendKey * Font * * Position: Set the position of the chart legend. The default legend * position is bottom. The available positions are: * * none * top * bottom * left * right * top_right * * ShowLegendKey: Set the legend keys shall be shown in data labels. The * default value is false. * * Font: Set the font properties of the chart legend text. The properties * that can be set are the