index.d.ts 47 KB

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