1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.office.excel;
22
23 import org.millscript.office.alerts.SpreadSheetAlert;
24 import org.millscript.office.spreadsheet.worksheets.WorksheetImpl;
25
26 /**
27 *
28 */
29 public class ExcelWorksheet extends WorksheetImpl {
30
31 private int firstUsedColumn;
32
33 private int firstUsedRow;
34
35 private int lastUsedColumn;
36
37 private int lastUsedRow;
38
39 /**
40 * @see org.millscript.office.spreadsheet.Worksheet#firstUsedColumn()
41 */
42 public int firstUsedColumn() {
43 return this.firstUsedColumn;
44 }
45
46 /**
47 * @see org.millscript.office.spreadsheet.Worksheet#firstUsedRow()
48 */
49 public int firstUsedRow() {
50 return this.firstUsedRow;
51 }
52
53 /**
54 * @see org.millscript.office.spreadsheet.Worksheet#lastUsedColumn()
55 */
56 public int lastUsedColumn() {
57 return this.lastUsedColumn;
58 }
59
60 /**
61 * @see org.millscript.office.spreadsheet.Worksheet#lastUsedRow()
62 */
63 public int lastUsedRow() {
64 return this.lastUsedRow;
65 }
66
67 /**
68 * @see org.millscript.office.spreadsheet.Worksheet#numberOfColumns()
69 */
70 public int numberOfColumns() {
71 return this.lastUsedColumn() - this.firstUsedColumn() + 1;
72 }
73
74 /**
75 * @see org.millscript.office.spreadsheet.Worksheet#numberOfRows()
76 */
77 public int numberOfRows() {
78 return this.lastUsedRow() - this.firstUsedRow() + 1;
79 }
80
81 /**
82 * @param index The indexToFirstUsedColumn to set.
83 */
84 public void setFirstUsedColumn( final int index ) {
85 if ( index < 1 ) {
86 throw new SpreadSheetAlert(
87 "Column index cannot be less than 1"
88 ).culprit( "index", index ).mishap();
89 } else if ( index > 0xFFFF ) {
90 throw new SpreadSheetAlert(
91 "Column index cannot be greater than 65535"
92 ).culprit( "index", index ).mishap();
93 } else if ( this.firstUsedColumn == 0 || index < this.firstUsedColumn ) {
94 this.firstUsedColumn = index;
95 }
96 }
97
98 /**
99 * @param index The firstUsedRow to set.
100 */
101 public void setFirstUsedRow( final int index ) {
102 if ( index < 1 ) {
103 throw new SpreadSheetAlert(
104 "Row index cannot be less than 1"
105 ).culprit( "index", index ).mishap();
106 } else if ( index > 0xFFFF ) {
107 throw new SpreadSheetAlert(
108 "Row index cannot be greater than 65535"
109 ).culprit( "index", index ).mishap();
110 } else if ( this.firstUsedRow == 0 || index < this.firstUsedRow ) {
111 this.firstUsedRow = index;
112 }
113 }
114
115 /**
116 * @param index The indexToLastUsedColumn to set.
117 */
118 public void setLastUsedColumn( final int index ) {
119 if ( index < 1 ) {
120 throw new SpreadSheetAlert(
121 "Column index cannot be less than 1"
122 ).culprit( "index", index ).mishap();
123 } else if ( index > 0xFFFF ) {
124 throw new SpreadSheetAlert(
125 "Column index cannot be greater than 65535"
126 ).culprit( "index", index ).mishap();
127 } else if ( this.lastUsedColumn == 0 || index > this.lastUsedColumn ) {
128 this.lastUsedColumn = index;
129 }
130 }
131
132 /**
133 * @param index The lastUsedRow to set.
134 */
135 public void setLastUsedRow( final int index ) {
136 if ( index < 1 ) {
137 throw new SpreadSheetAlert(
138 "Row index cannot be less than 1"
139 ).culprit( "index", index ).mishap();
140 } else if ( index > 0xFFFF ) {
141 throw new SpreadSheetAlert(
142 "Row index cannot be greater than 65535"
143 ).culprit( "index", index ).mishap();
144 } else if ( this.lastUsedRow == 0 || index > this.lastUsedRow ) {
145 this.lastUsedRow = index;
146 }
147 }
148
149 }