View | Details | Raw Unified | Return to bug 46120
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java (+22 lines)
Lines 21-36 Link Here
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
23
23
24
/**
25
 * 
26
 * First page footer content. Corresponds to first printed page.  
27
 * The first logical page in the sheet may not be printed, for example, if the print area is specified to 
28
 * be a range such that it falls outside the first page's scope.
29
 * 
30
 */
24
public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
31
public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
25
32
33
    /**
34
     * Create an instance of XSSFFirstFooter from the supplied XML bean
35
     * @see XSSFSheet#getFirstFooter()
36
     * @param headerFooter
37
     */
26
    protected XSSFFirstFooter(CTHeaderFooter headerFooter) {
38
    protected XSSFFirstFooter(CTHeaderFooter headerFooter) {
27
        super(headerFooter);
39
        super(headerFooter);
40
        headerFooter.setDifferentFirst(true);
28
    }
41
    }
29
    
42
    
43
    /**
44
     * Get the content text representing the footer
45
     * @return text
46
     */
30
    public String getText() {
47
    public String getText() {
31
        return getHeaderFooter().getFirstFooter();
48
        return getHeaderFooter().getFirstFooter();
32
    }
49
    }
33
    
50
    
51
    /**
52
     * Set a text for the footer. If null unset the value.
53
     * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax
54
     * @param text - a string representing the footer. 
55
     */
34
    public void setText(String text) {
56
    public void setText(String text) {
35
    	if(text == null) {
57
    	if(text == null) {
36
    		getHeaderFooter().unsetFirstFooter();
58
    		getHeaderFooter().unsetFirstFooter();
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.java (-4 / +100 lines)
Lines 18-23 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
Lines 26-49 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)
Lines 69-75 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
	}
Lines 79-84 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)
Lines 86-91 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)
Lines 93-98 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)
Lines 100-113 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
    }
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvenFooter.java (-1 / +24 lines)
Lines 21-36 Link Here
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
23
23
24
/**
25
 * 
26
 * Even page footer value. Corresponds to even printed pages. 
27
 * Even page(s) in the sheet may not be printed, for example, if the print area is specified to be 
28
 * a range such that it falls outside an even page's scope. 
29
 * If no even footer is specified, then the odd footer's value is assumed for even page footers. 
30
 *
31
 */
