aboutsummaryrefslogtreecommitdiffstats
path: root/src/documentation/content/xdocs/hssf/quick-guide.xml
diff options
context:
space:
mode:
Diffstat (limited to 'src/documentation/content/xdocs/hssf/quick-guide.xml')
-rw-r--r--src/documentation/content/xdocs/hssf/quick-guide.xml71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/documentation/content/xdocs/hssf/quick-guide.xml b/src/documentation/content/xdocs/hssf/quick-guide.xml
index 69850afe88..66da604892 100644
--- a/src/documentation/content/xdocs/hssf/quick-guide.xml
+++ b/src/documentation/content/xdocs/hssf/quick-guide.xml
@@ -69,6 +69,7 @@
<li><link href="#NamedRanges">Named Ranges and Named Cells</link></li>
<li><link href="#CellComments">How to set cell comments</link></li>
<li><link href="#Autofit">How to adjust column width to fit the contents</link></li>
+ <li><link href="#Hyperlinks">Hyperlinks</link></li>
</ul>
</section>
<section><title>Features</title>
@@ -1322,6 +1323,76 @@ Examples:
(either via <code>-Djava.awt.headless=true</code> startup parameter or via <code>System.setProperty("java.awt.headless", "true")</code>).
</warning>
</section>
+ <anchor id="Hyperlinks"/>
+ <section><title>How to read hyperlinks</title>
+ <source>
+ HSSFSheet sheet = workbook.getSheetAt(0);
+
+ HSSFCell cell = sheet.getRow(0).getCell((short)0);
+ HSSFHyperlink link = cell.getHyperlink();
+ if(link != null){
+ System.out.println(link.getAddress());
+ }
+ </source>
+ </section>
+ <section><title>How to create hyperlinks</title>
+ <source>
+ HSSFWorkbook wb = new HSSFWorkbook();
+
+ //cell style for hyperlinks
+ //by default hypelrinks are blue and underlined
+ HSSFCellStyle hlink_style = wb.createCellStyle();
+ HSSFFont hlink_font = wb.createFont();
+ hlink_font.setUnderline(HSSFFont.U_SINGLE);
+ hlink_font.setColor(HSSFColor.BLUE.index);
+ hlink_style.setFont(hlink_font);
+
+ HSSFCell cell;
+ HSSFSheet sheet = wb.createSheet("Hyperlinks");
+
+ //URL
+ cell = sheet.createRow(0).createCell((short)0);
+ cell.setCellValue("URL Link");
+ HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
+ link.setAddress("http://poi.apache.org/");
+ cell.setHyperlink(link);
+ cell.setCellStyle(hlink_style);
+
+ //link to a file in the current directory
+ cell = sheet.createRow(1).createCell((short)0);
+ cell.setCellValue("File Link");
+ link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
+ link.setAddress("link1.xls");
+ cell.setHyperlink(link);
+ cell.setCellStyle(hlink_style);
+
+ //e-mail link
+ cell = sheet.createRow(2).createCell((short)0);
+ cell.setCellValue("Email Link");
+ link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
+ //note, if subject contains white spaces, make sure they are url-encoded
+ link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
+ cell.setHyperlink(link);
+ cell.setCellStyle(hlink_style);
+
+ //link to a place in this workbook
+
+ //create a target sheet and cell
+ HSSFSheet sheet2 = wb.createSheet("Target Sheet");
+ sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");
+
+ cell = sheet.createRow(3).createCell((short)0);
+ cell.setCellValue("Worksheet Link");
+ link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
+ link.setAddress("'Target Sheet'!A1");
+ cell.setHyperlink(link);
+ cell.setCellStyle(hlink_style);
+
+ FileOutputStream out = new FileOutputStream("hssf-links.xls");
+ wb.write(out);
+ out.close();
+ </source>
+ </section>
</body>
</document>