You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HSSFHyperlink.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.usermodel;
  16. import org.apache.poi.hssf.record.HyperlinkRecord;
  17. import org.apache.poi.ss.usermodel.Hyperlink;
  18. /**
  19. * Represents an Excel hyperlink.
  20. *
  21. * @author Yegor Kozlov (yegor at apache dot org)
  22. */
  23. public class HSSFHyperlink implements Hyperlink {
  24. /**
  25. * Link to a existing file or web page
  26. */
  27. public static final int LINK_URL = 1;
  28. /**
  29. * Link to a place in this document
  30. */
  31. public static final int LINK_DOCUMENT = 2;
  32. /**
  33. * Link to an E-mail address
  34. */
  35. public static final int LINK_EMAIL = 3;
  36. /**
  37. * Link to a file
  38. */
  39. public static final int LINK_FILE = 4;
  40. /**
  41. * Low-level record object that stores the actual hyperlink data
  42. */
  43. protected HyperlinkRecord record = null;
  44. /**
  45. * If we create a new hypelrink remember its type
  46. */
  47. protected int link_type;
  48. /**
  49. * Construct a new hyperlink
  50. *
  51. * @param type the type of hyperlink to create
  52. */
  53. public HSSFHyperlink( int type )
  54. {
  55. this.link_type = type;
  56. record = new HyperlinkRecord();
  57. switch(type){
  58. case LINK_URL:
  59. case LINK_EMAIL:
  60. record.newUrlLink();
  61. break;
  62. case LINK_FILE:
  63. record.newFileLink();
  64. break;
  65. case LINK_DOCUMENT:
  66. record.newDocumentLink();
  67. break;
  68. }
  69. }
  70. /**
  71. * Initialize the hyperlink by a <code>HyperlinkRecord</code> record
  72. *
  73. * @param record
  74. */
  75. protected HSSFHyperlink( HyperlinkRecord record )
  76. {
  77. this.record = record;
  78. }
  79. /**
  80. * Return the row of the first cell that contains the hyperlink
  81. *
  82. * @return the 0-based row of the cell that contains the hyperlink
  83. */
  84. public int getFirstRow(){
  85. return record.getFirstRow();
  86. }
  87. /**
  88. * Set the row of the first cell that contains the hyperlink
  89. *
  90. * @param row the 0-based row of the first cell that contains the hyperlink
  91. */
  92. public void setFirstRow(int row){
  93. record.setFirstRow(row);
  94. }
  95. /**
  96. * Return the row of the last cell that contains the hyperlink
  97. *
  98. * @return the 0-based row of the last cell that contains the hyperlink
  99. */
  100. public int getLastRow(){
  101. return record.getLastRow();
  102. }
  103. /**
  104. * Set the row of the last cell that contains the hyperlink
  105. *
  106. * @param row the 0-based row of the last cell that contains the hyperlink
  107. */
  108. public void setLastRow(int row){
  109. record.setLastRow(row);
  110. }
  111. /**
  112. * Return the column of the first cell that contains the hyperlink
  113. *
  114. * @return the 0-based column of the first cell that contains the hyperlink
  115. */
  116. public int getFirstColumn(){
  117. return record.getFirstColumn();
  118. }
  119. /**
  120. * Set the column of the first cell that contains the hyperlink
  121. *
  122. * @param col the 0-based column of the first cell that contains the hyperlink
  123. */
  124. public void setFirstColumn(int col){
  125. record.setFirstColumn((short)col);
  126. }
  127. /**
  128. * Return the column of the last cell that contains the hyperlink
  129. *
  130. * @return the 0-based column of the last cell that contains the hyperlink
  131. */
  132. public int getLastColumn(){
  133. return record.getLastColumn();
  134. }
  135. /**
  136. * Set the column of the last cell that contains the hyperlink
  137. *
  138. * @param col the 0-based column of the last cell that contains the hyperlink
  139. */
  140. public void setLastColumn(int col){
  141. record.setLastColumn((short)col);
  142. }
  143. /**
  144. * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, path to a file, etc.
  145. *
  146. * @return the address of this hyperlink
  147. */
  148. public String getAddress(){
  149. return record.getAddress();
  150. }
  151. public String getTextMark(){
  152. return record.getTextMark();
  153. }
  154. /**
  155. * Convenience method equivalent to {@link #setAddress(String)}
  156. *
  157. * @param textMark the place in worksheet this hypelrink referes to, e.g. 'Target Sheet'!A1'
  158. */
  159. public void setTextMark(String textMark) {
  160. record.setTextMark(textMark);
  161. }
  162. public String getShortFilename(){
  163. return record.getShortFilename();
  164. }
  165. /**
  166. * Convenience method equivalent to {@link #setAddress(String)}
  167. *
  168. * @param shortFilename the path to a file this hypelrink points to, e.g. 'readme.txt'
  169. */
  170. public void setShortFilename(String shortFilename) {
  171. record.setShortFilename(shortFilename);
  172. }
  173. /**
  174. * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
  175. *
  176. * @param address the address of this hyperlink
  177. */
  178. public void setAddress(String address){
  179. record.setAddress(address);
  180. }
  181. /**
  182. * Return text label for this hyperlink
  183. *
  184. * @return text to display
  185. */
  186. public String getLabel(){
  187. return record.getLabel();
  188. }
  189. /**
  190. * Sets text label for this hyperlink
  191. *
  192. * @param label text label for this hyperlink
  193. */
  194. public void setLabel(String label){
  195. record.setLabel(label);
  196. }
  197. /**
  198. * Return the type of this hyperlink
  199. *
  200. * @return the type of this hyperlink
  201. */
  202. public int getType(){
  203. return link_type;
  204. }
  205. }