24
public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{
32
public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{
25
33
    
34
    /**
35
     * Create an instance of XSSFEvenFooter from the supplied XML bean
36
     * @see XSSFSheet#getEvenFooter()
37
     * @param headerFooter
38
     */
26
    public XSSFEvenFooter(CTHeaderFooter headerFooter) {
39
    public XSSFEvenFooter(CTHeaderFooter headerFooter) {
27
        super(headerFooter);
40
        super(headerFooter);
41
        headerFooter.setDifferentOddEven(true);
28
    }
42
    }
29
    
43
    
44
    /**
45
     * Get the content text representing the footer
46
     * @return text
47
     */
30
    public String getText() {
48
    public String getText() {
31
        return getHeaderFooter().getEvenFooter();
49
        return getHeaderFooter().getEvenFooter();
32
    }
50
    }
33
    
51
    
52
    /**
53
     * Set a text for the footer. If null unset the value.
54
     * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax
55
     * @param text - a string representing the footer. 
56
     */
34
    public void setText(String text) {
57
    public void setText(String text) {
35
    	if(text == null) {
58
    	if(text == null) {
36
    		getHeaderFooter().unsetEvenFooter();
59
    		getHeaderFooter().unsetEvenFooter();
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java (+20 lines)
Lines 21-36 Link Here
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
23
23
24
/**
25
 * Odd page header value. Corresponds to odd printed pages. 
26
 * Odd page(s) in the sheet may not be printed, for example, if the print area is specified to be 
27
 * a range such that it falls outside an odd page's scope.
28
 *
29
 */
24
public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
30
public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
25
31
32
    /**
33
     * Create an instance of XSSFOddHeader from the supplied XML bean
34
     * @see XSSFSheet#getOddHeader()
35
     * @param headerFooter
36
     */
26
    protected XSSFOddHeader(CTHeaderFooter headerFooter) {
37
    protected XSSFOddHeader(CTHeaderFooter headerFooter) {
27
        super(headerFooter);
38
        super(headerFooter);
28
    }
39
    }
29
    
40
    
41
    /**
42
     * Get the content text representing this header
43
     * @return text
44
     */
30
    public String getText() {
45
    public String getText() {
31
        return getHeaderFooter().getOddHeader();
46
        return getHeaderFooter().getOddHeader();
32
    }
47
    }
33
    
48
    
49
    /**
50
     * Set a text for the header. If null unset the value
51
     * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax
52
     * @param text - a string representing the header. 
53
     */
34
    public void setText(String text) {
54
    public void setText(String text) {
35
    	if(text == null) {
55
    	if(text == null) {
36
    		getHeaderFooter().unsetOddHeader();
56
    		getHeaderFooter().unsetOddHeader();
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java (+22 lines)
Lines 21-36 Link Here
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
23
23
24
/**
25
 * 
26
 * First page header content. Corresponds to first printed page.
27
 * The first logical page in the sheet may not be printed, for example, if the print area is specified to 
28
 * be a range such that it falls outside the first page's scope.
29
 *
30
 */
24
public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
31
public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
25
32
33
    /**
34
     * Create an instance of XSSFFirstHeader from the supplied XML bean
35
     * @see XSSFSheet#getFirstHeader()
36
     * @param headerFooter
37
     */
26
    protected XSSFFirstHeader(CTHeaderFooter headerFooter) {
38
    protected XSSFFirstHeader(CTHeaderFooter headerFooter) {
27
        super(headerFooter);
39
        super(headerFooter);
40
        headerFooter.setDifferentFirst(true);
28
    }
41
    }
29
    
42
    
43
    /**
44
     * Get the content text representing this header
45
     * @return text
46
     */
30
    public String getText() {
47
    public String getText() {
31
        return getHeaderFooter().getFirstHeader();
48
        return getHeaderFooter().getFirstHeader();
32
    }
49
    }
33
    
50
    
51
    /**
52
     * Set a text for the header. If null unset the value
53
     * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax
54
     * @param text - a string representing the header. 
55
     */
34
    public void setText(String text) {
56
    public void setText(String text) {
35
    	if(text == null) {
57
    	if(text == null) {
36
    		getHeaderFooter().unsetFirstHeader();
58
    		getHeaderFooter().unsetFirstHeader();
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvenHeader.java (-9 / +34 lines)
Lines 21-42 Link Here
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
23
23
24
/**
25
 * <p>
26
 * Even page header value. Corresponds to even printed pages.
27
 * Even page(s) in the sheet may not be printed, for example, if the print area is specified to be 
28
 * a range such that it falls outside an even page's scope.
29
 * If no even header is specified, then odd header value is assumed for even page headers.
30
 *</p>
31
 *
32
 */
24
public class XSSFEvenHeader extends XSSFHeaderFooter implements Header{
33
public class XSSFEvenHeader extends XSSFHeaderFooter implements Header{
25
34
35
    /**
36
     * Create an instance of XSSFEvenHeader from the supplied XML bean
37
     * @see XSSFSheet#getEvenHeader()
38
     * @param headerFooter
39
     */
26
    public XSSFEvenHeader(CTHeaderFooter headerFooter) {
40
    public XSSFEvenHeader(CTHeaderFooter headerFooter) {
27
        super(headerFooter);
41
	super(headerFooter);
42
	headerFooter.setDifferentOddEven(true);
28
    }
43
    }
29
    
44
45
    /**
46
     * Get the content text representing this header
47
     * @return text
48
     */
30
    public String getText() {
49
    public String getText() {
31
        return getHeaderFooter().getEvenHeader();
50
	return getHeaderFooter().getEvenHeader();
32
    }
51
    }
33
    
52
53
    /**
54
     * Set a text for the header. If null unset the value
55
     * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax
56
     * @param text - a string representing the header. 
57
     */
34
    public void setText(String text) {
58
    public void setText(String text) {
35
    	if(text == null) {
59
	if(text == null) {
36
    		getHeaderFooter().unsetEvenHeader();
60
	    getHeaderFooter().unsetEvenHeader();
37
    	} else {
61
	} else {
38
    		getHeaderFooter().setEvenHeader(text);
62
	    getHeaderFooter().setEvenHeader(text);
39
    	}
63
	}
40
    }
64
    }
41
65
66
    
42
}
67
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFOddFooter.java (+20 lines)
Lines 21-36 Link Here
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
23
23
24
/**
25
 * Odd page footer value. Corresponds to odd printed pages.
26
 * Odd page(s) in the sheet may not be printed, for example, if the print area is specified to be 
27
 * a range such that it falls outside an odd page's scope.
28
 *
29
 */
24
public class XSSFOddFooter extends XSSFHeaderFooter implements Footer{
30
public class XSSFOddFooter extends XSSFHeaderFooter implements Footer{
25
31
32
    /**
33
     * Create an instance of XSSFOddFooter from the supplied XML bean
34
     * @see XSSFSheet#getOddFooter()
35
     * @param headerFooter
36
     */
26
    public XSSFOddFooter(CTHeaderFooter headerFooter) {
37
    public XSSFOddFooter(CTHeaderFooter headerFooter) {
27
        super(headerFooter);
38
        super(headerFooter);
28
    }
39
    }
29
    
40
    
41
    /**
42
     * Get the content text representing the footer
43
     * @return text
44
     */
30
    public String getText() {
45
    public String getText() {
31
        return getHeaderFooter().getOddFooter();
46
        return getHeaderFooter().getOddFooter();
32
    }
47
    }
33
    
48
    
49
    /**
50
     * Set a text for the footer. If null unset the value.
51
     * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax
52
     * @param text - a string representing the footer. 
53
     */
34
    public void setText(String text) {
54
    public void setText(String text) {
35
    	if(text == null) {
55
    	if(text == null) {
36
    		getHeaderFooter().unsetOddFooter();
56
    		getHeaderFooter().unsetOddFooter();
(-)src/examples/src/org/apache/poi/xssf/usermodel/examples/HeadersAndFooters.java (-3 / +40 lines)
Lines 19-26 Link Here
19
import java.io.FileOutputStream;
19
import java.io.FileOutputStream;
20
20
21
import org.apache.poi.ss.usermodel.Footer;
21
import org.apache.poi.ss.usermodel.Footer;
22
import org.apache.poi.ss.usermodel.Header;
22
import org.apache.poi.ss.usermodel.Sheet;
23
import org.apache.poi.ss.usermodel.Sheet;
23
import org.apache.poi.ss.usermodel.Workbook;
24
import org.apache.poi.ss.usermodel.Workbook;
25
import org.apache.poi.xssf.usermodel.XSSFSheet;
24
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
26
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
25
27
26
public class HeadersAndFooters {
28
public class HeadersAndFooters {
Lines 28-34 Link Here
28
30
29
    public static void main(String[]args) throws Exception {
31
    public static void main(String[]args) throws Exception {
30
        Workbook wb = new XSSFWorkbook();
32
        Workbook wb = new XSSFWorkbook();
31
        Sheet sheet = wb.createSheet("format sheet");
33
        Sheet sheet = wb.createSheet("first-header - format sheet");
32
        sheet.createRow(0).createCell(0).setCellValue(123);
34
        sheet.createRow(0).createCell(0).setCellValue(123);
33
35
34
        //set page numbers in the footer
36
        //set page numbers in the footer
Lines 37-45 Link Here
37
        //&N == page numbers
39
        //&N == page numbers
38
        footer.setRight("Page &P of &N");
40
        footer.setRight("Page &P of &N");
39
41
40
        // Create various cells and rows for spreadsheet.
42
        
43
        Header firstHeader=((XSSFSheet)sheet).getFirstHeader();
44
        //&F == workbook file name
45
        firstHeader.setLeft("&F ......... first header");
46
        
47
        for(int i=0;i<100;i=i+10){
48
            sheet.createRow(i).createCell(0).setCellValue(123);
49
        }
50
        
51
        
52
        XSSFSheet sheet2 = (XSSFSheet)wb.createSheet("odd header-even footer");
53
        Header oddHeader=sheet2.getOddHeader();
54
        //&B == bold
55
        //&E == double underline
56
        //&D == date
57
        oddHeader.setCenter("&B &E oddHeader     &D ");
58
        
59
        Footer evenFooter=sheet2.getEvenFooter();
60
        evenFooter.setRight("even footer &P");
61
        sheet2.createRow(10).createCell(0).setCellValue("Second sheet with an oddHeader and an evenFooter");
41
62
42
        FileOutputStream fileOut = new FileOutputStream("pageNumerOnFooter.xlsx");
63
        for(int i=0;i<200;i=i+10){
64
            sheet2.createRow(i).createCell(0).setCellValue(123);
65
        }
66
        
67
        XSSFSheet sheet3 = (XSSFSheet)wb.createSheet("odd header- odd footer");
68
        sheet3.createRow(10).createCell(0).setCellValue("Third sheet with oddHeader and oddFooter");
69
        Header oddH=sheet3.getOddHeader();
70
        //&C == centered
71
        oddH.setCenter("centered oddHeader");
72
        oddH.setLeft("left ");
73
        oddH.setRight("right ");
74
        
75
        Footer oddF=sheet3.getOddFooter();
76
        oddF.setLeft("Page &P");
77
        oddF.setRight("Pages &N ");
78
        
79
        FileOutputStream fileOut = new FileOutputStream("headerFooter.xlsx");
43
        wb.write(fileOut);
80
        wb.write(fileOut);
44
        fileOut.close();
81
        fileOut.close();
45
82

Return to bug 46120