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

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java (-4 / +99 lines)
Lines 36-46 Link Here
36
	private PackageRelationship externalRel;
36
	private PackageRelationship externalRel;
37
	private CTHyperlink ctHyperlink;
37
	private CTHyperlink ctHyperlink;
38
	private String location;
38
	private String location;
39
	
39
40
	/**
41
	 * Create a new XSSFHyperlink. This method is protected to be used only by XSSFCreationHelper
42
	 * @param type - the type of hyperlink to create
43
	 * @see Hyperlink
44
	 */
40
	protected XSSFHyperlink(int type) {
45
	protected XSSFHyperlink(int type) {
41
		this.type = type;
46
		this.type = type;
42
		this.ctHyperlink = CTHyperlink.Factory.newInstance();
47
		this.ctHyperlink = CTHyperlink.Factory.newInstance();
43
	}
48
	}
49
	/**
50
	 * Create a new XSSFHyperlink Initialize the hyperlink by a <code>HyperlinkRecord</code> record
51
	 * This method is protected to be used only by <link>XSSFSheet.initHyperlinks()</link>
52
	 * @param ctHyperlink
53
	 * @param PackageRelationship
54
 	 *
55
	 */
44
	protected XSSFHyperlink(CTHyperlink ctHyperlink, PackageRelationship hyperlinkRel) {
56
	protected XSSFHyperlink(CTHyperlink ctHyperlink, PackageRelationship hyperlinkRel) {
45
		this.ctHyperlink = ctHyperlink;
57
		this.ctHyperlink = ctHyperlink;
46
		this.externalRel = hyperlinkRel;
58
		this.externalRel = hyperlinkRel;
Lines 106-141 Link Here
106
		}
118
		}
107
	}
119
	}
108
	
120
	
121
	/**
122
	 * Return the type of this hyperlink
123
	 *
124
	 * @return the type of this hyperlink
125
	 */
109
	public int getType() {
126
	public int getType() {
110
		return type;
127
		return type;
111
	}
128
	}
112
	
129
	
113
	/**
130
	/**
114
	 * Get the reference of the cell this applies to,
131
	 * Get the reference of the cell this applies to,
115
	 *  eg A55
132
	 *  es A55
116
	 */
133
	 */
117
	public String getCellRef() {
134
	public String getCellRef() {
118
		return ctHyperlink.getRef();
135
		return ctHyperlink.getRef();
119
	}
136
	}
120
	
137
	
138
	/**
139
	 * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, path to a file
140
	 *
141
	 * @return  the address of this hyperlink
142
	 */
121
	public String getAddress() {
143
	public String getAddress() {
122
		return location;
144
		return location;
123
	}
145
	}
146
147
	/**
148
	 * Return text label for this hyperlink
149
	 * @return  text to display
150
	 */
124
	public String getLabel() {
151
	public String getLabel() {
125
		return ctHyperlink.getDisplay();
152
		return ctHyperlink.getDisplay();
126
	}
153
	}
154
	/**
155
	 * Location within target. If target is a workbook (or this workbook) this shall refer to a
156
	 * sheet and cell or a defined name. Can also be an HTML anchor if target is HTML file.
157
	 * @return location
158
	 */
127
	public String getLocation() {
159
	public String getLocation() {
128
		return ctHyperlink.getLocation();
160
		return ctHyperlink.getLocation();
129
	}
161
	}
130
	
162
	
163
	/**
164
	 * Sets text label for this hyperlink
165
	 *
166
	 * @param label text label for this hyperlink
167
	 */
131
	public void setLabel(String label) {
168
	public void setLabel(String label) {
132
		ctHyperlink.setDisplay(label);
169
		ctHyperlink.setDisplay(label);
133
	}
170
	}
134
	
171
	
172
	/**
173
	 * Location within target. If target is a workbook (or this workbook) this shall refer to a
174
	 * sheet and cell or a defined name. Can also be an HTML anchor if target is HTML file.
175
	 * @param location - string representing a location of this hyperlink
176
	 */
