zhao
2021-07-09 0821715ebc11d3934d0594a1cc2c39686d808906
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
/* ====================================================================
   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.Generic;
    using System.Collections;
 
    /// <summary>
    /// Used to specify the different possible policies
    /// if for the case of null and blank cells
    /// </summary>    
    public class MissingCellPolicy
    {
        private static int NEXT_ID = 1;
        public int id;
        public MissingCellPolicy()
        {
            this.id = NEXT_ID++;
        }
        /// <summary>Missing cells are returned as null, Blank cells are returned as normal</summary>
        public static MissingCellPolicy RETURN_NULL_AND_BLANK = new MissingCellPolicy();
        /// <summary>Missing cells are returned as null, as are blank cells</summary>
        public static MissingCellPolicy RETURN_BLANK_AS_NULL = new MissingCellPolicy();
        /// <summary>A new, blank cell is Created for missing cells. Blank cells are returned as normal</summary>
        public static MissingCellPolicy CREATE_NULL_AS_BLANK = new MissingCellPolicy();
    }
 
    /// <summary>
    /// High level representation of a row of a spreadsheet.
    /// </summary>    
    public interface IRow
    {
        /// <summary>
        /// Use this to create new cells within the row and return it.
        /// 
        /// The cell that is returned is a <see cref="ICell"/>/<see cref="CellType.BLANK"/>.
        /// The type can be changed either through calling <c>SetCellValue</c> or <c>SetCellType</c>.
        /// </summary>
        /// <param name="column">the column number this cell represents</param>
        /// <returns>Cell a high level representation of the created cell.</returns>
        /// <throws>
        /// ArgumentException if columnIndex &lt; 0 or greater than the maximum number of supported columns
        /// (255 for *.xls, 1048576 for *.xlsx)
        /// </throws>
        ICell CreateCell(int column);
 
        /// <summary>
        /// Use this to create new cells within the row and return it.
        /// 
        /// The cell that is returned is a <see cref="ICell"/>/<see cref="CellType.BLANK"/>. The type can be changed
        /// either through calling <code>SetCellValue</code> or <code>SetCellType</code>.
        /// </summary>
        /// <param name="column">the column number this cell represents</param>
        /// <param name="type"></param>
        /// <returns>Cell a high level representation of the created cell.</returns>
        /// <throws>ArgumentException if columnIndex &lt; 0 or greater than the maximum number of supported columns
        /// (255 for *.xls, 1048576 for *.xlsx)
        /// </throws>
        ICell CreateCell(int column, HH.WMS.Utils.NPOI.SS.UserModel.CellType type);
 
        /// <summary>
        /// Remove the Cell from this row.
        /// </summary>
        /// <param name="cell">the cell to remove</param>
        void RemoveCell(ICell cell);
 
        /// <summary>
        /// Get row number this row represents
        /// </summary>        
        /// <returns>the row number (0 based)</returns>
        int RowNum { get; set; }
 
        /// <summary>
        /// Get the cell representing a given column (logical cell) 0-based.  If you
        /// ask for a cell that is not defined....you get a null.
        /// </summary>
        /// <param name="cellnum">0 based column number</param>
        /// <returns>Cell representing that column or null if undefined.</returns>
        /// <see cref="GetCell(int, HH.WMS.Utils.NPOI.SS.UserModel.MissingCellPolicy)"/>
        ICell GetCell(int cellnum);
 
        /// <summary>
        /// Returns the cell at the given (0 based) index, with the specified {@link HH.WMS.Utils.NPOI.SS.usermodel.Row.MissingCellPolicy}
        /// </summary>
        /// <returns>the cell at the given (0 based) index</returns>
        /// <throws>ArgumentException if cellnum &lt; 0 or the specified MissingCellPolicy is invalid</throws>
        /// <see cref="MissingCellPolicy.RETURN_NULL_AND_BLANK"/>
        /// <see cref="MissingCellPolicy.RETURN_BLANK_AS_NULL"/>
        /// <see cref="MissingCellPolicy.CREATE_NULL_AS_BLANK"/>
        ICell GetCell(int cellnum, MissingCellPolicy policy);
 
        /// <summary>
        /// Get the number of the first cell Contained in this row.
        /// </summary>
        /// <returns>
        /// short representing the first logical cell in the row,
        /// or -1 if the row does not contain any cells.
        /// </returns>
        short FirstCellNum { get; }
 
        /// <summary>
        /// Gets the index of the last cell Contained in this row <b>PLUS ONE</b>. The result also
        /// happens to be the 1-based column number of the last cell.  This value can be used as a
        /// standard upper bound when iterating over cells:
        /// <pre>
        /// short minColIx = row.GetFirstCellNum();
        /// short maxColIx = row.GetLastCellNum();
        /// for(short colIx=minColIx; colIx&lt;maxColIx; colIx++) {
        /// Cell cell = row.GetCell(colIx);
        /// if(cell == null) {
        /// continue;
        /// }
        /// //... do something with cell
        /// }
        /// </pre>
        /// </summary>
        /// <returns>
        /// short representing the last logical cell in the row <b>PLUS ONE</b>,
        /// or -1 if the row does not contain any cells.
        /// </returns>
        short LastCellNum { get; }
 
        /// <summary>
        /// Gets the number of defined cells (NOT number of cells in the actual row!).
        /// That is to say if only columns 0,4,5 have values then there would be 3.
        /// </summary>
        /// <returns>int representing the number of defined cells in the row.</returns>
        int PhysicalNumberOfCells { get; }
 
        /// <summary>
        /// Get whether or not to display this row with 0 height
        /// </summary>
        /// <returns>zHeight height is zero or not.</returns>
        bool ZeroHeight { get; set; }
 
        /// <summary>
        /// Get the row's height measured in twips (1/20th of a point). 
        /// If the height is not set, the default worksheet value is returned,
        /// <see cref="ISheet.DefaultRowHeightInPoints"/>
        /// </summary>
        /// <returns>row height measured in twips (1/20th of a point)</returns>
        short Height { get; set; }
 
        /// <summary>
        /// Returns row height measured in point size. 
        /// If the height is not set, the default worksheet value is returned,
        /// <see cref="ISheet.DefaultRowHeightInPoints"/>
        /// </summary>
        /// <returns>row height measured in point size
        /// <see cref="ISheet.DefaultRowHeightInPoints"/>
        /// </returns>
        float HeightInPoints { get; set; }
        /// <summary>
        /// Is this row formatted? Most aren't, but some rows
        /// do have whole-row styles. For those that do, you
        /// can get the formatting from <see cref="RowStyle"/>
        /// </summary>
        bool IsFormatted { get; }
        /// <summary>
        /// Cell iterator of the physically defined cells.  Note element 4 may
        /// actually be row cell depending on how many are defined!
        /// </summary>
        IEnumerator GetEnumerator();
 
        /// <summary>
        /// Returns the Sheet this row belongs to
        /// </summary>
        /// <returns>the Sheet that owns this row</returns>
        ISheet Sheet { get; }
 
        /// <summary>
        /// Returns the whole-row cell styles. Most rows won't
        /// have one of these, so will return null. Call IsFormmated to check first
        /// </summary>
        /// <value>The row style.</value>
        ICellStyle RowStyle { get; set; }
 
        /// <summary>
        /// Moves the supplied cell to a new column, which
        /// must not already have a cell there!
        /// </summary>
        /// <param name="cell">The cell to move</param>
        /// <param name="newColumn">The new column number (0 based)</param>
        void MoveCell(ICell cell, int newColumn);
 
        /// <summary>
        /// Get cells in the row
        /// </summary>
        List<ICell> Cells { get; }
    }
}