1    
2    
3    /* ====================================================================
4     * The Apache Software License, Version 1.1
5     *
6     * Copyright (c) 2002 The Apache Software Foundation.  All rights
7     * reserved.
8     *
9     * Redistribution and use in source and binary forms, with or without
10    * modification, are permitted provided that the following conditions
11    * are met:
12    *
13    * 1. Redistributions of source code must retain the above copyright
14    *    notice, this list of conditions and the following disclaimer.
15    *
16    * 2. Redistributions in binary form must reproduce the above copyright
17    *    notice, this list of conditions and the following disclaimer in
18    *    the documentation and/or other materials provided with the
19    *    distribution.
20    *
21    * 3. The end-user documentation included with the redistribution,
22    *    if any, must include the following acknowledgment:
23    *       "This product includes software developed by the
24    *        Apache Software Foundation (http://www.apache.org/)."
25    *    Alternately, this acknowledgment may appear in the software itself,
26    *    if and wherever such third-party acknowledgments normally appear.
27    *
28    * 4. The names "Apache" and "Apache Software Foundation" and
29    *    "Apache POI" must not be used to endorse or promote products
30    *    derived from this software without prior written permission. For
31    *    written permission, please contact apache@apache.org.
32    *
33    * 5. Products derived from this software may not be called "Apache",
34    *    "Apache POI", nor may "Apache" appear in their name, without
35    *    prior written permission of the Apache Software Foundation.
36    *
37    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40    * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41    * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44    * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45    * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47    * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48    * SUCH DAMAGE.
49    * ====================================================================
50    *
51    * This software consists of voluntary contributions made by many
52    * individuals on behalf of the Apache Software Foundation.  For more
53    * information on the Apache Software Foundation, please see
54    * <http://www.apache.org/>.
55    */
56   
57   
58   
59   package org.apache.poi.hssf.usermodel;
60   
61   
62   
63   import org.apache.poi.hssf.record.FooterRecord;
64   
65   
66   
67   /**
68   
69    * Class to read and manipulate the footer.
70   
71    * <P>
72   
73    * The footer works by having a left, center, and right side.  The total cannot
74   
75    * be more that 255 bytes long.  One uses this class by getting the HSSFFooter
76   
77    * from HSSFSheet and then getting or setting the left, center, and right side.
78   
79    * For special things (such as page numbers and date), one can use a the methods
80   
81    * that return the characters used to represent these.  One can also change the
82   
83    * fonts by using similar methods.
84   
85    * <P>
86   
87    * @author Shawn Laubach (laubach@acm.org)
88   
89    */
90   
91   public class HSSFFooter extends Object {
92   
93   
94   
95     FooterRecord footerRecord;
96   
97     String left;
98   
99     String center;
100  
101    String right;
102  
103  
104  
105    /**
106  
107     * Constructor.  Creates a new footer interface from a footer record
108  
109     * @param footerRecord Footer record to create the footer with
110  
111     */
112  
113    protected HSSFFooter(FooterRecord footerRecord) {
114  
115      this.footerRecord = footerRecord;
116  
117      String foot = footerRecord.getFooter();
118  
119    }
120  
121  
122  
123    /**
124  
125     * Get the left side of the footer.
126  
127     * @return The string representing the left side.
128  
129     */
130  
131    public String getLeft() {
132  
133      return left;
134  
135    }
136  
137  
138  
139    /**
140  
141     * Sets the left string.
142  
143     * @newLeft The string to set as the left side.
144  
145     */
146  
147    public void setLeft(String newLeft) {
148  
149      left = newLeft;
150  
151      createFooterString();
152  
153    }
154  
155  
156  
157    /**
158  
159     * Get the center of the footer.
160  
161     * @return The string representing the center.
162  
163     */
164  
165    public String getCenter() {
166  
167      return center;
168  
169    }
170  
171  
172  
173    /**
174  
175     * Sets the center string.
176  
177     * @newLeft The string to set as the center.
178  
179     */
180  
181    public void setCenter(String newCenter) {
182  
183      center = newCenter;
184  
185      createFooterString();
186  
187    }
188  
189  
190  
191    /**
192  
193     * Get the right side of the footer.
194  
195     * @return The string representing the right side.
196  
197     */
198  
199    public String getRight() {
200  
201      return right;
202  
203    }
204  
205  
206  
207    /**
208  
209     * Sets the right string.
210  
211     * @newLeft The string to set as the right side.
212  
213     */
214  
215    public void setRight(String newRight) {
216  
217      right = newRight;
218  
219      createFooterString();
220  
221    }
222  
223  
224  
225    /**
226  
227     * Creates the complete footer string based on the left, center, and middle
228  
229     * strings.
230  
231     */
232  
233    private void createFooterString() {
234  
235      footerRecord.setFooter(
236  
237      "&C" + (center == null ? "" : center) +
238  
239      "&L" + (left == null ? "" : left) +
240  
241      "&R" + (right == null ? "" : right));
242  
243      footerRecord.setFooterLength((byte)footerRecord.getFooter().length());
244  
245    }
246  
247  
248  
249    /**
250  
251     * Returns the string that represents the change in font size.
252  
253     * @param size the new font size
254  
255     * @return The special string to represent a new font size
256  
257     */
258  
259    public static String fontSize(short size) {
260  
261      return "&" + size;
262  
263    }
264  
265  
266  
267    /**
268  
269     * Returns the string that represents the change in font.
270  
271     * @param font the new font
272  
273     * @param style the fonts style
274  
275     * @return The special string to represent a new font size
276  
277     */
278  
279    public static String font(String font, String style) {
280  
281      return "&\"" + font + "," + style + "\"";
282  
283    }
284  
285  
286  
287    /**
288  
289     * Returns the string representing the current page number
290  
291     * @return The special string for page number
292  
293     */
294  
295    public static String page() {
296  
297      return "&P";
298  
299    }
300  
301  
302  
303    /**
304  
305     * Returns the string representing the number of pages.
306  
307     * @return The special string for the number of pages
308  
309     */
310  
311    public static String numPages() {
312  
313      return "&N";
314  
315    }
316  
317  
318  
319    /**
320  
321     * Returns the string representing the current date
322  
323     * @return The special string for the date
324  
325     */
326  
327    public static String date() {
328  
329      return "&D";
330  
331    }
332  
333  
334  
335    /**
336  
337     * Returns the string representing the current time
338  
339     * @return The special string for the time
340  
341     */
342  
343    public static String time() {
344  
345      return "&T";
346  
347    }
348  
349  
350  
351    /**
352  
353     * Returns the string representing the current file name
354  
355     * @return The special string for the file name
356  
357     */
358  
359    public static String file() {
360  
361      return "&F";
362  
363    }
364  
365  
366  
367    /**
368  
369     * Returns the string representing the current tab (sheet) name
370  
371     * @return The special string for tab name
372  
373     */
374  
375    public static String tab() {
376  
377      return "&A";
378  
379    }
380  
381  }
382  
383  
384  
385  ??????????????HSSFFooter?????????????????????????????????Object???FooterRecord????????????????footerRecord??????????left??????????center??????????right????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????HSSFFooter????????????????????????FooterRecord?????????????????????????footerRecord???????????????????footerRecord????????????????????????????????getFooter??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????getLeft????????????left???????????????????????????????????????????????????????????????????????????????????????????????????????????setLeft?????left????????????newLeft?????createFooterString????????????????????????????????????????????????????????????????????????????????????????????????????????????????????getCenter????????????center??????????????????????????????????????????????????????????????????????????????????????????????????????????setCenter?????center??????????????newCenter?????createFooterString????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????getRight????????????right?????????????????????????????????????????????????????????????????????????????????????????????????????????????setRight?????right?????????????newRight?????createFooterString???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????createFooterString?????footerRecord??????????????????setFooter?????????????center???????????????????????????????????center?????????????left?????????????????????????????????left?????????????right??????????????????????????????????right?????footerRecord??????????????????setFooterLength????????????????????????????????????????footerRecord?????????????????????????????????????????????????????getFooter?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????fontSize??????????????????size??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????font????????????????????font?????????????????????????????????style????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????page?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????numPages??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????date??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????time????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????file??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????tab