Link Here
|
18 |
package org.apache.poi.xssf.usermodel.extensions; |
18 |
package org.apache.poi.xssf.usermodel.extensions; |
19 |
|
19 |
|
20 |
import org.apache.poi.ss.usermodel.HeaderFooter; |
20 |
import org.apache.poi.ss.usermodel.HeaderFooter; |
|
|
21 |
import org.apache.poi.xssf.usermodel.XSSFSheet; |
21 |
import org.apache.poi.xssf.usermodel.helpers.HeaderFooterHelper; |
22 |
import org.apache.poi.xssf.usermodel.helpers.HeaderFooterHelper; |
22 |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; |
23 |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; |
23 |
|
24 |
|
Link Here
|
26 |
* |
27 |
* |
27 |
* For a list of all the different fields that can be |
28 |
* For a list of all the different fields that can be |
28 |
* placed into a header or footer, such as page number, |
29 |
* placed into a header or footer, such as page number, |
29 |
* bold, underline etc, see |
30 |
* bold, underline etc, see the follow formatting syntax |
30 |
* {@link org.apache.poi.hssf.usermodel.HeaderFooter}. |
31 |
* |
|
|
32 |
*<b> Header/Footer Formatting Syntax</b> |
33 |
*<p> |
34 |
* There are a number of formatting codes that can be written inline with the actual header / footer text, which |
35 |
* affect the formatting in the header or footer. |
36 |
*</p> |
37 |
* |
38 |
* This example shows the text "Center Bold Header" on the first line (center section), and the date on the second |
39 |
* line (center section). |
40 |
* &CCenter &"-,Bold"Bold &"-,Regular"Header_x000A_&D |
41 |
* |
42 |
* <b>General Rules:</b> |
43 |
* There is no required order in which these codes must appear. |
44 |
* The first occurrence of the following codes turns the formatting ON, the second occurrence turns it OFF again: |
45 |
* |
46 |
* <dl> |
47 |
* <dt> &L </dt> <dd>code for "left section" (there are three header / footer locations, "left", "center", and "right"). When |
48 |
* two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the |
49 |
* order of appearance, and placed into the left section.</dd> |
50 |
* <dt> &P </dt> <dd> code for "current page #"</dd> |
51 |
* <dt> &N </dt> <dd> code for "total pages"</dd> |
52 |
* <dt>&font size </dt> <dd> code for "text font size", where font size is a font size in points.</dd> |
53 |
* <dt> &K </dt> <dd> code for "text font color" |
54 |
* RGB Color is specified as RRGGBB |
55 |
* Theme Color is specifed as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade |
56 |
* value, NN is the tint/shade value.</dd> |
57 |
* <dt> &S </dt> <dd> code for "text strikethrough" on / off</dd> |
58 |
* <dt> &X </dt> <dd> code for "text super script" on / off</dd> |
59 |
* <dt> &Y </dt> <dd> code for "text subscript" on / off</dd> |
60 |
* <dt> &C </dt> <dd> code for "center section". When two or more occurrences of this section marker exist, the contents |
61 |
* from all markers are concatenated, in the order of appearance, and placed into the center section. |
62 |
* SpreadsheetML Reference Material - Worksheets 1966</dd> |
63 |
* <dt> &D </dt> <dd> code for "date"</dd> |
64 |
* <dt> &T </dt> <dd> code for "time"</dd> |
65 |
* <dt> &G </dt> <dd> code for "picture as background"</dd> |
66 |
* <dt> &U </dt> <dd> code for "text single underline"</dd> |
67 |
* <dt> &E </dt> <dd> code for "double underline"</dd> |
68 |
* <dt> &R </dt> <dd> code for "right section". When two or more occurrences of this section marker exist, the contents |
69 |
* from all markers are concatenated, in the order of appearance, and placed into the right section.</dd> |
70 |
* <dt> &Z </dt> <dd> code for "this workbook's file path"</dd> |
71 |
* <dt> &F </dt> <dd> code for "this workbook's file name"</dd> |
72 |
* <dt> &A </dt> <dd> code for "sheet tab name"</dd> |
73 |
* <dt> &+ </dt> <dd> code for add to page #.</dd> |
74 |
* <dt> &- </dt> <dd> code for subtract from page #.</dd> |
75 |
* <dt> &"font name,font type" - code for "text font name" and "text font type", where font name and font type |
76 |
* are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font |
77 |
* name, it means "none specified". Both of font name and font type can be localized values.</dd> |
78 |
* <dt> &"-,Bold" </dt> <dd> code for "bold font style"</dd> |
79 |
* <dt> &B </dt> <dd> also means "bold font style"</dd> |
80 |
* <dt> &"-,Regular" </dt> <dd> code for "regular font style"</dd> |
81 |
* <dt> &"-,Italic" </dt> <dd> code for "italic font style"</dd> |
82 |
* <dt> &I </dt> <dd> also means "italic font style"</dd> |
83 |
* <dt> &"-,Bold Italic" </dt> <dd> code for "bold italic font style"</dd> |
84 |
* <dt> &O </dt> <dd> code for "outline style"</dd> |
85 |
* <dt> &H </dt> <dd> code for "shadow style"</dd> |
86 |
* </dl> |
87 |
* |
88 |
* |
31 |
*/ |
89 |
*/ |
32 |
public abstract class XSSFHeaderFooter implements HeaderFooter { |
90 |
public abstract class XSSFHeaderFooter implements HeaderFooter { |
33 |
private HeaderFooterHelper helper; |
91 |
private HeaderFooterHelper helper; |
34 |
private CTHeaderFooter headerFooter; |
92 |
private CTHeaderFooter headerFooter; |
35 |
|
93 |
|
36 |
private boolean stripFields = false; |
94 |
private boolean stripFields = false; |
37 |
|
95 |
|
|
|
96 |
/** |
97 |
* Create an instance of XSSFHeaderFooter from the supplied XML bean |
98 |
* @param headerFooter |
99 |
*/ |
38 |
public XSSFHeaderFooter(CTHeaderFooter headerFooter) { |
100 |
public XSSFHeaderFooter(CTHeaderFooter headerFooter) { |
39 |
this.headerFooter = headerFooter; |
101 |
this.headerFooter = headerFooter; |
40 |
this.helper = new HeaderFooterHelper(); |
102 |
this.helper = new HeaderFooterHelper(); |
41 |
} |
103 |
} |
42 |
|
104 |
|
|
|
105 |
/** |
106 |
* Returns the underlying CTHeaderFooter xml bean |
107 |
* |
108 |
* @return the underlying CTHeaderFooter xml bean |
109 |
*/ |
43 |
public CTHeaderFooter getHeaderFooter() { |
110 |
public CTHeaderFooter getHeaderFooter() { |
44 |
return this.headerFooter; |
111 |
return this.headerFooter; |
45 |
} |
112 |
} |
46 |
|
113 |
|
|
|
114 |
/** |
115 |
* |
116 |
* @return |
117 |
*/ |
47 |
public String getValue() { |
118 |
public String getValue() { |
48 |
String value = getText(); |
119 |
String value = getText(); |
49 |
if(value == null) |
120 |
if(value == null) |
Link Here
|
69 |
public void setAreFieldsStripped(boolean stripFields) { |
140 |
public void setAreFieldsStripped(boolean stripFields) { |
70 |
this.stripFields = stripFields; |
141 |
this.stripFields = stripFields; |
71 |
} |
142 |
} |
72 |
|
143 |
|
|
|
144 |
/** |
145 |
* Removes any fields (eg macros, page markers etc) |
146 |
* from the string. |
147 |
* Normally used to make some text suitable for showing |
148 |
* to humans, and the resultant text should not normally |
149 |
* be saved back into the document! |
150 |
*/ |
73 |
public static String stripFields(String text) { |
151 |
public static String stripFields(String text) { |
74 |
return org.apache.poi.hssf.usermodel.HeaderFooter.stripFields(text); |
152 |
return org.apache.poi.hssf.usermodel.HeaderFooter.stripFields(text); |
75 |
} |
153 |
} |
Link Here
|
79 |
|
157 |
|
80 |
protected abstract void setText(String text); |
158 |
protected abstract void setText(String text); |
81 |
|
159 |
|
|
|
160 |
/** |
161 |
* get the text representing the center part of this element |
162 |
*/ |
82 |
public String getCenter() { |
163 |
public String getCenter() { |
83 |
String text = helper.getCenterSection(getText()); |
164 |
String text = helper.getCenterSection(getText()); |
84 |
if(stripFields) |
165 |
if(stripFields) |
Link Here
|
86 |
return text; |
167 |
return text; |
87 |
} |
168 |
} |
88 |
|
169 |
|
|
|
170 |
/** |
171 |
* get the text representing the left part of this element |
172 |
*/ |
89 |
public String getLeft() { |
173 |
public String getLeft() { |
90 |
String text = helper.getLeftSection(getText()); |
174 |
String text = helper.getLeftSection(getText()); |
91 |
if(stripFields) |
175 |
if(stripFields) |
Link Here
|
93 |
return text; |
177 |
return text; |
94 |
} |
178 |
} |
95 |
|
179 |
|
|
|
180 |
/** |
181 |
* get the text representing the right part of this element |
182 |
*/ |
96 |
public String getRight() { |
183 |
public String getRight() { |
97 |
String text = helper.getRightSection(getText()); |
184 |
String text = helper.getRightSection(getText()); |
98 |
if(stripFields) |
185 |
if(stripFields) |
Link Here
|
100 |
return text; |
187 |
return text; |
101 |
} |
188 |
} |
102 |
|
189 |
|
|
|
190 |
/** |
191 |
* set a centered string value for this element |
192 |
*/ |
103 |
public void setCenter(String newCenter) { |
193 |
public void setCenter(String newCenter) { |
104 |
setText(helper.setCenterSection(getText(), newCenter)); |
194 |
setText(helper.setCenterSection(getText(), newCenter)); |
105 |
} |
195 |
} |
106 |
|
196 |
|
|
|
197 |
/** |
198 |
* set a left string value for this element |
199 |
*/ |
107 |
public void setLeft(String newLeft) { |
200 |
public void setLeft(String newLeft) { |
108 |
setText(helper.setLeftSection(getText(), newLeft)); |
201 |
setText(helper.setLeftSection(getText(), newLeft)); |
109 |
} |
202 |
} |
110 |
|
203 |
|
|
|
204 |
/** |
205 |
* set a right string value for this element |
206 |
*/ |
111 |
public void setRight(String newRight) { |
207 |
public void setRight(String newRight) { |
112 |
setText(helper.setRightSection(getText(), newRight)); |
208 |
setText(helper.setRightSection(getText(), newRight)); |
113 |
} |
209 |
} |