index.d.ts 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035
  1. declare interface Buffer extends ArrayBuffer { }
  2. export declare enum RelationshipType {
  3. None = 0,
  4. OfficeDocument = 1,
  5. Worksheet = 2,
  6. CalcChain = 3,
  7. SharedStrings = 4,
  8. Styles = 5,
  9. Theme = 6,
  10. Hyperlink = 7
  11. }
  12. export declare enum DocumentType {
  13. Xlsx = 1
  14. }
  15. export const enum PaperSize {
  16. Legal = 5,
  17. Executive = 7,
  18. A4 = 9,
  19. A5 = 11,
  20. B5 = 13,
  21. Envelope_10 = 20,
  22. Envelope_DL = 27,
  23. Envelope_C5 = 28,
  24. Envelope_B5 = 34,
  25. Envelope_Monarch = 37,
  26. Double_Japan_Postcard_Rotated = 82,
  27. K16_197x273_mm = 119,
  28. }
  29. export interface WorksheetViewCommon {
  30. /**
  31. * Sets the worksheet view's orientation to right-to-left, `false` by default
  32. */
  33. rightToLeft: boolean;
  34. /**
  35. * The currently selected cell
  36. */
  37. activeCell: string;
  38. /**
  39. * Shows or hides the ruler in Page Layout, `true` by default
  40. */
  41. showRuler: boolean;
  42. /**
  43. * Shows or hides the row and column headers (e.g. A1, B1 at the top and 1,2,3 on the left,
  44. * `true` by default
  45. */
  46. showRowColHeaders: boolean;
  47. /**
  48. * Shows or hides the gridlines (shown for cells where borders have not been defined),
  49. * `true` by default
  50. */
  51. showGridLines: boolean;
  52. /**
  53. * Percentage zoom to use for the view, `100` by default
  54. */
  55. zoomScale: number;
  56. /**
  57. * Normal zoom for the view, `100` by default
  58. */
  59. zoomScaleNormal: number;
  60. }
  61. export interface WorksheetViewNormal {
  62. /**
  63. * Controls the view state
  64. */
  65. state: 'normal';
  66. /**
  67. * Presentation style
  68. */
  69. style: 'pageBreakPreview' | 'pageLayout';
  70. }
  71. export interface WorksheetViewFrozen {
  72. /**
  73. * Where a number of rows and columns to the top and left are frozen in place.
  74. * Only the bottom left section will scroll
  75. */
  76. state: 'frozen';
  77. /**
  78. * Presentation style
  79. */
  80. style?: 'pageBreakPreview';
  81. /**
  82. * How many columns to freeze. To freeze rows only, set this to 0 or undefined
  83. */
  84. xSplit?: number;
  85. /**
  86. * How many rows to freeze. To freeze columns only, set this to 0 or undefined
  87. */
  88. ySplit?: number;
  89. /**
  90. * Which cell will be top-left in the bottom-right pane. Note: cannot be a frozen cell.
  91. * Defaults to first unfrozen cell
  92. */
  93. topLeftCell?: string;
  94. }
  95. export interface WorksheetViewSplit {
  96. /**
  97. * Where the view is split into 4 sections, each semi-independently scrollable.
  98. */
  99. state: 'split';
  100. /**
  101. * Presentation style
  102. */
  103. style?: 'pageBreakPreview' | 'pageLayout';
  104. /**
  105. * How many points from the left to place the splitter.
  106. * To split vertically, set this to 0 or undefined
  107. */
  108. xSplit?: number;
  109. /**
  110. * How many points from the top to place the splitter.
  111. * To split horizontally, set this to 0 or undefined
  112. */
  113. ySplit?: number;
  114. /**
  115. * Which cell will be top-left in the bottom-right pane
  116. */
  117. topLeftCell?: string;
  118. /**
  119. * Which pane will be active
  120. */
  121. activePane?: 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
  122. }
  123. export type WorksheetView =
  124. & WorksheetViewCommon
  125. & (WorksheetViewNormal | WorksheetViewFrozen | WorksheetViewSplit);
  126. export interface WorkbookView {
  127. x: number;
  128. y: number;
  129. width: number;
  130. height: number;
  131. firstSheet: number;
  132. activeTab: number;
  133. visibility: string;
  134. }
  135. export type FillPatterns =
  136. | 'none' | 'solid'
  137. | 'darkVertical' | 'darkHorizontal' | 'darkGrid' | 'darkTrellis' | 'darkDown' | 'darkUp'
  138. | 'lightVertical' | 'lightHorizontal' | 'lightGrid' | 'lightTrellis' | 'lightDown' | 'lightUp'
  139. | 'darkGray' | 'mediumGray' | 'lightGray' | 'gray125' | 'gray0625';
  140. export interface FillPattern {
  141. type: 'pattern';
  142. pattern: FillPatterns;
  143. fgColor?: Partial<Color>;
  144. bgColor?: Partial<Color>;
  145. }
  146. export interface GradientStop {
  147. position: number;
  148. color: Partial<Color>;
  149. }
  150. export interface FillGradientAngle {
  151. type: 'gradient';
  152. gradient: 'angle';
  153. /**
  154. * For 'angle' gradient, specifies the direction of the gradient. 0 is from the left to the right.
  155. * Values from 1 - 359 rotates the direction clockwise
  156. */
  157. degree: number;
  158. /**
  159. * Specifies the gradient colour sequence. Is an array of objects containing position and
  160. * color starting with position 0 and ending with position 1.
  161. * Intermediary positions may be used to specify other colours on the path.
  162. */
  163. stops: GradientStop[];
  164. }
  165. export interface FillGradientPath {
  166. type: 'gradient';
  167. gradient: 'path';
  168. /**
  169. * For 'path' gradient. Specifies the relative coordinates for the start of the path.
  170. * 'left' and 'top' values range from 0 to 1
  171. */
  172. center: { left: number; top: number };
  173. /**
  174. * Specifies the gradient colour sequence. Is an array of objects containing position and
  175. * color starting with position 0 and ending with position 1.
  176. * Intermediary positions may be used to specify other colours on the path.
  177. */
  178. stops: GradientStop[];
  179. }
  180. export type Fill = FillPattern | FillGradientAngle | FillGradientPath;
  181. export interface Font {
  182. name: string;
  183. size: number;
  184. family: number;
  185. scheme: 'minor' | 'major' | 'none';
  186. charset: number;
  187. color: Partial<Color>;
  188. bold: boolean;
  189. italic: boolean;
  190. underline: boolean | 'none' | 'single' | 'double' | 'singleAccounting' | 'doubleAccounting';
  191. vertAlign: 'superscript' | 'subscript';
  192. strike: boolean;
  193. outline: boolean;
  194. }
  195. export type BorderStyle =
  196. | 'thin' | 'dotted' | 'hair' | 'medium' | 'double' | 'thick' | 'dashed' | 'dashDot'
  197. | 'dashDotDot' | 'slantDashDot' | 'mediumDashed' | 'mediumDashDotDot' | 'mediumDashDot';
  198. export interface Color {
  199. /**
  200. * Hex string for alpha-red-green-blue e.g. FF00FF00
  201. */
  202. argb: string;
  203. /**
  204. * Choose a theme by index
  205. */
  206. theme: number;
  207. }
  208. export interface Border {
  209. style: BorderStyle;
  210. color: Partial<Color>;
  211. }
  212. export interface BorderDiagonal extends Border {
  213. up: boolean;
  214. down: boolean;
  215. }
  216. export interface Borders {
  217. top: Partial<Border>;
  218. left: Partial<Border>;
  219. bottom: Partial<Border>;
  220. right: Partial<Border>;
  221. diagonal: Partial<BorderDiagonal>;
  222. }
  223. export interface Margins {
  224. top: number;
  225. left: number;
  226. bottom: number;
  227. right: number;
  228. header: number;
  229. footer: number;
  230. }
  231. export declare enum ReadingOrder {
  232. LeftToRight = 1,
  233. RightToLeft = 2,
  234. }
  235. export interface Alignment {
  236. horizontal: 'left' | 'center' | 'right' | 'fill' | 'justify' | 'centerContinuous' | 'distributed';
  237. vertical: 'top' | 'middle' | 'bottom' | 'distributed' | 'justify';
  238. wrapText: boolean;
  239. shrinkToFit: boolean;
  240. indent: number;
  241. readingOrder: 'rtl' | 'ltr';
  242. textRotation: number | 'vertical';
  243. }
  244. export interface Protection {
  245. locked: boolean;
  246. hidden: boolean;
  247. }
  248. export interface Style {
  249. numFmt: string;
  250. font: Partial<Font>;
  251. alignment: Partial<Alignment>;
  252. protection: Partial<Protection>;
  253. border: Partial<Borders>;
  254. fill: Fill;
  255. }
  256. export type DataValidationOperator =
  257. | 'between' | 'notBetween' | 'equal' | 'notEqual' | 'greaterThan' | 'lessThan'
  258. | 'greaterThanOrEqual' | 'lessThanOrEqual';
  259. export interface DataValidation {
  260. type: 'list' | 'whole' | 'decimal' | 'date' | 'textLength' | 'custom';
  261. formulae: any[];
  262. allowBlank?: boolean;
  263. operator?: DataValidationOperator;
  264. error?: string;
  265. errorTitle?: string;
  266. errorStyle?: string;
  267. prompt?: string;
  268. promptTitle?: string;
  269. showErrorMessage?: boolean;
  270. showInputMessage?: boolean;
  271. }
  272. export declare enum ErrorValue {
  273. NotApplicable = '#N/A',
  274. Ref = '#REF!',
  275. Name = '#NAME?',
  276. DivZero = '#DIV/0!',
  277. Null = '#NULL!',
  278. Value = '#VALUE!',
  279. Num = '#NUM!',
  280. }
  281. export interface CellErrorValue {
  282. error: '#N/A' | '#REF!' | '#NAME?' | '#DIV/0!' | '#NULL!' | '#VALUE!' | '#NUM!';
  283. }
  284. export interface RichText {
  285. text: string;
  286. font?: Partial<Font>;
  287. }
  288. export interface CellRichTextValue {
  289. richText: RichText[];
  290. }
  291. export interface CellHyperlinkValue {
  292. text: string;
  293. hyperlink: string;
  294. tooltip?: string;
  295. }
  296. export interface CellFormulaValue {
  297. formula: string;
  298. result?: number | string | boolean | Date | CellErrorValue;
  299. date1904?: boolean;
  300. }
  301. export interface CellSharedFormulaValue {
  302. sharedFormula: string;
  303. readonly formula?: string;
  304. result?: number | string | boolean | Date | CellErrorValue;
  305. date1904?: boolean;
  306. }
  307. export declare enum ValueType {
  308. Null = 0,
  309. Merge = 1,
  310. Number = 2,
  311. String = 3,
  312. Date = 4,
  313. Hyperlink = 5,
  314. Formula = 6,
  315. SharedString = 7,
  316. RichText = 8,
  317. Boolean = 9,
  318. Error = 10
  319. }
  320. export declare enum FormulaType {
  321. None = 0,
  322. Master = 1,
  323. Shared = 2
  324. }
  325. export type CellValue =
  326. | null | number | string | boolean | Date | undefined
  327. | CellErrorValue
  328. | CellRichTextValue | CellHyperlinkValue
  329. | CellFormulaValue | CellSharedFormulaValue;
  330. export interface CommentMargins {
  331. insetmode: 'auto' | 'custom';
  332. inset: Number[];
  333. }
  334. export interface CommentProtection {
  335. locked: 'True' | 'False';
  336. lockText: 'True' | 'False';
  337. }
  338. export type CommentEditAs = 'twoCells' | 'oneCells' | 'absolute';
  339. export interface Comment {
  340. texts?: RichText[];
  341. margins?: Partial<CommentMargins>;
  342. protection?: Partial<CommentProtection>;
  343. editAs?: CommentEditAs;
  344. }
  345. export interface CellModel {
  346. address: Address;
  347. style: Style;
  348. type: ValueType;
  349. text?: string;
  350. hyperlink?: string;
  351. value?: CellValue;
  352. master: string;
  353. formula?: string;
  354. sharedFormula?: string;
  355. result?: string | number | any;
  356. comment: Comment;
  357. }
  358. export interface Cell extends Style, Address {
  359. readonly worksheet: Worksheet;
  360. readonly workbook: Workbook;
  361. readonly effectiveType: ValueType;
  362. readonly isMerged: boolean;
  363. readonly master: Cell;
  364. readonly isHyperlink: boolean;
  365. readonly hyperlink: string; // todo
  366. readonly text: string;
  367. readonly fullAddress: {
  368. sheetName: string;
  369. address: string;
  370. row: number;
  371. col: number;
  372. };
  373. model: CellModel;
  374. /**
  375. * Assign (or get) a name for a cell (will overwrite any other names that cell had)
  376. */
  377. name: string;
  378. /**
  379. * Assign (or get) an array of names for a cell (cells can have more than one name)
  380. */
  381. names: string[];
  382. /**
  383. * Cells can define what values are valid or not and provide
  384. * prompting to the user to help guide them.
  385. */
  386. dataValidation: DataValidation;
  387. /**
  388. * Value of the cell
  389. */
  390. value: CellValue;
  391. /**
  392. * comment of the cell
  393. */
  394. note: string | Comment;
  395. /**
  396. * convenience getter to access the formula
  397. */
  398. readonly formula: string;
  399. /**
  400. * convenience getter to access the formula result
  401. */
  402. readonly result: number | string | Date;
  403. /**
  404. * The type of the cell's value
  405. */
  406. readonly type: ValueType;
  407. /**
  408. * The type of the cell's formula
  409. */
  410. readonly formulaType: FormulaType;
  411. /**
  412. * The styles of the cell
  413. */
  414. style: Partial<Style>;
  415. addName(name: string): void;
  416. /**
  417. * Remove a name from a cell
  418. */
  419. removeName(name: string): void;
  420. removeAllNames(): void;
  421. destroy(): void;
  422. toCsvString(): string;
  423. release(): void;
  424. addMergeRef(): void;
  425. releaseMergeRef(): void;
  426. merge(master: Cell, ignoreStyle?: boolean): void;
  427. unmerge(): void;
  428. isMergedTo(master: Cell): boolean;
  429. toString(): string;
  430. }
  431. export interface RowModel {
  432. cells: CellModel[];
  433. number: number;
  434. min: number;
  435. max: number;
  436. height: number;
  437. style: Partial<Style>;
  438. hidden: boolean;
  439. outlineLevel: number;
  440. collapsed: boolean;
  441. }
  442. export interface Row extends Style {
  443. readonly worksheet: Worksheet;
  444. readonly hasValues: boolean;
  445. readonly dimensions: number;
  446. model: Partial<RowModel> | null;
  447. /**
  448. * Set a specific row height
  449. */
  450. height: number;
  451. /**
  452. * Make row hidden
  453. */
  454. hidden: boolean;
  455. /**
  456. * Get a row as a sparse array
  457. */
  458. // readonly values: CellValue[];
  459. values: CellValue[] | { [key: string]: CellValue };
  460. /**
  461. * Set an outline level for rows
  462. */
  463. outlineLevel?: number;
  464. /**
  465. * The row number
  466. */
  467. readonly number: number;
  468. /**
  469. * Indicate the collapsed state based on outlineLevel
  470. */
  471. readonly collapsed: boolean;
  472. /**
  473. * Number of cells including empty ones
  474. */
  475. readonly cellCount: number;
  476. /**
  477. * Number of non-empty cells
  478. */
  479. readonly actualCellCount: number;
  480. /**
  481. * Get cell by number, column letter or column key
  482. */
  483. getCell(indexOrKey: number | string): Cell;
  484. findCell(colNumber: number): Cell | undefined;
  485. getCellEx(address: Address): Cell;
  486. /**
  487. * Iterate over all non-null cells in a row
  488. */
  489. eachCell(callback: (cell: Cell, colNumber: number) => void): void;
  490. /**
  491. * Iterate over all cells in a row (including empty cells)
  492. */
  493. eachCell(opt: { includeEmpty: boolean }, callback: (cell: Cell, colNumber: number) => void): void;
  494. /**
  495. * Cut one or more cells (cells to the right are shifted left)
  496. *
  497. * Note: this operation will not affect other rows
  498. */
  499. splice(start: number, count: number, ...insert: any[]): void;
  500. /**
  501. * Commit a completed row to stream
  502. */
  503. commit(): void;
  504. destroy(): void;
  505. addPageBreak(lft?: number, rght?: number): void;
  506. }
  507. export interface Column {
  508. /**
  509. * Can be a string to set one row high header or an array to set multi-row high header
  510. */
  511. header?: string | string[];
  512. /**
  513. * The name of the properties associated with this column in each row
  514. */
  515. key?: string;
  516. /**
  517. * The width of the column
  518. */
  519. width?: number;
  520. /**
  521. * Set an outline level for columns
  522. */
  523. outlineLevel: number;
  524. /**
  525. * Hides the column
  526. */
  527. hidden: boolean;
  528. /**
  529. * Styles applied to the column
  530. */
  531. style: Partial<Style>;
  532. /**
  533. * The cell values in the column
  534. */
  535. values: ReadonlyArray<CellValue>;
  536. /**
  537. * Column letter key
  538. */
  539. readonly letter: string;
  540. readonly number: number;
  541. readonly worksheet: Worksheet;
  542. readonly isCustomWidth: boolean;
  543. readonly headers: string[];
  544. readonly isDefault: boolean;
  545. readonly headerCount: number;
  546. /**
  547. * Below properties read from style
  548. */
  549. border?: Partial<Borders>;
  550. fill?: Fill;
  551. numFmt?: string;
  552. font?: Partial<Font>;
  553. alignment?: Partial<Alignment>;
  554. protection?: Partial<Protection>;
  555. toString(): string
  556. equivalentTo(other: Column): boolean
  557. /**
  558. * indicate the collapsed state based on outlineLevel
  559. */
  560. readonly collapsed: boolean;
  561. /**
  562. * Iterate over all current cells in this column
  563. */
  564. eachCell(callback: (cell: Cell, rowNumber: number) => void): void;
  565. /**
  566. * Iterate over all current cells in this column including empty cells
  567. */
  568. eachCell(opt: { includeEmpty: boolean }, callback: (cell: Cell, rowNumber: number) => void): void;
  569. defn: any; //todo
  570. }
  571. export interface PageSetup {
  572. /**
  573. * Whitespace on the borders of the page. Units are inches.
  574. */
  575. margins: Margins;
  576. /**
  577. * Orientation of the page - i.e. taller (`'portrait'`) or wider (`'landscape'`).
  578. *
  579. * `'portrait'` by default
  580. */
  581. orientation: 'portrait' | 'landscape';
  582. /**
  583. * Horizontal Dots per Inch. Default value is 4294967295
  584. */
  585. horizontalDpi: number;
  586. /**
  587. * Vertical Dots per Inch. Default value is 4294967295
  588. */
  589. verticalDpi: number;
  590. /**
  591. * Whether to use fitToWidth and fitToHeight or scale settings.
  592. *
  593. * Default is based on presence of these settings in the pageSetup object - if both are present,
  594. * scale wins (i.e. default will be false)
  595. */
  596. fitToPage: boolean;
  597. /**
  598. * How many pages wide the sheet should print on to. Active when fitToPage is true
  599. *
  600. * Default is 1
  601. */
  602. fitToWidth: number;
  603. /**
  604. * How many pages high the sheet should print on to. Active when fitToPage is true
  605. *
  606. * Default is 1
  607. */
  608. fitToHeight: number;
  609. /**
  610. * Percentage value to increase or reduce the size of the print. Active when fitToPage is false
  611. *
  612. * Default is 100
  613. */
  614. scale: number;
  615. /**
  616. * Which order to print the pages.
  617. *
  618. * Default is `downThenOver`
  619. */
  620. pageOrder: 'downThenOver' | 'overThenDown';
  621. /**
  622. * Print without colour
  623. *
  624. * false by default
  625. */
  626. blackAndWhite: boolean;
  627. /**
  628. * Print with less quality (and ink)
  629. *
  630. * false by default
  631. */
  632. draft: boolean;
  633. /**
  634. * Where to place comments
  635. *
  636. * Default is `None`
  637. */
  638. cellComments: 'atEnd' | 'asDisplayed' | 'None';
  639. /**
  640. * Where to show errors
  641. *
  642. * Default is `displayed`
  643. */
  644. errors: 'dash' | 'blank' | 'NA' | 'displayed';
  645. /**
  646. * What paper size to use (see below)
  647. *
  648. * | Name | Value |
  649. * | ----------------------------- | --------- |
  650. * | Letter | `undefined` |
  651. * | Legal | `5` |
  652. * | Executive | `7` |
  653. * | A4 | `9` |
  654. * | A5 | `11` |
  655. * | B5 (JIS) | `13` |
  656. * | Envelope #10 | `20` |
  657. * | Envelope DL | `27` |
  658. * | Envelope C5 | `28` |
  659. * | Envelope B5 | `34` |
  660. * | Envelope Monarch | `37` |
  661. * | Double Japan Postcard Rotated | `82` |
  662. * | 16K 197x273 mm | `119` |
  663. */
  664. paperSize: PaperSize;
  665. /**
  666. * Whether to show the row numbers and column letters, `false` by default
  667. */
  668. showRowColHeaders: boolean;
  669. /**
  670. * Whether to show grid lines, `false` by default
  671. */
  672. showGridLines: boolean;
  673. /**
  674. * Which number to use for the first page
  675. */
  676. firstPageNumber: number;
  677. /**
  678. * Whether to center the sheet data horizontally, `false` by default
  679. */
  680. horizontalCentered: boolean;
  681. /**
  682. * Whether to center the sheet data vertically, `false` by default
  683. */
  684. verticalCentered: boolean;
  685. /**
  686. * Set Print Area for a sheet, e.g. `'A1:G20'`
  687. */
  688. printArea: string;
  689. /**
  690. * Repeat specific rows on every printed page, e.g. `'1:3'`
  691. */
  692. printTitlesRow: string;
  693. /**
  694. * Repeat specific columns on every printed page, e.g. `'A:C'`
  695. */
  696. printTitlesColumn: string;
  697. }
  698. export interface HeaderFooter {
  699. /**
  700. * Set the value of differentFirst as true, which indicates that headers/footers for first page are different from the other pages, `false` by default
  701. */
  702. differentFirst: boolean,
  703. /**
  704. * Set the value of differentOddEven as true, which indicates that headers/footers for odd and even pages are different, `false` by default
  705. */
  706. differentOddEven: boolean,
  707. /**
  708. * Set header string for odd pages, could format the string and `null` by default
  709. */
  710. oddHeader: string,
  711. /**
  712. * Set footer string for odd pages, could format the string and `null` by default
  713. */
  714. oddFooter: string,
  715. /**
  716. * Set header string for even pages, could format the string and `null` by default
  717. */
  718. evenHeader: string,
  719. /**
  720. * Set footer string for even pages, could format the string and `null` by default
  721. */
  722. evenFooter: string,
  723. /**
  724. * Set header string for the first page, could format the string and `null` by default
  725. */
  726. firstHeader: string,
  727. /**
  728. * Set footer string for the first page, could format the string and `null` by default
  729. */
  730. firstFooter: string
  731. }
  732. export type AutoFilter = string | {
  733. from: string | { row: number; column: number };
  734. to: string | { row: number; column: number };
  735. };
  736. export interface WorksheetProtection {
  737. objects: boolean;
  738. scenarios: boolean;
  739. selectLockedCells: boolean;
  740. selectUnlockedCells: boolean;
  741. formatCells: boolean;
  742. formatColumns: boolean;
  743. formatRows: boolean;
  744. insertColumns: boolean;
  745. insertRows: boolean;
  746. insertHyperlinks: boolean;
  747. deleteColumns: boolean;
  748. deleteRows: boolean;
  749. sort: boolean;
  750. autoFilter: boolean;
  751. pivotTables: boolean;
  752. spinCount: number;
  753. }
  754. export interface Image {
  755. extension: 'jpeg' | 'png' | 'gif';
  756. base64?: string;
  757. filename?: string;
  758. buffer?: Buffer;
  759. }
  760. export interface IAnchor {
  761. col: number;
  762. row: number;
  763. nativeCol: number;
  764. nativeRow: number;
  765. nativeColOff: number;
  766. nativeRowOff: number;
  767. }
  768. export class Anchor implements IAnchor {
  769. col: number;
  770. nativeCol: number;
  771. nativeColOff: number;
  772. nativeRow: number;
  773. nativeRowOff: number;
  774. row: number;
  775. private readonly colWidth: number;
  776. private readonly rowHeight: number;
  777. worksheet: Worksheet;
  778. constructor(model?: IAnchor | object);
  779. }
  780. export interface ImageRange {
  781. tl: Anchor;
  782. br: Anchor;
  783. }
  784. export interface ImagePosition {
  785. tl: { col: number; row: number };
  786. ext: { width: number; height: number };
  787. }
  788. export interface ImageHyperlinkValue {
  789. hyperlink: string;
  790. tooltip?: string;
  791. }
  792. export interface Range extends Location {
  793. sheetName: string;
  794. tl: string;
  795. $t$l: string;
  796. br: string;
  797. $b$r: string;
  798. range: string;
  799. $range: string;
  800. shortRange: string;
  801. $shortRange: string;
  802. count: number;
  803. decode(): void;
  804. decode(v: Range): void;
  805. decode(v: string): void;
  806. decode(v: Location): void;
  807. decode(top: number, left: number, bottom: number, right: number, sheetName?: string): void;
  808. decode(tl: string, br: string, sheetName?: string): void;
  809. decode(v: [string, string]): void;
  810. decode(v: [string, string, string]): void;
  811. decode(v: [number, number, number, number]): void;
  812. decode(v: [number, number, number, number, string]): void;
  813. expand(top: number, left: number, bottom: number, right: number): void;
  814. expandRow(row: Row): void;
  815. expandToAddress(addressStr: string): void;
  816. toString(): string;
  817. intersects(other: Range): boolean;
  818. contains(addressStr: string): boolean;
  819. containsEx(address: Partial<{
  820. sheetName: string;
  821. row: number;
  822. col: number;
  823. }>): boolean;
  824. }
  825. export interface RowBreak {
  826. id: number;
  827. max: number;
  828. min: number;
  829. man: number;
  830. }
  831. export interface WorksheetModel {
  832. id: number;
  833. name: string;
  834. // dataValidations: this.dataValidations.model,
  835. properties: WorksheetProperties;
  836. pageSetup: Partial<PageSetup>;
  837. headerFooter: Partial<HeaderFooter>;
  838. rowBreaks: RowBreak[];
  839. views: WorksheetView[];
  840. autoFilter: AutoFilter;
  841. media: Media[];
  842. merges: Range['range'][];
  843. }
  844. export type WorksheetState = 'visible' | 'hidden' | 'veryHidden';
  845. export type CellIsOperators = 'equal' | 'greaterThan' | 'lessThan' | 'between';
  846. export type ContainsTextOperators = 'containsText' | 'containsBlanks' | 'notContainsBlanks' | 'containsErrors' | 'notContainsErrors';
  847. export type TimePeriodTypes = 'lastWeek' | 'thisWeek' | 'nextWeek' | 'yesterday' | 'today' | 'tomorrow' | 'last7Days' | 'lastMonth'
  848. | 'thisMonth' | 'nextMonth';
  849. export type IconSetTypes = '5Arrows' | '5ArrowsGray' | '5Boxes' | '5Quarters' | '5Rating' | '4Arrows' | '4ArrowsGray'
  850. | '4Rating' | '4RedToBlack' | '4TrafficLights' | 'NoIcons' | '3Arrows' | '3ArrowsGray' | '3Flags' | '3Signs'
  851. | '3Stars' | '3Symbols' | '3Symbols2' | '3TrafficLights1' | '3TrafficLights2' | '3Triangles';
  852. export type CfvoTypes = 'percentile' | 'percent' | 'num' | 'min' | 'max' | 'formula' | 'autoMin' | 'autoMax';
  853. export interface Cvfo {
  854. type: CfvoTypes;
  855. value?: number;
  856. }
  857. export interface ConditionalFormattingBaseRule {
  858. priority: number;
  859. style?: Partial<Style>;
  860. }
  861. export interface ExpressionRuleType extends ConditionalFormattingBaseRule {
  862. type: 'expression';
  863. formulae?: any[];
  864. }
  865. export interface CellIsRuleType extends ConditionalFormattingBaseRule {
  866. type: 'cellIs';
  867. formulae?: any[];
  868. operator?: CellIsOperators;
  869. }
  870. export interface Top10RuleType extends ConditionalFormattingBaseRule {
  871. type: 'top10';
  872. rank: number;
  873. percent: boolean;
  874. bottom: boolean;
  875. }
  876. export interface AboveAverageRuleType extends ConditionalFormattingBaseRule {
  877. type: 'aboveAverage';
  878. aboveAverage: boolean;
  879. }
  880. export interface ColorScaleRuleType extends ConditionalFormattingBaseRule {
  881. type: 'colorScale';
  882. cfvo?: Cvfo[];
  883. color?: Partial<Color>[];
  884. }
  885. export interface IconSetRuleType extends ConditionalFormattingBaseRule {
  886. type: 'iconSet';
  887. showValue?: boolean;
  888. reverse?: boolean;
  889. custom?: boolean;
  890. iconSet?: IconSetTypes;
  891. cfvo?: Cvfo[];
  892. }
  893. export interface ContainsTextRuleType extends ConditionalFormattingBaseRule {
  894. type: 'containsText';
  895. operator?: ContainsTextOperators;
  896. text?: string;
  897. }
  898. export interface TimePeriodRuleType extends ConditionalFormattingBaseRule {
  899. type: 'timePeriod';
  900. timePeriod?: TimePeriodTypes;
  901. }
  902. export interface DataBarRuleType extends ConditionalFormattingBaseRule {
  903. type: 'dataBar';
  904. gradient?: boolean;
  905. minLength?: number;
  906. maxLength?: number;
  907. showValue?: boolean;
  908. border?: boolean;
  909. negativeBarColorSameAsPositive?: boolean;
  910. negativeBarBorderColorSameAsPositive?: boolean;
  911. axisPosition?: 'auto' | 'middle' | 'none';
  912. direction?: 'context' | 'leftToRight' | 'rightToLeft';
  913. cfvo?: Cvfo[];
  914. }
  915. export type ConditionalFormattingRule = ExpressionRuleType | CellIsRuleType | Top10RuleType | AboveAverageRuleType | ColorScaleRuleType | IconSetRuleType
  916. | ContainsTextRuleType | TimePeriodRuleType | DataBarRuleType;
  917. export type RowValues = CellValue[] | { [key: string]: CellValue } | undefined | null;
  918. export interface ConditionalFormattingOptions {
  919. ref: string;
  920. rules: ConditionalFormattingRule[];
  921. }
  922. export interface Worksheet {
  923. readonly id: number;
  924. name: string;
  925. readonly workbook: Workbook;
  926. readonly hasMerges: boolean;
  927. readonly dimensions: Range;
  928. /**
  929. * Contains information related to how a worksheet is printed
  930. */
  931. pageSetup: Partial<PageSetup>;
  932. /**
  933. * Worksheet Header and Footer
  934. */
  935. headerFooter: Partial<HeaderFooter>;
  936. /**
  937. * Worksheet State
  938. */
  939. state: WorksheetState;
  940. /**
  941. * Worksheet Properties
  942. */
  943. properties: WorksheetProperties;
  944. /**
  945. * Open panes representing the sheet
  946. */
  947. views: Array<Partial<WorksheetView>>;
  948. /**
  949. * Apply an auto filter to your worksheet.
  950. */
  951. autoFilter?: AutoFilter;
  952. destroy(): void;
  953. /**
  954. * A count of the number of rows that have values. If a mid-document row is empty, it will not be included in the count.
  955. */
  956. readonly actualRowCount: number;
  957. /**
  958. * The total column size of the document. Equal to the maximum cell count from all of the rows
  959. */
  960. readonly columnCount: number;
  961. /**
  962. * Get the last column in a worksheet
  963. */
  964. readonly lastColumn: Column | undefined;
  965. /**
  966. * A count of the number of columns that have values.
  967. */
  968. readonly actualColumnCount: number;
  969. getColumnKey(key: string): Column;
  970. setColumnKey(key: string, value: Column): void;
  971. deleteColumnKey(key: string): void;
  972. eachColumnKey(callback: (col: Column, index: number) => void): void;
  973. /**
  974. * Access an individual columns by key, letter and 1-based column number
  975. */
  976. getColumn(indexOrKey: number | string): Column;
  977. /**
  978. * Cut one or more columns (columns to the right are shifted left)
  979. * and optionally insert more
  980. *
  981. * If column properties have been definde, they will be cut or moved accordingly
  982. *
  983. * Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
  984. *
  985. * Also: If the worksheet has more rows than values in the colulmn inserts,
  986. * the rows will still be shifted as if the values existed
  987. */
  988. spliceColumns(start: number, count: number, ...insert: any[][]): void;
  989. /**
  990. * Add column headers and define column keys and widths.
  991. *
  992. * Note: these column structures are a workbook-building convenience only,
  993. * apart from the column width, they will not be fully persisted.
  994. */
  995. columns: Array<Partial<Column>>;
  996. /**
  997. * The total row size of the document. Equal to the row number of the last row that has values.
  998. */
  999. readonly rowCount: number;
  1000. /**
  1001. * Get the last editable row in a worksheet (or undefined if there are none)
  1002. */
  1003. readonly lastRow: Row | undefined;
  1004. /**
  1005. * Tries to find and return row for row no, else undefined
  1006. *
  1007. * @param row The 1-index row number
  1008. */
  1009. findRow(row: number): Row | undefined;
  1010. /**
  1011. * Tries to find and return rows for row no start and length, else undefined
  1012. *
  1013. * @param start The 1-index starting row number
  1014. * @param length The length of the expected array
  1015. */
  1016. findRows(start: number, length: number): Row[] | undefined;
  1017. /**
  1018. * Cut one or more rows (rows below are shifted up)
  1019. * and optionally insert more
  1020. *
  1021. * Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
  1022. */
  1023. spliceRows(start: number, count: number, ...insert: any[][]): void;
  1024. /**
  1025. * Add a couple of Rows by key-value, after the last current row, using the column keys,
  1026. * or add a row by contiguous Array (assign to columns A, B & C)
  1027. */
  1028. addRow(data: any[] | any, style?: string): Row;
  1029. /**
  1030. * Add multiple rows by providing an array of arrays or key-value pairs
  1031. */
  1032. addRows(rows: any[], style?: string): Row[];
  1033. /**
  1034. * Insert a Row by key-value, at the position (shifiting down all rows from position),
  1035. * using the column keys, or add a row by contiguous Array (assign to columns A, B & C)
  1036. */
  1037. insertRow(pos: number, value: any[] | any, style?: string): Row;
  1038. /**
  1039. * Insert multiple rows at position (shifiting down all rows from position)
  1040. * by providing an array of arrays or key-value pairs
  1041. */
  1042. insertRows(pos: number, values: any[], style?: string): Row[];
  1043. /**
  1044. * Duplicate rows and insert new rows
  1045. */
  1046. duplicateRow(rowNum: number, count: number, insert: boolean): void;
  1047. /**
  1048. * Get or create row by 1-based index
  1049. */
  1050. getRow(index: number): Row;
  1051. /**
  1052. * Get or create rows by 1-based index
  1053. */
  1054. getRows(start: number, length: number): Row[] | undefined;
  1055. /**
  1056. * Iterate over all rows that have values in a worksheet
  1057. */
  1058. eachRow(callback: (row: Row, rowNumber: number) => void): void;
  1059. /**
  1060. * Iterate over all rows (including empty rows) in a worksheet
  1061. */
  1062. eachRow(opt: { includeEmpty: boolean }, callback: (row: Row, rowNumber: number) => void): void;
  1063. /**
  1064. * return all rows as sparse array
  1065. */
  1066. getSheetValues(): RowValues[];
  1067. /**
  1068. * returns the cell at [r,c] or address given by r. If not found, return undefined
  1069. */
  1070. findCell(r: number | string, c: number | string): Cell | undefined;
  1071. /**
  1072. * Get or create cell
  1073. */
  1074. getCell(r: number | string, c?: number | string): Cell;
  1075. /**
  1076. * Merge cells, either:
  1077. *
  1078. * tlbr string, e.g. `'A4:B5'`
  1079. *
  1080. * tl string, br string, e.g. `'G10', 'H11'`
  1081. *
  1082. * t, l, b, r numbers, e.g. `10,11,12,13`
  1083. */
  1084. mergeCells(): void;
  1085. mergeCells(v: Range): void;
  1086. mergeCells(v: string): void;
  1087. mergeCells(v: Location): void;
  1088. mergeCells(top: number, left: number, bottom: number, right: number, sheetName?: string): void;
  1089. mergeCells(tl: string, br: string, sheetName?: string): void;
  1090. mergeCells(v: [string, string]): void;
  1091. mergeCells(v: [string, string, string]): void;
  1092. mergeCells(v: [number, number, number, number]): void;
  1093. mergeCells(v: [number, number, number, number, string]): void;
  1094. mergeCellsWithoutStyle(): void;
  1095. mergeCellsWithoutStyle(v: Range): void;
  1096. mergeCellsWithoutStyle(v: string): void;
  1097. mergeCellsWithoutStyle(v: Location): void;
  1098. mergeCellsWithoutStyle(top: number, left: number, bottom: number, right: number, sheetName?: string): void;
  1099. mergeCellsWithoutStyle(tl: string, br: string, sheetName?: string): void;
  1100. mergeCellsWithoutStyle(v: [string, string]): void;
  1101. mergeCellsWithoutStyle(v: [string, string, string]): void;
  1102. mergeCellsWithoutStyle(v: [number, number, number, number]): void;
  1103. mergeCellsWithoutStyle(v: [number, number, number, number, string]): void;
  1104. /**
  1105. * unmerging the cells breaks the style links
  1106. */
  1107. unMergeCells(): void;
  1108. unMergeCells(v: Range): void;
  1109. unMergeCells(v: string): void;
  1110. unMergeCells(v: Location): void;
  1111. unMergeCells(top: number, left: number, bottom: number, right: number, sheetName?: string): void;
  1112. unMergeCells(tl: string, br: string, sheetName?: string): void;
  1113. unMergeCells(v: [string, string]): void;
  1114. unMergeCells(v: [string, string, string]): void;
  1115. unMergeCells(v: [number, number, number, number]): void;
  1116. unMergeCells(v: [number, number, number, number, string]): void;
  1117. fillFormula(range: Range | string | Location, formula: string, results?: ((r: number, c: number) => string | number) | number[] | number[][]): void;
  1118. /**
  1119. * Using the image id from `Workbook.addImage`, set the background to the worksheet
  1120. */
  1121. addBackgroundImage(imageId: number): void;
  1122. getBackgroundImageId(): string;
  1123. /**
  1124. * Using the image id from `Workbook.addImage`,
  1125. * embed an image within the worksheet to cover a range
  1126. */
  1127. addImage(imageId: number, range: string | { editAs?: string; } & ImageRange & { hyperlinks?: ImageHyperlinkValue } | { editAs?: string; } & ImagePosition & { hyperlinks?: ImageHyperlinkValue }): void;
  1128. getImages(): Array<{
  1129. type: 'image',
  1130. imageId: string;
  1131. range: ImageRange;
  1132. }>;
  1133. commit(): void;
  1134. model: WorksheetModel;
  1135. /**
  1136. * Worksheet protection
  1137. */
  1138. protect(password: string, options: Partial<WorksheetProtection>): Promise<void>;
  1139. unprotect(): void;
  1140. /**
  1141. * Add a new table and return a reference to it
  1142. */
  1143. addTable(tableProperties: TableProperties): Table;
  1144. /**
  1145. * fetch table by name or id
  1146. */
  1147. getTable(name: string): Table;
  1148. /**
  1149. * delete table by name or id
  1150. */
  1151. removeTable(name: string): void;
  1152. /**
  1153. * fetch table
  1154. */
  1155. getTables(): [Table, void][];
  1156. /**
  1157. * add conditionalFormattingOptions
  1158. */
  1159. addConditionalFormatting(cf: ConditionalFormattingOptions): void;
  1160. /**
  1161. * delete conditionalFormattingOptions
  1162. */
  1163. removeConditionalFormatting(filter: any): void;
  1164. }
  1165. export interface CalculationProperties {
  1166. /**
  1167. * Whether the application shall perform a full recalculation when the workbook is opened
  1168. */
  1169. fullCalcOnLoad: boolean
  1170. }
  1171. export interface WorksheetProperties {
  1172. /**
  1173. * Color of the tab
  1174. */
  1175. tabColor: Partial<Color>;
  1176. /**
  1177. * The worksheet column outline level (default: 0)
  1178. */
  1179. outlineLevelCol: number;
  1180. /**
  1181. * The worksheet row outline level (default: 0)
  1182. */
  1183. outlineLevelRow: number;
  1184. /**
  1185. * The outline properties which controls how it will summarize rows and columns
  1186. */
  1187. outlineProperties: {
  1188. summaryBelow: boolean,
  1189. summaryRight: boolean,
  1190. };
  1191. /**
  1192. * Default row height (default: 15)
  1193. */
  1194. defaultRowHeight: number;
  1195. /**
  1196. * Default column width (optional)
  1197. */
  1198. defaultColWidth?: number;
  1199. /**
  1200. * default: 55
  1201. */
  1202. dyDescent: number;
  1203. showGridLines: boolean;
  1204. }
  1205. export interface AddWorksheetOptions {
  1206. properties: Partial<WorksheetProperties>;
  1207. pageSetup: Partial<PageSetup>;
  1208. headerFooter: Partial<HeaderFooter>;
  1209. views: Array<Partial<WorksheetView>>;
  1210. state: WorksheetState;
  1211. }
  1212. export interface WorkbookProperties {
  1213. /**
  1214. * Set workbook dates to 1904 date system
  1215. */
  1216. date1904: boolean;
  1217. }
  1218. export interface JSZipGeneratorOptions {
  1219. /**
  1220. * @default DEFLATE
  1221. */
  1222. compression: 'STORE' | 'DEFLATE';
  1223. compressionOptions: null | {
  1224. /**
  1225. * @default 6
  1226. */
  1227. level: number;
  1228. };
  1229. }
  1230. export interface XlsxReadOptions {
  1231. /**
  1232. * The list of XML node names to ignore while parsing an XLSX file
  1233. */
  1234. ignoreNodes: string[];
  1235. }
  1236. export interface XlsxWriteOptions extends stream.xlsx.WorkbookWriterOptions {
  1237. /**
  1238. * The option passed to JsZip#generateAsync(options)
  1239. */
  1240. zip: Partial<JSZipGeneratorOptions>;
  1241. }
  1242. export interface Xlsx {
  1243. /**
  1244. * read from a file
  1245. */
  1246. readFile(path: string, options?: Partial<XlsxReadOptions>): Promise<Workbook>;
  1247. /**
  1248. * read from a stream
  1249. * @param stream
  1250. */
  1251. read(stream: import('stream').Stream, options?: Partial<XlsxReadOptions>): Promise<Workbook>;
  1252. /**
  1253. * load from an array buffer
  1254. * @param buffer
  1255. */
  1256. load(buffer: Buffer, options?: Partial<XlsxReadOptions>): Promise<Workbook>;
  1257. /**
  1258. * write to a buffer
  1259. */
  1260. writeBuffer(options?: Partial<XlsxWriteOptions>): Promise<Buffer>;
  1261. /**
  1262. * write to a file
  1263. */
  1264. writeFile(path: string, options?: Partial<XlsxWriteOptions>): Promise<void>;
  1265. /**
  1266. * write to a stream
  1267. */
  1268. write(stream: import('stream').Stream, options?: Partial<XlsxWriteOptions>): Promise<void>;
  1269. }
  1270. // https://c2fo.github.io/fast-csv/docs/parsing/options
  1271. type HeaderArray = (string | undefined | null)[];
  1272. type HeaderTransformFunction = (headers: HeaderArray) => HeaderArray;
  1273. export interface FastCsvParserOptionsArgs {
  1274. objectMode: boolean;
  1275. delimiter: string;
  1276. quote: string | null;
  1277. escape: string;
  1278. headers: boolean | HeaderTransformFunction | HeaderArray;
  1279. renameHeaders: boolean;
  1280. ignoreEmpty: boolean;
  1281. comment: string;
  1282. strictColumnHandling: boolean;
  1283. discardUnmappedColumns: boolean;
  1284. trim: boolean;
  1285. ltrim: boolean;
  1286. rtrim: boolean;
  1287. encoding: string;
  1288. maxRows: number;
  1289. skipLines: number;
  1290. skipRows: number;
  1291. }
  1292. interface QuoteColumnMap {
  1293. [s: string]: boolean;
  1294. }
  1295. declare type QuoteColumns = boolean | boolean[] | QuoteColumnMap;
  1296. interface RowMap {
  1297. [key: string]: any;
  1298. }
  1299. declare type RowHashArray = [string, any][];
  1300. declare type RowArray = string[];
  1301. declare type Rows = RowArray | RowMap | RowHashArray;
  1302. declare type RowTransformCallback = (error?: Error | null, row?: Rows) => void;
  1303. interface RowTransformFunction {
  1304. (row: Rows, callback: RowTransformCallback): void;
  1305. (row: Rows): Rows;
  1306. }
  1307. // https://c2fo.github.io/fast-csv/docs/formatting/options/
  1308. export interface FastCsvFormatterOptionsArgs {
  1309. objectMode: boolean;
  1310. delimiter: string;
  1311. rowDelimiter: string;
  1312. quote: string | boolean;
  1313. escape: string;
  1314. quoteColumns: QuoteColumns;
  1315. quoteHeaders: QuoteColumns;
  1316. headers: null | boolean | string[];
  1317. includeEndRowDelimiter: boolean;
  1318. writeBOM: boolean;
  1319. transform: RowTransformFunction;
  1320. alwaysWriteHeaders: boolean;
  1321. }
  1322. export interface CsvReadOptions {
  1323. dateFormats: string[];
  1324. map(value: any, index: number): any;
  1325. sheetName: string;
  1326. parserOptions: Partial<FastCsvParserOptionsArgs>;
  1327. }
  1328. export interface CsvWriteOptions {
  1329. dateFormat: string;
  1330. dateUTC: boolean;
  1331. sheetName: string;
  1332. sheetId: number;
  1333. encoding: string;
  1334. map(value: any, index: number): any;
  1335. includeEmptyRows: boolean;
  1336. formatterOptions: Partial<FastCsvFormatterOptionsArgs>;
  1337. }
  1338. export interface Csv {
  1339. /**
  1340. * read from a file
  1341. */
  1342. readFile(path: string, options?: Partial<CsvReadOptions>): Promise<Worksheet>;
  1343. /**
  1344. * read from a stream
  1345. */
  1346. read(stream: import('stream').Stream, options?: Partial<CsvReadOptions>): Promise<Worksheet>;
  1347. /**
  1348. * Create input stream for reading
  1349. */
  1350. createInputStream(options?: Partial<CsvReadOptions>): import('events').EventEmitter;
  1351. /**
  1352. * write to a buffer
  1353. */
  1354. writeBuffer(options?: Partial<CsvWriteOptions>): Promise<Buffer>;
  1355. /**
  1356. * write to a file
  1357. */
  1358. writeFile(path: string, options?: Partial<CsvWriteOptions>): Promise<void>;
  1359. /**
  1360. * write to a stream
  1361. */
  1362. write(stream: import('stream').Stream, options?: Partial<CsvWriteOptions>): Promise<void>;
  1363. }
  1364. export interface Media {
  1365. type: string; // image,background
  1366. name: string;
  1367. extension: string;
  1368. buffer: Buffer;
  1369. }
  1370. export interface Address {
  1371. sheetName?: string;
  1372. address: string;
  1373. col: string;
  1374. row: string;
  1375. $col$row: string;
  1376. }
  1377. export interface Location {
  1378. top: number;
  1379. left: number;
  1380. bottom: number;
  1381. right: number;
  1382. }
  1383. export interface CellMatrix {
  1384. addCell(addressStr: string): void;
  1385. getCell(addressStr: string): Cell;
  1386. findCell(addressStr: string): Cell | undefined;
  1387. findCellAt(sheetName: string, rowNumber: number, colNumber: number): Cell | undefined;
  1388. addCellEx(address: string | Location): void;
  1389. getCellEx(address: string | Location): Cell;
  1390. findCellEx(address: string | Location, create: boolean): Cell | undefined;
  1391. getCellAt(sheetName: string, rowNumber: number, colNumber: number): Cell;
  1392. removeCellEx(address: string | Location): void;
  1393. forEach(callback: (cell: Cell) => void): void;
  1394. map<T>(callback: (cell: Cell) => T): T[];
  1395. findSheet(address: string | Location, create: boolean): Cell[] | undefined;
  1396. findSheetRow(sheet: Cell[][], address: string | Location, create: boolean): Row | undefined;
  1397. findRowCell(row: any[], address: Address, create: boolean): Cell | undefined;
  1398. }
  1399. export interface DefinedNamesRanges {
  1400. name: string;
  1401. ranges: string[];
  1402. }
  1403. export type DefinedNamesModel = DefinedNamesRanges[];
  1404. export interface DefinedNames {
  1405. getMatrix(name: string): CellMatrix;
  1406. // add a name to a cell. locStr in the form SheetName!$col$row or SheetName!$c1$r1:$c2:$r2
  1407. add(locStr: string, name?: string): void;
  1408. addEx(location: string | Location, name: string): Cell;
  1409. remove(locStr: string | Location, name: string): void;
  1410. removeEx(location: string | Location, name: string): void;
  1411. removeAllNames(location: string | Location): void;
  1412. forEach(callback: (name: string, cell: Cell) => void): void;
  1413. // get all the names of a cell
  1414. getNames(addressStr: string): string[];
  1415. getNamesEx(address: string): string[];
  1416. getRanges(name: string, matrix?: CellMatrix): DefinedNamesRanges;
  1417. model: DefinedNamesModel;
  1418. }
  1419. export interface WorkbookModel {
  1420. creator: string;
  1421. lastModifiedBy: string;
  1422. lastPrinted: Date;
  1423. created: Date;
  1424. modified: Date;
  1425. properties: WorkbookProperties;
  1426. worksheets: Worksheet[];
  1427. sheets: WorksheetModel[];
  1428. definedNames: DefinedNamesModel;
  1429. views: WorkbookView[];
  1430. company: string;
  1431. manager: string;
  1432. title: string;
  1433. subject: string;
  1434. keywords: string;
  1435. category: string;
  1436. description: string;
  1437. language: string;
  1438. revision: Date;
  1439. contentStatus: string;
  1440. themes: string[];
  1441. media: Media[];
  1442. }
  1443. export class Workbook {
  1444. category: string;
  1445. company: string;
  1446. creator: string;
  1447. description: string;
  1448. keywords: string;
  1449. lastModifiedBy: string;
  1450. created: Date;
  1451. manager: string;
  1452. modified: Date;
  1453. lastPrinted: Date;
  1454. properties: WorkbookProperties;
  1455. subject: string;
  1456. title: string;
  1457. /**
  1458. * Workbook calculation Properties
  1459. */
  1460. calcProperties: CalculationProperties;
  1461. /**
  1462. * xlsx file format operations
  1463. */
  1464. readonly xlsx: Xlsx;
  1465. /**
  1466. * csv file format operations
  1467. */
  1468. readonly csv: Csv;
  1469. readonly nextId: number;
  1470. readonly definedNames: DefinedNames;
  1471. model: WorkbookModel;
  1472. /**
  1473. * The Workbook views controls how many separate windows Excel will open when viewing the workbook.
  1474. */
  1475. views: WorkbookView[];
  1476. /**
  1477. * return a clone of worksheets in order
  1478. */
  1479. worksheets: Worksheet[];
  1480. /**
  1481. * Add a new worksheet and return a reference to it
  1482. */
  1483. addWorksheet(name?: string, options?: Partial<AddWorksheetOptions>): Worksheet;
  1484. removeWorksheetEx(worksheet: Worksheet): void;
  1485. removeWorksheet(indexOrName: number | string): void;
  1486. /**
  1487. * fetch sheet by name or id
  1488. */
  1489. getWorksheet(indexOrName?: number | string): Worksheet | undefined;
  1490. /**
  1491. * Iterate over all sheets.
  1492. *
  1493. * Note: `workbook.worksheets.forEach` will still work but this is better.
  1494. */
  1495. eachSheet(callback: (worksheet: Worksheet, id: number) => void): void;
  1496. clearThemes(): void;
  1497. /**
  1498. * Add Image to Workbook and return the id
  1499. */
  1500. addImage(img: Image): number;
  1501. getImage(id: number): Image;
  1502. }
  1503. export interface TableStyleProperties {
  1504. /**
  1505. * The colour theme of the table
  1506. * @default 'TableStyleMedium2'
  1507. */
  1508. theme?: 'TableStyleDark1' | 'TableStyleDark10' | 'TableStyleDark11' | 'TableStyleDark2' | 'TableStyleDark3' | 'TableStyleDark4' | 'TableStyleDark5' | 'TableStyleDark6' | 'TableStyleDark7' | 'TableStyleDark8' | 'TableStyleDark9' | 'TableStyleLight1' | 'TableStyleLight10' | 'TableStyleLight11' | 'TableStyleLight12' | 'TableStyleLight13' | 'TableStyleLight14' | 'TableStyleLight15' | 'TableStyleLight16' | 'TableStyleLight17' | 'TableStyleLight18' | 'TableStyleLight19' | 'TableStyleLight2' | 'TableStyleLight20' | 'TableStyleLight21' | 'TableStyleLight3' | 'TableStyleLight4' | 'TableStyleLight5' | 'TableStyleLight6' | 'TableStyleLight7' | 'TableStyleLight8' | 'TableStyleLight9' | 'TableStyleMedium1' | 'TableStyleMedium10' | 'TableStyleMedium11' | 'TableStyleMedium12' | 'TableStyleMedium13' | 'TableStyleMedium14' | 'TableStyleMedium15' | 'TableStyleMedium16' | 'TableStyleMedium17' | 'TableStyleMedium18' | 'TableStyleMedium19' | 'TableStyleMedium2' | 'TableStyleMedium20' | 'TableStyleMedium21' | 'TableStyleMedium22' | 'TableStyleMedium23' | 'TableStyleMedium24' | 'TableStyleMedium25' | 'TableStyleMedium26' | 'TableStyleMedium27' | 'TableStyleMedium28' | 'TableStyleMedium3' | 'TableStyleMedium4' | 'TableStyleMedium5' | 'TableStyleMedium6' | 'TableStyleMedium7' | 'TableStyleMedium8' | 'TableStyleMedium9';
  1509. /**
  1510. * Highlight the first column (bold)
  1511. * @default false
  1512. */
  1513. showFirstColumn?: boolean;
  1514. /**
  1515. * Highlight the last column (bold)
  1516. * @default false
  1517. */
  1518. showLastColumn?: boolean;
  1519. /**
  1520. * Alternate rows shown with background colour
  1521. * @default false
  1522. */
  1523. showRowStripes?: boolean;
  1524. /**
  1525. * Alternate rows shown with background colour
  1526. * @default false
  1527. */
  1528. showColumnStripes?: boolean;
  1529. }
  1530. export interface TableColumnProperties {
  1531. /**
  1532. * The name of the column, also used in the header
  1533. */
  1534. name: string;
  1535. /**
  1536. * Switches the filter control in the header
  1537. * @default false
  1538. */
  1539. filterButton?: boolean;
  1540. /**
  1541. * Label to describe the totals row (first column)
  1542. * @default 'Total'
  1543. */
  1544. totalsRowLabel?: string;
  1545. /**
  1546. * Name of the totals function
  1547. * @default 'none'
  1548. */
  1549. totalsRowFunction?: 'none' | 'average' | 'countNums' | 'count' | 'max' | 'min' | 'stdDev' | 'var' | 'sum' | 'custom';
  1550. /**
  1551. * Optional formula for custom functions
  1552. */
  1553. totalsRowFormula?: string;
  1554. }
  1555. export interface TableProperties {
  1556. /**
  1557. * The name of the table
  1558. */
  1559. name: string;
  1560. /**
  1561. * The display name of the table
  1562. */
  1563. displayName?: string;
  1564. /**
  1565. * Top left cell of the table
  1566. */
  1567. ref: string;
  1568. /**
  1569. * Show headers at top of table
  1570. * @default true
  1571. */
  1572. headerRow?: boolean;
  1573. /**
  1574. * Show totals at bottom of table
  1575. * @default false
  1576. */
  1577. totalsRow?: boolean;
  1578. /**
  1579. * Extra style properties
  1580. * @default {}
  1581. */
  1582. style?: TableStyleProperties;
  1583. /**
  1584. * Column definitions
  1585. */
  1586. columns: TableColumnProperties[]
  1587. /**
  1588. * Rows of data
  1589. */
  1590. rows: any[][]
  1591. }
  1592. export type TableColumn = Required<TableColumnProperties>
  1593. export interface Table extends Required<TableProperties> {
  1594. /**
  1595. * Commit changes
  1596. */
  1597. commit: () => void
  1598. /**
  1599. * Remove a rows of data
  1600. */
  1601. removeRows: (rowIndex: number, count: number) => void
  1602. /**
  1603. * Add a row of data, either insert at rowNumber or append
  1604. */
  1605. addRow: (values: any[], rowNumber?: number) => void
  1606. /**
  1607. * Get column
  1608. */
  1609. getColumn: (colIndex: number) => TableColumn
  1610. /**
  1611. * Add a new column, including column defn and values
  1612. * inserts at colNumber or adds to the right
  1613. */
  1614. addColumn: (column: TableColumnProperties, values: any[], colIndex: number) => void
  1615. /**
  1616. * Remove a column with data
  1617. */
  1618. removeColumns: (colIndex: number, count: number) => void
  1619. }
  1620. export namespace config {
  1621. function setValue(key: 'promise', promise: any): void;
  1622. }
  1623. export namespace stream {
  1624. namespace xlsx {
  1625. interface WorkbookWriterOptions {
  1626. /**
  1627. * Specifies a writable stream to write the XLSX workbook to.
  1628. */
  1629. stream: import('stream').Stream;
  1630. /**
  1631. * If stream not specified, this field specifies the path to a file to write the XLSX workbook to.
  1632. */
  1633. filename: string;
  1634. /**
  1635. * Specifies whether to use shared strings in the workbook. Default is false
  1636. */
  1637. useSharedStrings: boolean;
  1638. /**
  1639. * Specifies whether to add style information to the workbook.
  1640. * Styles can add some performance overhead. Default is false
  1641. */
  1642. useStyles: boolean;
  1643. }
  1644. interface ArchiverZipOptions {
  1645. comment: string;
  1646. forceLocalTime: boolean;
  1647. forceZip64: boolean;
  1648. store: boolean;
  1649. zlib: Partial<ZlibOptions>;
  1650. }
  1651. interface ZlibOptions {
  1652. /**
  1653. * @default constants.Z_NO_FLUSH
  1654. */
  1655. flush: number;
  1656. /**
  1657. * @default constants.Z_FINISH
  1658. */
  1659. finishFlush: number;
  1660. /**
  1661. * @default 16*1024
  1662. */
  1663. chunkSize: number;
  1664. windowBits: number;
  1665. level: number; // compression only
  1666. memLevel: number; // compression only
  1667. strategy: number; // compression only
  1668. dictionary: Buffer | NodeJS.TypedArray | DataView | ArrayBuffer; // deflate/inflate only, empty dictionary by default
  1669. }
  1670. interface WorkbookStreamWriterOptions extends WorkbookWriterOptions {
  1671. /**
  1672. * Specifies whether to add style information to the workbook.
  1673. * Styles can add some performance overhead. Default is false
  1674. */
  1675. zip: Partial<ArchiverZipOptions>;
  1676. }
  1677. class WorkbookWriter extends Workbook {
  1678. constructor(options: Partial<WorkbookStreamWriterOptions>);
  1679. // commit all worksheets, then add suplimentary files
  1680. commit(): Promise<void>;
  1681. addStyles(): Promise<void>;
  1682. addThemes(): Promise<void>;
  1683. addOfficeRels(): Promise<void>;
  1684. addContentTypes(): Promise<void>;
  1685. addApp(): Promise<void>;
  1686. addCore(): Promise<void>;
  1687. addSharedStrings(): Promise<void>;
  1688. addWorkbookRels(): Promise<void>;
  1689. addWorkbook(): Promise<void>;
  1690. }
  1691. interface WorkbookStreamReaderOptions {
  1692. /**
  1693. * @default 'emit'
  1694. */
  1695. worksheets?: 'emit' | 'ignore';
  1696. /**
  1697. * @default 'cache'
  1698. */
  1699. sharedStrings?: 'cache' | 'emit' | 'ignore';
  1700. /**
  1701. * @default 'ignore'
  1702. */
  1703. hyperlinks?: 'cache' | 'emit' | 'ignore';
  1704. /**
  1705. * @default 'ignore'
  1706. */
  1707. styles?: 'cache' | 'ignore';
  1708. /**
  1709. * @default 'ignore'
  1710. */
  1711. entries?: 'emit' | 'ignore';
  1712. }
  1713. class WorkbookReader extends Workbook {
  1714. constructor(input: string | import('stream').Stream, options: Partial<WorkbookStreamReaderOptions>);
  1715. read(): Promise<void>;
  1716. [Symbol.asyncIterator](): AsyncGenerator<WorksheetReader>;
  1717. parse(): AsyncIterator<any>;
  1718. }
  1719. interface WorksheetReaderOptions {
  1720. workbook: Workbook;
  1721. id: number;
  1722. entry: import('stream').Stream;
  1723. options: WorkbookStreamReaderOptions;
  1724. }
  1725. class WorksheetReader {
  1726. constructor(options: WorksheetReaderOptions);
  1727. read(): Promise<void>;
  1728. [Symbol.asyncIterator](): AsyncGenerator<Row>;
  1729. parse(): AsyncIterator<Array<any>>;
  1730. dimensions(): number;
  1731. columns(): number;
  1732. getColumn(c: number): Column;
  1733. }
  1734. }
  1735. }