1
106
107
108
109 package org.apache.poi.hssf.usermodel;
110
111
112
113 import org.apache.poi.hssf.record.HeaderRecord;
114
115
116
117 /**
118
119 * Class to read and manipulate the header.
120
121 * <P>
122
123 * The header works by having a left, center, and right side. The total cannot
124
125 * be more that 255 bytes long. One uses this class by getting the HSSFHeader
126
127 * from HSSFSheet and then getting or setting the left, center, and right side.
128
129 * For special things (such as page numbers and date), one can use a the methods
130
131 * that return the characters used to represent these. One can also change the
132
133 * fonts by using similar methods.
134
135 * <P>
136
137 * @author Shawn Laubach (laubach@acm.org)
138
139 */
140
141 public class HSSFHeader extends Object {
142
143
144
145 HeaderRecord headerRecord;
146
147 String left;
148
149 String center;
150
151 String right;
152
153
154
155 /**
156
157 * Constructor. Creates a new header interface from a header record
158
159 * @param headerRecord Header record to create the header with
160
161 */
162
163 protected HSSFHeader(HeaderRecord headerRecord) {
164
165 this.headerRecord = headerRecord;
166
167 String head = headerRecord.getHeader();
168
169 }
170
171
172
173 /**
174
175 * Get the left side of the header.
176
177 * @return The string representing the left side.
178
179 */
180
181 public String getLeft() {
182
183 return left;
184
185 }
186
187
188
189 /**
190
191 * Sets the left string.
192
193 * @newLeft The string to set as the left side.
194
195 */
196
197 public void setLeft(String newLeft) {
198
199 left = newLeft;
200
201 createHeaderString();
202
203 }
204
205
206
207 /**
208
209 * Get the center of the header.
210
211 * @return The string representing the center.
212
213 */
214
215 public String getCenter() {
216
217 return center;
218
219 }
220
221
222
223 /**
224
225 * Sets the center string.
226
227 * @newLeft The string to set as the center.
228
229 */
230
231 public void setCenter(String newCenter) {
232
233 center = newCenter;
234
235 createHeaderString();
236
237 }
238
239
240
241 /**
242
243 * Get the right side of the header.
244
245 * @return The string representing the right side.
246
247 */
248
249 public String getRight() {
250
251 return right;
252
253 }
254
255
256
257 /**
258
259 * Sets the right string.
260
261 * @newLeft The string to set as the right side.
262
263 */
264
265 public void setRight(String newRight) {
266
267 right = newRight;
268
269 createHeaderString();
270
271 }
272
273
274
275 /**
276
277 * Creates the complete header string based on the left, center, and middle
278
279 * strings.
280
281 */
282
283 private void createHeaderString() {
284
285 headerRecord.setHeader(
286
287 "&C" + (center == null ? "" : center) +
288
289 "&L" + (left == null ? "" : left) +
290
291 "&R" + (right == null ? "" : right));
292
293 headerRecord.setHeaderLength((byte)headerRecord.getHeader().length());
294
295 }
296
297
298
299 /**
300
301 * Returns the string that represents the change in font size.
302
303 * @param size the new font size
304
305 * @return The special string to represent a new font size
306
307 */
308
309 public static String fontSize(short size) {
310
311 return "&" + size;
312
313 }
314
315
316
317 /**
318
319 * Returns the string that represents the change in font.
320
321 * @param font the new font
322
323 * @param style the fonts style
324
325 * @return The special string to represent a new font size
326
327 */
328
329 public static String font(String font, String style) {
330
331 return "&\"" + font + "," + style + "\"";
332
333 }
334
335
336
337 /**
338
339 * Returns the string representing the current page number
340
341 * @return The special string for page number
342
343 */
344
345 public static String page() {
346
347 return "&P";
348
349 }
350
351
352
353 /**
354
355 * Returns the string representing the number of pages.
356
357 * @return The special string for the number of pages
358
359 */
360
361 public static String numPages() {
362
363 return "&N";
364
365 }
366
367
368
369 /**
370
371 * Returns the string representing the current date
372
373 * @return The special string for the date
374
375 */
376
377 public static String date() {
378
379 return "&D";
380
381 }
382
383
384
385 /**
386
387 * Returns the string representing the current time
388
389 * @return The special string for the time
390
391 */
392
393 public static String time() {
394
395 return "&T";
396
397 }
398
399
400
401 /**
402
403 * Returns the string representing the current file name
404
405 * @return The special string for the file name
406
407 */
408
409 public static String file() {
410
411 return "&F";
412
413 }
414
415
416
417 /**
418
419 * Returns the string representing the current tab (sheet) name
420
421 * @return The special string for tab name
422
423 */
424
425 public static String tab() {
426
427 return "&A";
428
429 }
430
431 }
432
433
434
435 ???????????????HSSFHeader?????????????????????????????????Object???HeaderRecord????????????????headerRecord??????????left??????????center??????????right????????????????HSSFHeader????????????????????????HeaderRecord?????????????????????????headerRecord???????????????????headerRecord????????????????????????????????getHeader????????????????????getLeft????????????left??????????????????setLeft?????left????????????newLeft?????createHeaderString????????????????????getCenter????????????center??????????????????setCenter?????center??????????????newCenter?????createHeaderString????????????????????getRight????????????right??????????????????setRight?????right?????????????newRight?????createHeaderString???????????????????createHeaderString?????headerRecord??????????????????setHeader?????????????center???????????????????????????????????center?????????????left?????????????????????????????????left?????????????right??????????????????????????????????right?????headerRecord??????????????????setHeaderLength????????????????????????????????????????headerRecord?????????????????????????????????????????????????????getHeader???????????????????????????fontSize??????????????????size???????????????????????????font????????????????????font?????????????????????????????????style???????????????????????????page???????????????????????????numPages???????????????????????????date???????????????????????????time???????????????????????????file???????????????????????????tab