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,546 lines (1,478 loc) 145 kB
// Copyright 2022 - 2024 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, } /** * 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. * * 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; 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; }; /** * 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; }; /** * 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?: ShapeLine; 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. */ 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; }; /** * ShapeLine directly maps the line settings of the shape. */ export type ShapeLine = { Color?: string; Width?: number; }; /** * 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; 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; }; /* * ChartNumFmt directly maps the number format settings of the chart. */ export type ChartNumFmt = { CustomNumFmt?: string; SourceLinked?: boolean; }; /** * ChartAxis directly maps the format settings of the chart axis. */ export type ChartAxis = { None?: boolean; MajorGridLines?: boolean; MinorGridLines?: boolean; MajorUnit?: number; TickLabelPosition?: ChartTickLabelPositionType; TickLabelSkip?: number; ReverseOrder?: boolean; Secondary?: boolean; Maximum?: number; Minimum?: number; Font?: Font; LogBase?: number; NumFmt?: ChartNumFmt; Title?: RichTextRun[]; }; /** * ChartDimension directly maps the dimension of the chart. */ export type ChartDimension = { Width?: number; Height?: number; }; /** * ChartPlotArea directly maps the format settings of the plot area. */ export type ChartPlotArea = { SecondPlotValues?: number; ShowBubbleSize?: boolean; ShowCatName?: boolean; ShowLeaderLines?: boolean; ShowPercent?: boolean; ShowSerName?: boolean; ShowVal?: boolean; Fill?: Fill; NumFmt?: ChartNumFmt; }; /** * ChartLineType defines the currently supported chart line types enumeration. */ export enum ChartLineType { ChartLineUnset, ChartLineSolid, ChartLineNone, ChartLineAutomatic, } /** * 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, } /** * 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?: RichTextRun[]; VaryColors?: boolean; XAxis?: ChartAxis; YAxis?: ChartAxis; PlotArea?: ChartPlotArea; Fill?: Fill; Border?: ChartLine; ShowBlanksAs?: string; BubbleSize?: number; HoleSize?: number; }; /** * ChartLegend directly maps the format settings of the chart legend. */ export type ChartLegend = { Position?: string ShowLegendKey?: boolean; }; /** * ChartMarker directly maps the format settings of the chart marker. */ export type ChartMarker = { Fill?: Fill; Symbol?: string; Size?: number; }; /** * ChartLine directly maps the format settings of the chart line. */ export type ChartLine = { Type?: ChartLineType; Smooth?: boolean; Width?: number; }; /** * ChartSeries directly maps the format settings of the chart series. */ export type ChartSeries = { Name?: string; Categories?: string; Values?: string; Sizes?: string; Fill?: Fill; Line?: ChartLine; Marker?: ChartMarker; DataLabelPosition?: ChartDataLabelPositionType; }; /** * 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; }; /** * 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. */ export type PivotTableField = { Compact?: boolean; Data?: string; Name?: string; Outline?: boolean; ShowAll?: boolean; InsertBlankRow?: boolean; Subtotal?: string; DefaultSubtotal?: boolean; NumFmt?: number; }; /** * 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; }; /** * 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; }; /** * 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: [{ * 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 * * 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 * Line * Marker * DataLabelPosition * * 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. * * 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 * * DataLabelPosition: This sets the position of the chart series data label. * * Set properties of the chart legend. The options that can be set are: * * Position * ShowLegendKey * * 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. * * Set properties of the chart title. The properties that can be set are: * * Title * * Title: Set the name (title) for the chart. The name is displayed above * the chart. The name can also be a formula such as Sheet1!$A$1 or a list * with a sheet name. The name property is optional. The default is to have * no chart title. * * Specifies how blank cells are plotted on the chart by 'ShowBlanksAs'. The * default value is gap. The options that can be set are: * * gap * span * zero * * gap: Specifies that blank values shall be left as a gap. * * span: Specifies that blank values shall be spanned with a line. * * zero: Specifies that blank values shall be treated as zero. * * Specifies that each data marker in the series has a different color by * 'VaryColors'. The default value is true. * * Set chart offset, scale, aspect ratio setting and print settings by * 'Format', same as function 'AddPicture'. * * Set the position of the chart plot area by 'PlotArea'. The properties * that can be set are: * * SecondPlotValues * ShowBubbleSize * ShowCatName * ShowLeaderLines * ShowPercent * ShowSerName * ShowVal * NumFmt * * SecondPlotValues: Specifies the values in second plot for the 'pieOfPie' * and 'barOfPie' chart. * * ShowBubbleSize: Specifies the bubble size shall be shown in a data label. * The 'ShowBubbleSize' property is optional. The default value is false. * * ShowCatName: Specifies that the category name shall be shown in the data * label. The 'ShowCatName' property is optional. The default value is true. * * ShowLeaderLines: Specifies leader lines shall be shown for data labels. * The 'ShowLeaderLines' property is optional. The default value is false. * * ShowPercent: Specifies that the percentage shall be shown in a data * label. The 'ShowPercent' property is optional. The default value is * false. * * ShowSerName: Specifies that the series name shall be shown in a data * label. The 'ShowSerName' property is optional. The default value is * false. * * ShowVal: Specifies that the value shall be shown in a data label. * The 'ShowVal' property is optional. The default value is false. * * NumFmt: Specifies that if linked to source and set custom number format * code for data labels. The 'NumFmt' property is optional. The default * format code is 'General'. * * Set the primary horizontal and vertical axis options by 'XAxis' and * 'YAxis'. The properties of 'XAxis' that can be set are: * * None * MajorGridLines * MinorGridLines * TickLabelSkip * ReverseOrder * Maximum * Minimum * Font * NumFmt * Title * * The properties of 'YAxis' that can be set are: * * None * MajorGridLines * MinorGridLines * MajorUnit * Secondary * ReverseOrder * Maximum * Minimum * Font * LogBase * NumFmt * Title * * None: Disable axes. * * MajorGridLines: Specifies major grid lines. * * MinorGridLines: Specifies minor grid lines. * * MajorUnit: Specifies the distance between major ticks. Shall contain a * positive floating-point number. The 'MajorUnit' property is optional. The * default value is auto. * * Secondary: Specifies the current series vertical axis as the secondary * axis, this only works for the second and later chart in the combo chart. * The default value is false. * * TickLabelSkip: Specifies how many tick labels to skip between label that * is drawn. The 'TickLabelSkip' property is optional. The default value is * auto. * * ReverseOrder: Specifies that the categories or values on reverse order * (orientation of the chart). The 'ReverseOrder' property is optional. The * default value is false. * * Maximum: Specifies that the fixed maximum, 0 is auto. The 'Maximum' * property is optional. The default value is auto. * * Minimum: Specifies that the fixed minimum, 0 is auto. The 'Minimum' * property is optional. The default value is auto. * * Font: Specifies that the font of the horizontal and vertical axis. The * properties of font that can be set are: * * Bold * Italic * Underline * Family * Size * Strike * Color * VertAlign * * LogBase: Specifies logarithmic scale base number of the vertical axis. * * NumFmt: Specifies that if linked to source and set custom number format * code for axis. The 'NumFmt' property is optional. The default format code * is 'General'. * * Title: Specifies that the primary horizontal or vertical axis title and * resize chart. The 'Title' property is optional. * * Set chart size by 'Dimension' property. The 'Dimension' property is * optional. The default width is 480, and height is 260. * * Set the bubble size in all data series for the bubble chart or 3D bubble * chart by 'BubbleSizes' property. The 'BubbleSizes' property is optional. * The default width is 100, and the value should be great than 0 and less * or equal than 300. * * Set the doughnut hole size in all data series for the doughnut chart by * 'HoleSize' property. The 'HoleSize' property is optional. The default * width is 75, and the value should be great than 0 and less or equal than * 90. * * combo: Specifies the create a chart that combines two or more chart types * in a single chart. For example, create a clustered column - line 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.Col, * Series: [ * { * Name: 'Sheet1!$A$2', * Categories: 'Sheet1!$B$1:$D$1', * Values: 'Sheet1!$B$2:$D$2', * }, * ], * Format: { * ScaleX: 1, * ScaleY: 1, * OffsetX: 15, * OffsetY: 10, * PrintObject: true, * LockAspectRatio: false, * Locked: false, * }, * Title: [{ * Text: 'Clustered Column - Line Chart', * }], * Legend: { * Position: 'left', * ShowLegendKey: false, * }, * PlotArea: { * ShowCatName: false, * ShowLeaderLines: false, * ShowPercent: true, * ShowSerName: true, * ShowVal: true, * }, * }, { * Type: excelize.Line, * Series: [ * { * Name: 'Sheet1!$A$4', * Categories: 'Sheet1!$B$1:$D$1', * Values: 'Sheet1!$B$4:$D$4', * Marker: { * Symbol: 'none', * Size: 10, * }, * }, * ], * Format: { * ScaleX: 1, * ScaleY: