zhao
2021-07-07 2fdf959ac739edd6de84aa8053b8b9683dce8e8b
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for Additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */
 
namespace HH.WMS.Utils.NPOI.SS.UserModel
{
    using System;
    using System.Collections;
    using System.IO;
    using HH.WMS.Utils.NPOI.SS.Formula.Udf;
 
    public enum SheetState : int
    {
        /// <summary>
        /// Indicates the sheet is visible.
        /// </summary>
        VISIBLE = 0,
 
        /// <summary>
        /// Indicates the book window is hidden, but can be shown by the user via the user interface.
        /// </summary>
        HIDDEN = 1,
 
        /// <summary>
        /// Indicates the sheet is hidden and cannot be shown in the user interface (UI).
        /// </summary>
        /// <remarks>
        /// In Excel this state is only available programmatically in VBA:
        /// ThisWorkbook.Sheets("MySheetName").Visible = xlSheetVeryHidden
        /// 
        /// </remarks>
        VERY_HIDDEN = 2
    }
 
    /// <summary>
    /// High level interface of a Excel workbook.  This is the first object most users 
    /// will construct whether they are reading or writing a workbook.  It is also the
    /// top level object for creating new sheets/etc.
    /// This interface is shared between the implementation specific to xls and xlsx.
    /// This way it is possible to access Excel workbooks stored in both formats.
    /// </summary>
    public interface IWorkbook
    {
 
        /// <summary>
        /// get the active sheet.  The active sheet is is the sheet
        /// which is currently displayed when the workbook is viewed in Excel.
        /// </summary>
        int ActiveSheetIndex { get; }
 
        /// <summary>
        /// Gets the first tab that is displayed in the list of tabs in excel.
        /// </summary>
        int FirstVisibleTab { get; set; }
 
        /// <summary>
        /// Sets the order of appearance for a given sheet.
        /// </summary>
        /// <param name="sheetname">the name of the sheet to reorder</param>
        /// <param name="pos">the position that we want to insert the sheet into (0 based)</param>
        void SetSheetOrder(String sheetname, int pos);
 
        /// <summary>
        /// Sets the tab whose data is actually seen when the sheet is opened.
        /// This may be different from the "selected sheet" since excel seems to
        /// allow you to show the data of one sheet when another is seen "selected"
        /// in the tabs (at the bottom).
        /// </summary>
        /// <param name="index">the index of the sheet to select (0 based)</param>
        void SetSelectedTab(int index);
 
        /// <summary>
        /// set the active sheet. The active sheet is is the sheet
        /// which is currently displayed when the workbook is viewed in Excel.
        /// </summary>
        /// <param name="sheetIndex">index of the active sheet (0-based)</param>
        void SetActiveSheet(int sheetIndex);
 
        /// <summary>
        /// Set the sheet name
        /// </summary>
        /// <param name="sheet">sheet number (0 based)</param>
        /// <returns>Sheet name</returns>
        String GetSheetName(int sheet);
 
        /// <summary>
        /// Set the sheet name.
        /// </summary>
        /// <param name="sheet">sheet number (0 based)</param>
        /// <param name="name">sheet name</param>
        void SetSheetName(int sheet, String name);
   
        /// <summary>
        /// Returns the index of the sheet by its name
        /// </summary>
        /// <param name="name">the sheet name</param>
        /// <returns>index of the sheet (0 based)</returns>
        int GetSheetIndex(String name);
 
        /// <summary>
        /// Returns the index of the given sheet
        /// </summary>
        /// <param name="sheet">the sheet to look up</param>
        /// <returns>index of the sheet (0 based)</returns>
        int GetSheetIndex(ISheet sheet);
 
        /// <summary>
        /// Sreate an Sheet for this Workbook, Adds it to the sheets and returns
        /// the high level representation.  Use this to create new sheets.
        /// </summary>
        /// <returns></returns>
        ISheet CreateSheet();
 
        /// <summary>
        /// Create an Sheet for this Workbook, Adds it to the sheets and returns
        /// the high level representation.  Use this to create new sheets.
        /// </summary>
        /// <param name="sheetname">sheetname to set for the sheet.</param>
        /// <returns>Sheet representing the new sheet.</returns>
        ISheet CreateSheet(String sheetname);
 
        /// <summary>
        /// Create an Sheet from an existing sheet in the Workbook.
        /// </summary>
        /// <param name="sheetNum"></param>
        /// <returns></returns>
        ISheet CloneSheet(int sheetNum);
 
         /// <summary>
         /// Get the number of spreadsheets in the workbook
         /// </summary>
        int NumberOfSheets { get; }
 
