-
Notifications
You must be signed in to change notification settings - Fork 2
/
aps-excel.d.ts
146 lines (128 loc) · 5.35 KB
/
aps-excel.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/************************************************
* *
* aps-excel v0.2.0 API *
* *
************************************************/
declare module "aps-excel" {
export var Excel: Excel;
export interface Excel {
load(path: string): Workbook;
}
export interface Workbook {
save(path: string): void;
getSheetAt(index: number): Sheet;
getSheet(name: string): Sheet;
}
export interface Sheet {
/**
* getRow returns a row object that you can read or edit
* note there is a flag for whether the row previously existed on not
* so it is safe to call getRow without first calling getRowExists
* if getRow returns you a row that doesn't exist you will need to call either:
* Row.create() or
* Sheet.createRow(####)
*/
getRow(row: number): Row;
/**
* getRowExists lets you know whether a specific row exists.
* if you call it with a row number greater than getRowCount()
* you should expect it to return false.
* if you call it with a row number less or equal to getRowCount()
* it will let you know whether that row exists.
*/
getRowExists(row: number): boolean;
/**
* getRowCount() tells you NOT how 'many' rows exist, but rather,
* what is the last row that MIGHT exist. So if getRowCount() returns 99
* it is possible that the only row existing is row 99, the first 98 may
* be blank and non-existing. This makes it excellent when reading through
* a file to know when to stop looking for more rows.
* so, you might say for row 12 to getRowCount() - read the row and see if
* is any data in that row that I care about.
*/
getRowCount(): number;
/**
* cloneRow() takes the source row and copies it to the destination row
* it does NOT insert it, it deletes whatever is currently in the destination
* row including formatting.
* So if you want to do an insert, with the current API you would have to
* - close last row to last plus 1, clone last-1 to initial last etc.., In other
* words, avoid doing an insert!
*
* LETS ASSUME YOU ARE CREATING A SPREADSHEET AS AN EXPORT ROUTINE,
* and lets assume you have the formatting in the last row
* and lets assume you want to have the same formatting for every row you add:
* One option is this:
* I am about to write to row n, SO...
* cloneRow(n,n+1) // n is blank and has the formatting I want
* put my vaues in row n
* repeat until all rows added.
*/
cloneRow(source: number, destination: number): Row;
/**
* protect() makes the cells on this sheet that have cell.setLock(true)
* not reachable, without the password. In some cases you might just use a
* known password because you are just trying to make the user's life easy,
* but you don't want them to lock it out. So for example, with our language
* exports, we make it public knowledge that the password is 'locked', that
* way they can easily remember it if they need it.
*/
protect(password: string): void;
/**
* unprotect() note that with xls/xlsx, you don't need a password to unlock/
* unprotect a sheet. This is because the file is not encrypted, it is just
* flagged for user convenience as locked.
*/
unprotect(): void;
/**
* createRow() lets you create a row that you can then edit cells on on this sheet.
*/
createRow(row: number): Row;
/**
* A shortcut function for getting the value of a cell.
*/
getCellValue(row: number, column: number): any;
/**
* setCellValue is a js wrapper we wrote for the excel access.
* A shortcut function for setting the value of a cell.
* It will create a row and column as needed.
*/
setCellValue(row: number, column: number, value: any): void;
}
export interface Row {
getCell(cell: number): Cell;
getCellExists(cell: number): boolean;
/**
* lets you know if a row exists that you used getRow() to get for example
* If you now want to EDIT it, call either
* Row.create() or
* Sheet.createRow(####)
*/
isExists(): boolean;
/**
* Creates the row that is specified by this Row instance
*/
create(): void;
createCell(cell: number): Cell;
}
export class Cell {
isExists(): boolean;
/**
* Creates the cell that is specified by this Cell instance
* note that sheet.setCellValue automatically creates the cell if needed
*/
create(): void;
getValue(): any;
/**
* The cell must exist before you setValue (Unlike the Sheet.setCellValue which will
* create the cell if it doesn't exist.)
*/
setValue(value: any): void;
/**
* set the lock flag this cell to locked or unlocked.
* Note you have to also call protect before it is locked from the UI perspective.
*/
setLock(lock?: boolean): void;
getLock(): boolean;
}
}