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

(-)src/examples/src/org/apache/poi/xssf/usermodel/examples/PageNumberOnFooter.java (+29 lines)
Line 0 Link Here
1
package org.apache.poi.xssf.usermodel.examples;
2
3
import java.io.FileOutputStream;
4
5
import org.apache.poi.ss.usermodel.Footer;
6
import org.apache.poi.ss.usermodel.Sheet;
7
import org.apache.poi.ss.usermodel.Workbook;
8
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
9
10
public class PageNumberOnFooter {
11
12
    
13
    public static void main(String[]args) throws Exception{
14
	   Workbook wb = new XSSFWorkbook();
15
	   Sheet sheet = wb.createSheet("format sheet");
16
	   sheet.createRow(0).createCell(0).setCellValue(123);
17
	   Footer footer = sheet.getFooter();
18
	   //&P == current page number
19
	   //&N == page numbers
20
	    footer.setRight( "Page &P of &N" );
21
22
	    // Create various cells and rows for spreadsheet.
23
24
	    FileOutputStream fileOut = new FileOutputStream("pageNumerOnFooter.xlsx");
25
	    wb.write(fileOut);
26
	    fileOut.close();
27
28
    }
29
}
(-)src/examples/src/org/apache/poi/xssf/usermodel/examples/SelectedSheet.java (+28 lines)
Line 0 Link Here
1
package org.apache.poi.xssf.usermodel.examples;
2
3
import java.io.FileOutputStream;
4
5
import org.apache.poi.ss.usermodel.Sheet;
6
import org.apache.poi.ss.usermodel.Workbook;
7
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
8
9
public class SelectedSheet {
10
11
    public static void main(String[]args) throws Exception{
12
	Workbook wb = new XSSFWorkbook();
13
	Sheet sheet = wb.createSheet("row sheet");
14
15
	Sheet sheet2 = wb.createSheet("another sheet");
16
	Sheet sheet3 = wb.createSheet(" sheet 3 ");
17
	sheet3.setSelected(true);
18
19
	// Create various cells and rows for spreadsheet.
20
21
	FileOutputStream fileOut = new FileOutputStream("selectedSheet.xlsx");
22
	wb.write(fileOut);
23
	fileOut.close();
24
25
26
    }
27
28
}
(-)src/examples/src/org/apache/poi/xssf/usermodel/examples/HyperlinkExample.java (+79 lines)
Line 0 Link Here
1
package org.apache.poi.xssf.usermodel.examples;
2
3
import java.io.FileOutputStream;
4
5
import org.apache.poi.hssf.usermodel.HSSFFont;
6
import org.apache.poi.hssf.util.HSSFColor;
7
import org.apache.poi.ss.usermodel.Cell;
8
import org.apache.poi.ss.usermodel.CellStyle;
9
import org.apache.poi.ss.usermodel.CreationHelper;
10
import org.apache.poi.ss.usermodel.Font;
11
import org.apache.poi.ss.usermodel.Hyperlink;
12
import org.apache.poi.ss.usermodel.Sheet;
13
import org.apache.poi.ss.usermodel.Workbook;
14
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
15
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
16
17
public class HyperlinkExample {
18
19
    
20
    public static void main(String[]args) throws Exception{
21
	    Workbook wb = new XSSFWorkbook();
22
23
	    //cell style for hyperlinks
24
	    //by default hypelrinks are blue and underlined
25
	    CellStyle hlink_style = wb.createCellStyle();
26
	    Font hlink_font = wb.createFont();
27
	    hlink_font.setUnderline(HSSFFont.U_SINGLE);
28
	    hlink_font.setColor(HSSFColor.BLUE.index);
29
	    hlink_style.setFont(hlink_font);
30
31
	    Cell cell;
32
	    Sheet sheet = wb.createSheet("Hyperlinks");
33
	    CreationHelper createHelper = wb.getCreationHelper();
34
	    //URL
35
	    cell = sheet.createRow(0).createCell((short)0);
36
	    cell.setCellValue("URL Link");  
37
	    
38
	    Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
39
	    link.setAddress("http://poi.apache.org/");
40
	    cell.setHyperlink(link);
41
	    cell.setCellStyle(hlink_style);
42
43
	    //link to a file in the current directory
44
	    cell = sheet.createRow(1).createCell((short)0);
45
	    cell.setCellValue("File Link");
46
	    link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
47
	    link.setAddress("link1.xls");
48
	    cell.setHyperlink(link);
49
	    cell.setCellStyle(hlink_style);
50
51
	    //e-mail link
52
	    cell = sheet.createRow(2).createCell((short)0);
53
	    cell.setCellValue("Email Link");
54
	    link = createHelper.createHyperlink(Hyperlink.LINK_EMAIL);
55
	    //note, if subject contains white spaces, make sure they are url-encoded
56
	    link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
57
	    cell.setHyperlink(link);
58
	    cell.setCellStyle(hlink_style);
59
60
	    //link to a place in this workbook
61
62
	    //create a target sheet and cell
63
	    Sheet sheet2 = wb.createSheet("Target Sheet");
64
	    sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");
65
66
	    cell = sheet.createRow(3).createCell((short)0);
67
	    cell.setCellValue("Worksheet Link");
68
	    XSSFHyperlink link2 = (XSSFHyperlink)createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
69
	    link2.setAddress("'Target Sheet'!A1");
70
	    link2.setLocation("'Target Sheet'!A1");
71
	    cell.setHyperlink(link2);
72
	    cell.setCellStyle(hlink_style);
73
74
	    FileOutputStream out = new FileOutputStream("hyperinks.xlsx");
75
	    wb.write(out);
76
	    out.close();
77
	    
78
    }
79
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java (+8 lines)
Lines 124-133 Link Here
124
	public String getLabel() {
124
	public String getLabel() {
125
		return ctHyperlink.getDisplay();
125
		return ctHyperlink.getDisplay();
126
	}
126
	}
127
	public String getLocation() {
128
		return ctHyperlink.getLocation();
129
	}
127
	
130
	
128
	public void setLabel(String label) {
131
	public void setLabel(String label) {
129
		ctHyperlink.setDisplay(label);
132
		ctHyperlink.setDisplay(label);
130
	}
133
	}
134
	
135
	public void setLocation(String location){
136
		ctHyperlink.setLocation(location);
137
	}
138
	
131
	public void setAddress(String address) {
139
	public void setAddress(String address) {
132
		location = address;
140
		location = address;
133
	}
141
	}

Return to bug 46004