        /// <summary>
        /// Get the Sheet object at the given index.
        /// </summary>
        /// <param name="index">index of the sheet number (0-based physical &amp; logical)</param>
        /// <returns>Sheet at the provided index</returns>
        ISheet GetSheetAt(int index);
 
        /// <summary>
        /// Get sheet with the given name
        /// </summary>
        /// <param name="name">name of the sheet</param>
        /// <returns>Sheet with the name provided or null if it does not exist</returns>
        ISheet GetSheet(String name);
 
        /// <summary>
        /// Support foreach ISheet, e.g.
        /// HSSFWorkbook workbook = new HSSFWorkbook();
        /// foreach(ISheet sheet in workbook) ...
        /// </summary>
        /// <returns>Enumeration of all the sheets of this workbook</returns>
        IEnumerator GetEnumerator();
 
        /// <summary>
        /// Removes sheet at the given index
        /// </summary>
        /// <param name="index"></param>
        void RemoveSheetAt(int index);
 
 
        /**
         * To set just repeating columns:
         *  workbook.SetRepeatingRowsAndColumns(0,0,1,-1-1);
         * To set just repeating rows:
         *  workbook.SetRepeatingRowsAndColumns(0,-1,-1,0,4);
         * To remove all repeating rows and columns for a sheet.
         *  workbook.SetRepeatingRowsAndColumns(0,-1,-1,-1,-1);
         */
        /// <summary>
        /// Sets the repeating rows and columns for a sheet (as found in
        /// File->PageSetup->Sheet).  This is function is included in the workbook
        /// because it Creates/modifies name records which are stored at the
        /// workbook level.
        /// </summary>
        /// <param name="sheetIndex">0 based index to sheet.</param>
        /// <param name="startColumn">0 based start of repeating columns.</param>
        /// <param name="endColumn">0 based end of repeating columns.</param>
        /// <param name="startRow">0 based start of repeating rows.</param>
        /// <param name="endRow">0 based end of repeating rows.</param>
        void SetRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow);
 
 
        /// <summary>
        /// Create a new Font and add it to the workbook's font table
        /// </summary>
        /// <returns></returns>
        IFont CreateFont();
 
        /// <summary>
        /// Finds a font that matches the one with the supplied attributes
        /// </summary>
        /// <param name="boldWeight"></param>
        /// <param name="color"></param>
        /// <param name="fontHeight"></param>
        /// <param name="name"></param>
        /// <param name="italic"></param>
        /// <param name="strikeout"></param>
        /// <param name="typeOffset"></param>
        /// <param name="underline"></param>
        /// <returns>the font with the matched attributes or null</returns>
        IFont FindFont(short boldWeight, short color, short fontHeight, String name, bool italic, bool strikeout, short typeOffset, byte underline);
 
        /// <summary>
        /// Get the number of fonts in the font table
        /// </summary>
        short NumberOfFonts { get; }
 
        /// <summary>
        /// Get the font at the given index number
        /// </summary>
        /// <param name="idx">index number (0-based)</param>
        /// <returns>font at the index</returns>
        IFont GetFontAt(short idx);
 
        /// <summary>
        /// Create a new Cell style and add it to the workbook's style table
        /// </summary>
        /// <returns>the new Cell Style object</returns>
        ICellStyle CreateCellStyle();
 
        /// <summary>
        /// Get the number of styles the workbook Contains
        /// </summary>
        short NumCellStyles { get; }
 
        /// <summary>
        /// Get the cell style object at the given index
        /// </summary>
        /// <param name="idx">index within the set of styles (0-based)</param>
        /// <returns>CellStyle object at the index</returns>
        ICellStyle GetCellStyleAt(short idx);
 
        /// <summary>
        /// Write out this workbook to an OutPutstream.
        /// </summary>
        /// <param name="stream">the stream you wish to write to</param>
        void Write(Stream stream);
 
        /// <summary>
        /// the total number of defined names in this workbook
        /// </summary>
        int NumberOfNames { get; }
 
        /// <summary>
        /// the defined name with the specified name.
        /// </summary>
        /// <param name="name">the name of the defined name</param>
        /// <returns>the defined name with the specified name. null if not found</returns>
        IName GetName(String name);
 
        /// <summary>
        /// the defined name at the specified index
        /// </summary>
        /// <param name="nameIndex">position of the named range (0-based)</param>
        /// <returns></returns>
        IName GetNameAt(int nameIndex);
 
