zhao
2021-06-11 98186752629a7bd38965418af84db382d90b9c07
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
using System;
using System.Collections;
using System.Text;
 
namespace HH.WMS.Utils.NPOI.SS.Util
{
    using HH.WMS.Utils.NPOI.Util;
 
    using HH.WMS.Utils.NPOI.HSSF.Record;
 
    public class CellRangeAddressList
    {
        /**
 * List of <c>CellRangeAddress</c>es. Each structure represents a cell range
 */
        private ArrayList _list;
 
        public CellRangeAddressList()
        {
            _list = new ArrayList();
        }
        /**
         * Convenience constructor for creating a <c>CellRangeAddressList</c> with a single 
         * <c>CellRangeAddress</c>.  Other <c>CellRangeAddress</c>es may be Added later.
         */
        public CellRangeAddressList(int firstRow, int lastRow, int firstCol, int lastCol)
            : this()
        {
 
            AddCellRangeAddress(firstRow, firstCol, lastRow, lastCol);
        }
 
        /**
         * @param in the RecordInputstream to read the record from
         */
        public CellRangeAddressList(RecordInputStream in1)
        {
            int nItems = in1.ReadUShort();
            _list = new ArrayList(nItems);
 
            for (int k = 0; k < nItems; k++)
            {
                _list.Add(new CellRangeAddress(in1));
            }
        }
 
        /**
         * Get the number of following ADDR structures. The number of this
         * structures is automatically set when reading an Excel file and/or
         * increased when you manually Add a new ADDR structure . This is the reason
         * there isn't a set method for this field .
         * 
         * @return number of ADDR structures
         */
        public int CountRanges()
        {
            return _list.Count;
        }
 
        /**
         * Add a cell range structure.
         * 
         * @param firstRow - the upper left hand corner's row
         * @param firstCol - the upper left hand corner's col
         * @param lastRow - the lower right hand corner's row
         * @param lastCol - the lower right hand corner's col
         * @return the index of this ADDR structure
         */
        public void AddCellRangeAddress(int firstRow, int firstCol, int lastRow, int lastCol)
        {
            CellRangeAddress region = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol);
            AddCellRangeAddress(region);
        }
        public void AddCellRangeAddress(CellRangeAddress cra)
        {
            _list.Add(cra);
        }
        public CellRangeAddress Remove(int rangeIndex)
        {
            if (_list.Count == 0)
            {
                throw new Exception("List is empty");
            }
            if (rangeIndex < 0 || rangeIndex >= _list.Count)
            {
                throw new Exception("Range index (" + rangeIndex
                        + ") is outside allowable range (0.." + (_list.Count - 1) + ")");
            }
            CellRangeAddress cra = (CellRangeAddress)_list[rangeIndex];
            _list.Remove(rangeIndex);
            return cra;
        }
 
        /**
         * @return <c>CellRangeAddress</c> at the given index
         */
        public CellRangeAddress GetCellRangeAddress(int index)
        {
            return (CellRangeAddress)_list[index];
        }
        public int Serialize(int offset, byte[] data)
        {
            int totalSize = this.Size;
            Serialize(new LittleEndianByteArrayOutputStream(data, offset, totalSize));
            return totalSize;
        }
        public void Serialize(ILittleEndianOutput out1)
        {
            int nItems = _list.Count;
            out1.WriteShort(nItems);
            for (int k = 0; k < nItems; k++)
            {
                CellRangeAddress region = (CellRangeAddress)_list[k];
                region.Serialize(out1);
            }
        }
 
        public int Size
        {
            get
            {
                return GetEncodedSize(_list.Count);
            }
        }
        /**
         * @return the total size of for the specified number of ranges,
         *  including the initial 2 byte range count
         */
        public static int GetEncodedSize(int numberOfRanges)
        {
            return 2 + CellRangeAddress.GetEncodedSize(numberOfRanges);
        }
        public CellRangeAddressList Copy()
        {
            CellRangeAddressList result = new CellRangeAddressList();
 
            int nItems = _list.Count;
            for (int k = 0; k < nItems; k++)
            {
                CellRangeAddress region = (CellRangeAddress)_list[k];
                result.AddCellRangeAddress(region.Copy());
            }
            return result;
        }
        public CellRangeAddress[] CellRangeAddresses
        {
            get
            {
                CellRangeAddress[] result =
                    (CellRangeAddress[])_list.ToArray(typeof(CellRangeAddress));
                return result;
            }
        }
    }
}