From 2b6a2e54b7511554bc72e7de2f3ba1e509f6d7ba Mon Sep 17 00:00:00 2001 From: taoqf Date: Sat, 3 Feb 2018 17:14:05 +0800 Subject: [PATCH] add type definition --- index.d.ts | 1332 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 2 files changed, 1334 insertions(+), 1 deletion(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 000000000..86927a4e3 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,1332 @@ +/// + +import { Writable, Stream } from 'stream'; + +export const enum RelationshipType { + None = 0, + OfficeDocument = 1, + Worksheet = 2, + CalcChain = 3, + SharedStrings = 4, + Styles = 5, + Theme = 6, + Hyperlink = 7 +} + +export const enum DocumentType { + Xlsx = 1 +} + +export const enum PaperSize { + Legal = 5, + Executive = 7, + A4 = 9, + A5 = 11, + B5 = 13, + Envelope_10 = 20, + Envelope_DL = 27, + Envelope_C5 = 28, + Envelope_B5 = 34, + Envelope_Monarch = 37, + Double_Japan_Postcard_Rotated = 82, + K16_197x273_mm = 119, +} + +export interface WorksheetViewCommon { + /** + * Sets the worksheet view's orientation to right-to-left, `false` by default + */ + rightToLeft: boolean; + + /** + * The currently selected cell + */ + activeCell: string; + + /** + * Shows or hides the ruler in Page Layout, `true` by default + */ + showRuler: boolean; + + /** + * Shows or hides the row and column headers (e.g. A1, B1 at the top and 1,2,3 on the left, + * `true` by default + */ + showRowColHeaders: boolean; + + /** + * Shows or hides the gridlines (shown for cells where borders have not been defined), + * `true` by default + */ + showGridLines: boolean; + + /** + * Percentage zoom to use for the view, `100` by default + */ + zoomScale: number; + + /** + * Normal zoom for the view, `100` by default + */ + zoomScaleNormal: number; +} + +export interface WorksheetViewNormal { + /** + * Controls the view state + */ + state: 'normal'; + + /** + * Presentation style + */ + style: 'pageBreakPreview' | 'pageLayout'; +} + +export interface WorksheetViewFrozen { + /** + * Where a number of rows and columns to the top and left are frozen in place. + * Only the bottom left section will scroll + */ + state: 'frozen'; + + /** + * Presentation style + */ + style?: 'pageBreakPreview'; + + /** + * How many columns to freeze. To freeze rows only, set this to 0 or undefined + */ + xSplit?: number; + + /** + * How many rows to freeze. To freeze columns only, set this to 0 or undefined + */ + ySplit?: number; + + /** + * Which cell will be top-left in the bottom-right pane. Note: cannot be a frozen cell. + * Defaults to first unfrozen cell + */ + topLeftCell?: string; +} + +export interface WorksheetViewSplit { + /** + * Where the view is split into 4 sections, each semi-independently scrollable. + */ + state: 'split'; + + /** + * Presentation style + */ + style?: 'pageBreakPreview' | 'pageLayout'; + + /** + * How many points from the left to place the splitter. + * To split vertically, set this to 0 or undefined + */ + xSplit?: number; + + /** + * How many points from the top to place the splitter. + * To split horizontally, set this to 0 or undefined + */ + ySplit?: number; + + /** + * Which cell will be top-left in the bottom-right pane + */ + topLeftCell?: string; + + /** + * Which pane will be active + */ + activePane?: 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight'; +} + +export type WorksheetView = + & WorksheetViewCommon + & (WorksheetViewNormal | WorksheetViewFrozen | WorksheetViewSplit); + +export interface WorkbookView { + x: number; + y: number; + width: number; + height: number; + firstSheet: number; + activeTab: number; + visibility: string; +} + +export type FillPatterns = + | 'none' | 'solid' + | 'darkVertical' | 'darkHorizontal' | 'darkGrid' | 'darkTrellis' | 'darkDown' | 'darkUp' + | 'lightVertical' | 'lightHorizontal' | 'lightGrid' | 'lightTrellis' | 'lightDown' | 'lightUp' + | 'darkGray' | 'mediumGray' | 'lightGray' | 'gray125' | 'gray0625'; + +export interface FillPattern { + type: 'pattern'; + pattern: FillPatterns; + fgColor: Partial; + bgColor?: Partial; +} + +export interface GradientStop { + position: number; + color: Partial; +} + +export interface FillGradientAngle { + type: 'gradient'; + gradient: 'angle'; + + /** + * For 'angle' gradient, specifies the direction of the gradient. 0 is from the left to the right. + * Values from 1 - 359 rotates the direction clockwise + */ + degree: number; + + /** + * Specifies the gradient colour sequence. Is an array of objects containing position and + * color starting with position 0 and ending with position 1. + * Intermediary positions may be used to specify other colours on the path. + */ + stops: GradientStop[]; +} + +export interface FillGradientPath { + type: 'gradient'; + gradient: 'path'; + + /** + * For 'path' gradient. Specifies the relative coordinates for the start of the path. + * 'left' and 'top' values range from 0 to 1 + */ + center: { left: number; top: number }; + + /** + * Specifies the gradient colour sequence. Is an array of objects containing position and + * color starting with position 0 and ending with position 1. + * Intermediary positions may be used to specify other colours on the path. + */ + stops: GradientStop[]; +} + +export type Fill = FillPattern | FillGradientAngle | FillGradientPath; + +export interface Font { + name: string; + size: number; + family: number; + scheme: 'minor' | 'major' | 'none'; + charset: number; + color: Partial; + bold: boolean; + italic: boolean; + underline: boolean | 'none' | 'single' | 'double' | 'singleAccounting' | 'doubleAccounting'; + strike: boolean; + outline: boolean; +} + +export type BorderStyle = + | 'thin' | 'dotted' | 'hair' | 'medium' | 'double' | 'thick' | 'dashDot' + | 'dashDotDot' | 'slantDashDot' | 'mediumDashed' | 'mediumDashDotDot' | 'mediumDashDot'; + +export interface Color { + /** + * Hex string for alpha-red-green-blue e.g. FF00FF00 + */ + argb: string; + + /** + * Choose a theme by index + */ + theme: number; +} + +export interface Border { + style: BorderStyle; + color: Partial; +} + +export interface BorderDiagonal extends Border { + up: boolean; + down: boolean; +} + +export interface Borders { + top: Partial; + left: Partial; + bottom: Partial; + right: Partial; + diagonal: Partial; +} + +export interface Margins { + top: number; + left: number; + bottom: number; + right: number; + header: number; + footer: number; +} + +export const enum ReadingOrder { + LeftToRight = 1, + RightToLeft = 2, +} + +export interface Alignment { + horizontal: 'left' | 'center' | 'right' | 'fill' | 'justify' | 'centerContinuous' | 'distributed'; + vertical: 'top' | 'middle' | 'bottom' | 'distributed' | 'justify'; + wrapText: boolean; + indent: number; + readingOrder: 'rtl' | 'ltr'; + textRotation: number | 'vertical'; +} + +export interface Style { + numFmt: string; + font: Partial; + alignment: Partial; + border: Partial; + fill: Fill; +} + +export type DataValidationOperator = + | 'between' | 'notBetween' | 'equal' | 'notEqual' | 'greaterThan' | 'lessThan' + | 'greaterThanOrEqual' | 'lessThanOrEqual'; + +export interface DataValidation { + type: 'list' | 'whole' | 'decimal' | 'date' | 'textLength' | 'custom'; + formulae: any[]; + allowBlank?: boolean; + operator?: DataValidationOperator; + error?: string; + errorTitle?: string; + errorStyle?: string; + prompt?: string; + promptTitle?: string; + showErrorMessage?: boolean; + showInputMessage?: boolean; +} + +export interface CellErrorValue { + error: '#N/A' | '#REF!' | '#NAME?' | '#DIV/0!' | '#NULL!' | '#VALUE!' | '#NUM!'; +} + +export interface RichText { + text: string; + font?: Partial; +} + +export interface CellRichTextValue { + richText: RichText[]; +} + +export interface CellHyperlinkValue { + text: string; + hyperlink: string; +} + +export interface CellFormulaValue { + formula: string; + result: number | string | Date; +} + +export interface CellSharedFormulaValue { + sharedFormula: string; + readonly formula?: string; + result: number | string | Date; +} + +export const enum ValueType { + Null = 0, + Merge = 1, + Number = 2, + String = 3, + Date = 4, + Hyperlink = 5, + Formula = 6, + SharedString = 7, + RichText = 8, + Boolean = 9, + Error = 10 +} + +export const enum FormulaType { + None = 0, + Master = 1, + Shared = 2 +} + +export type CellValue = + | null | number | string | boolean | Date + | CellErrorValue + | CellRichTextValue | CellHyperlinkValue + | CellFormulaValue | CellSharedFormulaValue; + +export interface CellModel { + address: Address; + style: Style; + type: ValueType; + text?: string; + hyperlink?: string; + value?: CellValue; + master: Cell; + formula?: string; + sharedFormula?: string; + result?: string | number | any; +} + +export interface Cell extends Style, Address { + readonly worksheet: Worksheet; + readonly workbook: Workbook; + + readonly effectiveType: ValueType; + readonly isMerged: boolean; + readonly master: Cell; + readonly isHyperlink: boolean; + readonly hyperlink: string; // todo + readonly text: string; + readonly fullAddress: { + sheetName: string; + address: Address; + row: Row; + col: Column; + }; + model: CellModel; + /** + * Assign (or get) a name for a cell (will overwrite any other names that cell had) + */ + name: string; + + /** + * Assign (or get) an array of names for a cell (cells can have more than one name) + */ + names: string[]; + + /** + * Cells can define what values are valid or not and provide + * prompting to the user to help guide them. + */ + dataValidation: DataValidation; + + /** + * Value of the cell + */ + value: CellValue; + + /** + * convenience getter to access the formula + */ + readonly formula: string; + + /** + * convenience getter to access the formula result + */ + readonly result: number | string | Date; + + /** + * The type of the cell's value + */ + readonly type: ValueType; + + /** + * The type of the cell's formula + */ + readonly formulaType: FormulaType; + + /** + * The styles of the cell + */ + style: Partial