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
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
/* ====================================================================
   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.HSSF.UserModel
{
    using System;
    using System.IO;
    using System.Collections;
    using System.Collections.Generic;
 
    using HH.WMS.Utils.NPOI.HSSF.Record;
    using HH.WMS.Utils.NPOI.HSSF.Model;
    using HH.WMS.Utils.NPOI.Util;
    using HH.WMS.Utils.NPOI.SS.UserModel;
    using HH.WMS.Utils.NPOI.SS;
 
    /// <summary>
    /// High level representation of a row of a spReadsheet.
    /// Only rows that have cells should be Added to a Sheet.
    /// @author Andrew C. Oliver (acoliver at apache dot org)
    /// @author Glen Stampoultzis (glens at apache.org)
    /// </summary>
    [Serializable]
    public class HSSFRow : IComparable,IRow
    {
 
 
        /// <summary>
        /// used for collections
        /// </summary>
        public const int INITIAL_CAPACITY = 5;
 
        private int rowNum;
        private SortedDictionary<int, ICell> cells = new SortedDictionary<int, ICell>();
         
        /**
         * reference to low level representation
         */
 
        [NonSerialized]
        private RowRecord row;
 
        /**
         * reference to containing low level Workbook
         */
 
        private HSSFWorkbook book;
 
        /**
         * reference to containing Sheet
         */
 
        private HSSFSheet sheet;
 
        // TODO - ditch this constructor
        [Obsolete]
        public HSSFRow()
        {
        }
 
        /// <summary>
        /// Creates new HSSFRow from scratch. Only HSSFSheet should do this.
        /// </summary>
        /// <param name="book">low-level Workbook object containing the sheet that Contains this row</param>
        /// <param name="sheet">low-level Sheet object that Contains this Row</param>
        /// <param name="rowNum">the row number of this row (0 based)</param>
        ///<see cref="HH.WMS.Utils.NPOI.HSSF.UserModel.HSSFSheet.CreateRow(int)"/>
        public HSSFRow(HSSFWorkbook book, HSSFSheet sheet, int rowNum):this(book, sheet, new RowRecord(rowNum))
        {
 
        }
 
        /// <summary>
        /// Creates an HSSFRow from a low level RowRecord object.  Only HSSFSheet should do
        /// this.  HSSFSheet uses this when an existing file is Read in.
        /// </summary>
        /// <param name="book">low-level Workbook object containing the sheet that Contains this row</param>
        /// <param name="sheet"> low-level Sheet object that Contains this Row</param>
        /// <param name="record">the low level api object this row should represent</param>
        ///<see cref="HH.WMS.Utils.NPOI.HSSF.UserModel.HSSFSheet.CreateRow(int)"/>
        public HSSFRow(HSSFWorkbook book, HSSFSheet sheet, RowRecord record)
        {
            this.book = book;
            this.sheet = sheet;
            row = record;
 
            RowNum=(record.RowNumber);
             // Don't trust colIx boundaries as read by other apps
            // set the RowRecord empty for the moment
            record.SetEmpty();
            
 
        }
        /// <summary>
        /// Use this to create new cells within the row and return it.
        /// The cell that is returned is a CELL_TYPE_BLANK (<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>a high level representation of the created cell.</returns>
        public ICell CreateCell(int column)
        {
            return this.CreateCell(column, CellType.BLANK);
        }
 
        /// <summary>
        /// Use this to create new cells within the row and return it.
        /// The cell that is returned is a CELL_TYPE_BLANK. The type can be changed
        /// either through calling setCellValue or setCellType.
        /// </summary>
        /// <param name="columnIndex">the column number this cell represents</param>
        /// <param name="type">a high level representation of the created cell.</param>
        /// <returns></returns>
        public ICell CreateCell(int columnIndex, CellType type)
        {
            short shortCellNum = (short)columnIndex;
            if (columnIndex > 0x7FFF)
            {
                shortCellNum = (short)(0xffff - columnIndex);
            }
 
            ICell cell = new HSSFCell(book, sheet, RowNum, (short)columnIndex, type);
            AddCell(cell);
            sheet.Sheet.AddValueRecord(RowNum, ((HSSFCell)cell).CellValueRecord);
            return cell;
        }
        /// <summary>
        /// Remove the Cell from this row.
        /// </summary>
        /// <param name="cell">The cell to Remove.</param>
        public void RemoveCell(ICell cell)
        {
            if (cell == null)
            {
                throw new ArgumentException("cell must not be null");
            }
            RemoveCell((HSSFCell)cell, true);
        }
        /// <summary>
        /// Removes the cell.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <param name="alsoRemoveRecords">if set to <c>true</c> [also remove records].</param>
        private void RemoveCell(ICell cell, bool alsoRemoveRecords)
        {
 
            int column = cell.ColumnIndex;
            if (column < 0)
            {
                throw new Exception("Negative cell indexes not allowed");
            }
            //if (column >= cells.Count || cell != cells[column])
            if(!cells.ContainsKey(column)|| cell!=cells[column])
            {
                throw new Exception("Specified cell is not from this row");
            }
            if (cell.IsPartOfArrayFormulaGroup)
            {
                ((HSSFCell)cell).NotifyArrayFormulaChanging();
            }
            cells.Remove(column);
 
 
            if (alsoRemoveRecords)
            {
                CellValueRecordInterface cval = ((HSSFCell)cell).CellValueRecord;
                sheet.Sheet.RemoveValueRecord(RowNum, cval);
            }
 
            if (cell.ColumnIndex + 1 == row.LastCol)
            {
                row.LastCol = CalculateNewLastCellPlusOne(row.LastCol);
            }
            if (cell.ColumnIndex == row.FirstCol)
            {
                row.FirstCol = CalculateNewFirstCell(row.FirstCol);
            }
        }
        /**
         * used internally to refresh the "last cell plus one" when the last cell is removed.
         * @return 0 when row contains no cells
         */
        private int CalculateNewLastCellPlusOne(int lastcell)
        {
            int cellIx = lastcell - 1;
            ICell r = RetrieveCell(cellIx);
 
            while (r == null)
            {
                if (cellIx < 0)
                {
                    return 0;
                }
                r = RetrieveCell(--cellIx);
            }
            return cellIx + 1;
        }
 
        /**
         * used internally to refresh the "first cell" when the first cell is removed.
         * @return 0 when row contains no cells (also when first cell is occupied)
         */
        private int CalculateNewFirstCell(int firstcell)
        {
            int cellIx = firstcell + 1;
            ICell r = RetrieveCell(cellIx);
 
            if (cells.Count == 0)
                return 0;
 
            while (r == null)
            {
                if (cellIx <= cells.Count)
                {
                    return 0;
                }
                r = RetrieveCell(++cellIx);
            }
            return cellIx;
        }
        /// <summary>
        /// Create a high level Cell object from an existing low level record.  Should
        /// only be called from HSSFSheet or HSSFRow itself.
        /// </summary>
        /// <param name="cell">The low level cell to Create the high level representation from</param>
        /// <returns> the low level record passed in</returns>
        public ICell CreateCellFromRecord(CellValueRecordInterface cell)
        {
            ICell hcell = new HSSFCell(book, sheet, cell);
 
            AddCell(hcell);
            int colIx = cell.Column;
            if (row.IsEmpty)
            {
                row.FirstCol=(colIx);
                row.LastCol=(colIx + 1);
            }
            else
            {
                if (colIx < row.FirstCol)
                {
                    row.FirstCol = (colIx);
                }
                else if (colIx > row.LastCol)
                {
                    row.LastCol = (colIx + 1);
                }
                else
                {
                    // added cell is within first and last cells
                }
            }
            // TODO - RowRecord column boundaries need to be updated for cell comments too
            return hcell;
        }
 
        /// <summary>
        /// true, when the row is invisible. This is the case when the height is zero.
        /// </summary>
        public bool IsHidden
        {
            get { return this.ZeroHeight; }
            set { this.ZeroHeight = value; }
        }
 
        /// <summary>
        /// Removes all the cells from the row, and their
        /// records too.
        /// </summary>
        public void RemoveAllCells()
        {
            int initialLen = cells.Count;
            for (int i = 0; i < initialLen; i++)
            {
                RemoveCell(cells[i], true);
            }
            //cells = new HSSFCell[INITIAL_CAPACITY];
        }
 
        /// <summary>
        /// Get row number this row represents
        /// </summary>
        /// <value>the row number (0 based)</value>
        public int RowNum
        {
            get
            {
                return rowNum;
            }
            set
            {
                int maxrow = SpreadsheetVersion.EXCEL97.LastRowIndex;
                if ((value < 0) || (value > maxrow))
                {
                    throw new ArgumentException("Invalid row number (" + value
                            + ") outside allowable range (0.." + maxrow + ")");
                }
                this.rowNum = value;
                if (row != null)
                {
                    row.RowNumber = (value);   // used only for KEY comparison (HSSFRow)
                }
            }
        }
 
        /// <summary>
        /// Returns the rows outline level. Increased as you
        /// put it into more Groups (outlines), reduced as
        /// you take it out of them.
        /// </summary>
        /// <value>The outline level.</value>
        public int OutlineLevel
        {
            get { return row.OutlineLevel; }
        }
 
        /// <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>
        public void MoveCell(ICell cell, int newColumn)
        {
            // Ensure the destination is free
            //if (cells.Count > newColumn && cells[newColumn] != null)
            if(cells.ContainsKey(newColumn))
            {
                throw new ArgumentException("Asked to move cell to column " + newColumn + " but there's already a cell there");
            }
 
            // Check it's one of ours
            bool existflag = false;
            foreach (ICell cellinrow in cells.Values)
            {
                if (cellinrow.Equals(cell))
                {
                    existflag = true;
                    break;
                }
            }
            if (!existflag)
            {
                throw new ArgumentException("Asked to move a cell, but it didn't belong to our row");
            }
 
            // Move the cell to the new position
            // (Don't Remove the records though)
            RemoveCell(cell, false);
            ((HSSFCell)cell).UpdateCellNum(newColumn);
            AddCell(cell);
        }
        /**
 * Returns the HSSFSheet this row belongs to
 *
 * @return the HSSFSheet that owns this row
 */
        public ISheet Sheet
        {
            get
            {
                return sheet;
            }
        }
        /// <summary>
        /// used internally to Add a cell.
        /// </summary>
        /// <param name="cell">The cell.</param>
        private void AddCell(ICell cell)
        {
 
            int column = cell.ColumnIndex;
            // re-allocate cells array as required.
            //if (column >= cells.Count)
            //{
            //    HSSFCell[] oldCells = cells;
            //    int newSize = oldCells.Length * 2;
            //    if (newSize < column + 1)
            //    {
            //        newSize = column + 1;
            //    }
            //    cells = new HSSFCell[newSize];
            //    Array.Copy(oldCells, 0, cells, 0, oldCells.Length);
            //}
            if (cells.ContainsKey(column))
            {
                cells.Remove(column);
            }
            cells.Add(column, cell);
            
            // fix up firstCol and lastCol indexes
            if (row.IsEmpty|| column < row.FirstCol)
            {
                row.FirstCol=(column);
            }
 
            if (row.IsEmpty || column >= row.LastCol)
            {
                row.LastCol=((short)(column + 1)); // +1 -> for one past the last index 
            }
        }
 
        /// <summary>
        /// Get the hssfcell representing a given column (logical cell)
        /// 0-based. If you ask for a cell that is not defined, then
        /// you Get a null.
        /// This is the basic call, with no policies applied
        /// </summary>
        /// <param name="cellnum">0 based column number</param>
        /// <returns>Cell representing that column or null if Undefined.</returns>
        private ICell RetrieveCell(int cellnum)
        {
            if (!cells.ContainsKey(cellnum))
                return null;
            //if (cellnum < 0 || cellnum >= cells.Count) return null;
            return cells[cellnum];
        }
 
        /// <summary>
        /// Get the hssfcell representing a given column (logical cell)
        /// 0-based.  If you ask for a cell that is not defined then
        /// you get a null, unless you have set a different
        /// MissingCellPolicy on the base workbook.
        /// 
        /// Short method signature provided to retain binary
        /// compatibility.
        /// </summary>
        /// <param name="cellnum">0 based column number</param>
        /// <returns>Cell representing that column or null if undefined.</returns>
        [Obsolete]
        public ICell GetCell(short cellnum)
        {
            int ushortCellNum = cellnum & 0x0000FFFF; // avoid sign extension
            return GetCell(ushortCellNum);
        }
 
        /// <summary>
        /// Get the hssfcell representing a given column (logical cell)
        /// 0-based.  If you ask for a cell that is not defined then
        /// you get a null, unless you have set a different
        /// MissingCellPolicy on the base workbook.
        /// </summary>
        /// <param name="cellnum">0 based column number</param>
        /// <returns>Cell representing that column or null if undefined.</returns>
        public ICell GetCell(int cellnum)
        {
            return GetCell(cellnum, book.MissingCellPolicy);
        }
 
        /// <summary>
        /// Get the hssfcell representing a given column (logical cell)
        /// 0-based.  If you ask for a cell that is not defined, then
        /// your supplied policy says what to do
        /// </summary>
        /// <param name="cellnum">0 based column number</param>
        /// <param name="policy">Policy on blank / missing cells</param>
        /// <returns>that column or null if Undefined + policy allows.</returns>
        public ICell GetCell(int cellnum, MissingCellPolicy policy)
        {
            ICell cell = RetrieveCell(cellnum);
            if (policy == MissingCellPolicy.RETURN_NULL_AND_BLANK)
            {
                return cell;
            }
            if (policy == MissingCellPolicy.RETURN_BLANK_AS_NULL)
            {
                if (cell == null) return cell;
                if (cell.CellType == CellType.BLANK)
                {
                    return null;
                }
                return cell;
            }
            if (policy == MissingCellPolicy.CREATE_NULL_AS_BLANK)
            {
                if (cell == null)
                {
                    return CreateCell(cellnum, CellType.BLANK);
                }
                return cell;
            }
            throw new ArgumentException("Illegal policy " + policy + " (" + policy.id + ")");
        }
 
        /// <summary>
        /// Get the number of the first cell contained in this row.
        /// </summary>
        /// <value>the first logical cell in the row, or -1 if the row does not contain any cells.</value>
        public short FirstCellNum
        {
            get
            {
                if (row.IsEmpty)
                    return -1;
                else
                    return (short)row.FirstCol;
            }
        }
 
        /// <summary>
        /// Gets the index of the last cell contained in this row PLUS ONE
        /// . 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:
        /// </summary>
        /// <value>
        /// short representing the last logical cell in the row PLUS ONE, or -1 if the
        /// row does not contain any cells.
        ///</value>
        /// <example>
        /// 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
        /// }
        /// </example>
        public short LastCellNum
        {
            get
            {
                if (row.IsEmpty)
                {
                    return -1;
                }
                return (short)row.LastCol;
            }
        }
 
 
        /// <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>
        /// <value>the number of defined cells in the row.</value>
        public int PhysicalNumberOfCells
        {
            get
            {
                return cells.Count;
            }
        }
 
 
        /// <summary>
        /// Gets or sets  whether or not to Display this row with 0 height
        /// </summary>
        /// <value>height is zero or not.</value>
        public bool ZeroHeight
        {
            get
            {
                return row.ZeroHeight;
            }
            set 
            {
                row.ZeroHeight=(value);
            }
        }
 
        /// <summary>
        /// Get or sets the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)
        /// </summary>
        /// <value>rowheight or 0xff for Undefined (use sheet default)</value>
        public short Height
        {
            get
            {
                short height = row.Height;
 
                //The low-order 15 bits contain the row height.
                //The 0x8000 bit indicates that the row is standard height (optional)
                if ((height & 0x8000) != 0) height = sheet.Sheet.DefaultRowHeight;
                else height &= 0x7FFF;
 
                return height;
            }
            set
            {
                if (value == -1)
                {
                    row.Height = 20 * 20;
                }
                else
                {
                    row.BadFontHeight = true;
                    row.Height = value;
                }
            }
        }
        /// <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 {@link #getRowStyle()}
        /// </summary>
        /// <value>
        ///     <c>true</c> if this instance is formatted; otherwise, <c>false</c>.
        /// </value>
        public bool IsFormatted
        {
            get
            {
                return row.Formatted;
            }
        }
        /// <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>
        public ICellStyle RowStyle
        {
            get
            {
                if (!IsFormatted) { return null; }
                short styleIndex = row.XFIndex;
                ExtendedFormatRecord xf = book.Workbook.GetExFormatAt(styleIndex);
                return new HSSFCellStyle(styleIndex, xf, book);
            }
            set 
            {
                row.Formatted=(true);
                row.XFIndex=(value.Index);
            
            }
        }
        /// <summary>
        /// Get the row's height or ff (-1) for Undefined/default-height in points (20*Height)
        /// </summary>
        /// <value>row height or 0xff for Undefined (use sheet default).</value>
        public float HeightInPoints
        {
            get
            {
                return (row.Height / 20f);
            }
            set
            {
                if (value == -1)
                {
                    row.Height = 20;
                }
                else
                {
 
                    row.BadFontHeight = (true);
                    row.Height = (short)(value * 20);
                }
            }
        }
 
        /// <summary>
        /// Get the lowlevel RowRecord represented by this object - should only be called
        /// by other parts of the high level API
        /// </summary>
        /// <value>RowRecord this row represents</value>
        public RowRecord RowRecord
        {
            get
            {
                return row;
            }
        }
 
 
        /// <summary>
        /// used internally to refresh the "first cell" when the first cell is Removed.
        /// </summary>
        /// <param name="firstcell">The first cell index.</param>
        /// <returns></returns>
        [Obsolete]
        private short FindFirstCell(int firstcell)
        {
            short cellnum = (short)(firstcell + 1);
            ICell r = GetCell(cellnum);
 
            while (r == null && cellnum <= LastCellNum)
            {
                r = GetCell(++cellnum);
            }
            if (cellnum > LastCellNum)
                return -1;
            return cellnum;
        }
 
        /// <summary>
        /// Get cells in the row
        /// </summary>
        public List<ICell> Cells
        {
            get {
                return new List<ICell>(this.cells.Values);
            }
        }
 
        /// <summary>
        /// Gets the cell enumerator of the physically defined cells.
        /// </summary>
        /// <remarks>
        /// Note that the 4th element might well not be cell 4, as the iterator
        /// will not return Un-defined (null) cells.
        /// Call CellNum on the returned cells to know which cell they are.
        /// </remarks>
        public IEnumerator GetEnumerator()
        {
            //return //new CellEnumerator(this.cells);
            return this.cells.Values.GetEnumerator();
        }
        ///// <summary>
        ///// Alias for {@link CellEnumerator} to allow
        ///// foreach loops
        ///// </summary>
        ///// <returns></returns>
        //public IEnumerator GetEnumerator()
        //{
        //    return GetCellEnumerator();
        //}
 
        /*
         * An iterator over the (physical) cells in the row.
         */
        //private class CellEnumerator : IEnumerator
        //{
        //    int thisId = -1;
        //    int nextId = -1;
        //    private HSSFCell[] cells;
 
        //    public CellEnumerator()
        //    {
        //    }
 
        //    public CellEnumerator(HSSFCell[] cells)
        //    {
        //        this.cells = cells;
        //    }
 
        //    public bool MoveNext()
        //    {
                
        //        FindNext();
        //        return nextId < cells.Length;
        //    }
 
        //    public Object Current
        //    {
        //        get
        //        {
        //            thisId = nextId;
        //            Cell cell = cells[thisId];
        //            return cell;
        //        }
        //    }
 
        //    public void Remove()
        //    {
        //        if (thisId == -1)
        //            throw new InvalidOperationException("Remove() called before next()");
        //        cells[thisId] = null;
        //    }
 
        //    private void FindNext()
        //    {
        //        int i = nextId + 1;
        //        for (; i < cells.Length; i++)
        //        {
        //            if (cells[i] != null) break;
        //        }
        //        nextId = i;
        //    }
        //    public void Reset()
        //    {
        //        thisId = -1;
        //        nextId = -1;
        //    }
 
        //}
 
        /// <summary>
        /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>
        /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
        /// Value
        /// Meaning
        /// Less than zero
        /// This instance is less than <paramref name="obj"/>.
        /// Zero
        /// This instance is equal to <paramref name="obj"/>.
        /// Greater than zero
        /// This instance is greater than <paramref name="obj"/>.
        /// </returns>
        /// <exception cref="T:System.ArgumentException">
        ///     <paramref name="obj"/> is not the same type as this instance.
        /// </exception>
        public int CompareTo(Object obj)
        {
            HSSFRow loc = (HSSFRow)obj;
 
            if (this.RowNum == loc.RowNum)
            {
                return 0;
            }
            if (this.RowNum < loc.RowNum)
            {
                return -1;
            }
            if (this.RowNum > loc.RowNum)
            {
                return 1;
            }
            return -1;
        }
 
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(Object obj)
        {
            if (!(obj is HSSFRow))
            {
                return false;
            }
            HSSFRow loc = (HSSFRow)obj;
 
            if (this.RowNum == loc.RowNum)
            {
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// Returns a hash code. In this case it is the number of the row.
        /// </summary>
        public override int GetHashCode ()
        {
            return RowNum;
        }
    }
}