        /// <summary>
        /// Creates a new (unInitialised) defined name in this workbook
        /// </summary>
        /// <returns>new defined name object</returns>
        IName CreateName();
 
        /// <summary>
        /// Gets the defined name index by name
        /// </summary>
        /// <param name="name">the name of the defined name</param>
        /// <returns>zero based index of the defined name.</returns>
        int GetNameIndex(String name);
 
        /// <summary>
        /// Remove the defined name at the specified index
        /// </summary>
        /// <param name="index">named range index (0 based)</param>
        void RemoveName(int index);
 
        /// <summary>
        /// Remove a defined name by name
        /// </summary>
        /// <param name="name">the name of the defined name</param>
        void RemoveName(String name);
 
        /// <summary>
        /// Sets the printarea for the sheet provided
        /// </summary>
        /// <param name="sheetIndex">Zero-based sheet index</param>
        /// <param name="reference">Valid name Reference for the Print Area</param>
        void SetPrintArea(int sheetIndex, String reference);
 
 
        /// <summary>
        /// Sets the printarea for the sheet provided
        /// </summary>
        /// <param name="sheetIndex">Zero-based sheet index (0 = First Sheet)</param>
        /// <param name="startColumn">Column to begin printarea</param>
        /// <param name="endColumn">Column to end the printarea</param>
        /// <param name="startRow">Row to begin the printarea</param>
        /// <param name="endRow">Row to end the printarea</param>
        void SetPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow);
 
        /// <summary>
        /// Retrieves the reference for the printarea of the specified sheet, 
        /// the sheet name is Appended to the reference even if it was not specified.
        /// </summary>
        /// <param name="sheetIndex">Zero-based sheet index</param>
        /// <returns>Null if no print area has been defined</returns>
        String GetPrintArea(int sheetIndex);
 
        /// <summary>
        /// Delete the printarea for the sheet specified
        /// </summary>
        /// <param name="sheetIndex">Zero-based sheet index (0 = First Sheet)</param>
        void RemovePrintArea(int sheetIndex);
 
        /// <summary>
        /// Retrieves the current policy on what to do when getting missing or blank cells from a row.
        /// </summary>
        MissingCellPolicy MissingCellPolicy { get; set; }
 
        /// <summary>
        /// Returns the instance of DataFormat for this workbook.
        /// </summary>
        /// <returns>the DataFormat object</returns>
        IDataFormat CreateDataFormat();
 
        /// <summary>
        /// Adds a picture to the workbook.
        /// </summary>
        /// <param name="pictureData">The bytes of the picture</param>
        /// <param name="format">The format of the picture.</param>
        /// <returns>the index to this picture (1 based).</returns>
        int AddPicture(byte[] pictureData, PictureType format);
 
        /// <summary>
        /// Gets all pictures from the Workbook.
        /// </summary>
        /// <returns>the list of pictures (a list of link PictureData objects.)</returns>
        IList GetAllPictures();
 
        /// <summary>
        /// Return an object that handles instantiating concrete classes of 
        /// the various instances one needs for  HSSF and XSSF.
        /// </summary>
        /// <returns></returns>
        ICreationHelper GetCreationHelper();
 
        /// <summary>
        /// if this workbook is not visible in the GUI
        /// </summary>
        bool IsHidden { get; set; }
 
        /// <summary>
        /// Check whether a sheet is hidden.
        /// </summary>
        /// <param name="sheetIx">number of sheet</param>
        /// <returns>true if sheet is hidden</returns>
        bool IsSheetHidden(int sheetIx);
 
        /**
         * Check whether a sheet is very hidden.
         * <p>
         * This is different from the normal hidden status
         *  ({@link #isSheetHidden(int)})
         * </p>
         * @param sheetIx sheet index to check
         * @return <code>true</code> if sheet is very hidden
         */
        bool IsSheetVeryHidden(int sheetIx);
 
        /**
         * Hide or unhide a sheet
         *
         * @param sheetIx the sheet index (0-based)
         * @param hidden True to mark the sheet as hidden, false otherwise
         */
        void SetSheetHidden(int sheetIx, SheetState hidden);
 
        /**
         * Hide or unhide a sheet.
         * <pre>
         *  0 = not hidden
         *  1 = hidden
         *  2 = very hidden.
         * </pre>
         * @param sheetIx The sheet number
         * @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
         */
        void SetSheetHidden(int sheetIx, int hidden);
 
        /// <summary>
        /// Register a new toolpack in this workbook.
        /// </summary>
        /// <param name="toopack">the toolpack to register</param>
        void AddToolPack(UDFFinder toopack);
 
    }
}