135
	public void setLocation(String location){
177
	public void setLocation(String location){
136
		ctHyperlink.setLocation(location);
178
		ctHyperlink.setLocation(location);
137
	}
179
	}
138
	
180
	
181
	/**
182
	 * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, path to a file
183
	 *
184
	 * @param  address - the address of this hyperlink
185
	 */
139
	public void setAddress(String address) {
186
	public void setAddress(String address) {
140
		location = address;
187
		location = address;
141
        //we must set location for internal hyperlinks 
188
        //we must set location for internal hyperlinks 
Lines 155-174 Link Here
155
		return new CellReference(ctHyperlink.getRef());
202
		return new CellReference(ctHyperlink.getRef());
156
	}
203
	}
157
	
204
	
205
206
	/**
207
	 * Return the column of the first cell that contains the hyperlink
208
	 *
209
	 * @return the 0-based column of the first cell that contains the hyperlink
210
	 */
158
	public int getFirstColumn() {
211
	public int getFirstColumn() {
159
		return buildCellReference().getCol();
212
		return buildCellReference().getCol();
160
	}
213
	}
214
	
215
216
	/**
217
	 * Return the column of the last cell that contains the hyperlink
218
	 *
219
	 * @return the 0-based column of the last cell that contains the hyperlink
220
	 */
161
	public int getLastColumn() {
221
	public int getLastColumn() {
162
		return buildCellReference().getCol();
222
		return buildCellReference().getCol();
163
	}
223
	}
164
	
224
225
	/**
226
	 * Return the row of the first cell that contains the hyperlink
227
	 *
228
	 * @return the 0-based row of the cell that contains the hyperlink
229
	 */
165
	public int getFirstRow() {
230
	public int getFirstRow() {
166
		return buildCellReference().getRow();
231
		return buildCellReference().getRow();
167
	}
232
	}
233
	
234
235
	/**
236
	 * Return the row of the last cell that contains the hyperlink
237
	 *
238
	 * @return the 0-based row of the last cell that contains the hyperlink
239
	 */
168
	public int getLastRow() {
240
	public int getLastRow() {
169
		return buildCellReference().getRow();
241
		return buildCellReference().getRow();
170
	}
242
	}
171
	
243
244
	/**
245
	 * Set the column of the first cell that contains the hyperlink
246
	 *
247
	 * @param col the 0-based column of the first cell that contains the hyperlink
248
	 */
172
	public void setFirstColumn(int col) {
249
	public void setFirstColumn(int col) {
173
		ctHyperlink.setRef(
250
		ctHyperlink.setRef(
174
				new CellReference(
251
				new CellReference(
Lines 176-184 Link Here
176
				).formatAsString()
253
				).formatAsString()
177
		);
254
		);
178
	}
255
	}
256
257
	/**
258
	 * Set the column of the last cell that contains the hyperlink
259
	 *
260
	 * @param col the 0-based column of the last cell that contains the hyperlink
261
	 */
179
	public void setLastColumn(int col) {
262
	public void setLastColumn(int col) {
180
		setFirstColumn(col);
263
		setFirstColumn(col);
181
	}
264
	}
265
266
	/**
267
	 * Set the row of the first cell that contains the hyperlink
268
	 *
269
	 * @param row the 0-based row of the first cell that contains the hyperlink
270
	 */
182
	public void setFirstRow(int row) {
271
	public void setFirstRow(int row) {
183
		ctHyperlink.setRef(
272
		ctHyperlink.setRef(
184
				new CellReference(
273
				new CellReference(
Lines 186-191 Link Here
186
				).formatAsString()
275
				).formatAsString()
187
		);
276
		);
188
	}
277
	}
278
279
	/**
280
	 * Set the row of the last cell that contains the hyperlink
281
	 *
282
	 * @param row the 0-based row of the last cell that contains the hyperlink
283
	 */
189
	public void setLastRow(int row) {
284
	public void setLastRow(int row) {
190
		setFirstRow(row);
285
		setFirstRow(row);
191
	}
286
	}

Return to bug 46080