Reproduced from: http://blog.csdn.net/u014232091/article/details/23710391 (original original)
POI implement the function of clicking a hyperlink in an Excel file to jump to a column of a sheet page
Describe:
Build a hyperlink in an Excel file when you click a cell to jump to a column of a sheet page, such as
Click the number (the total number) on the total page to jump to the detail page and view each row of data
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Org.apache.poi.hssf.usermodel.HSSFCell;
Import Org.apache.poi.hssf.usermodel.HSSFCellStyle;
Import Org.apache.poi.hssf.usermodel.HSSFFont;
Import Org.apache.poi.hssf.usermodel.HSSFHyperlink;
Import Org.apache.poi.hssf.usermodel.HSSFRow;
Import Org.apache.poi.hssf.usermodel.HSSFSheet;
Import Org.apache.poi.hssf.usermodel.HSSFWorkbook;
Import Org.apache.poi.hssf.util.HSSFColor;
Import org.apache.poi.hssf.util.Region;
Import Org.apache.poi.ss.usermodel.Hyperlink; public class Test {public static void main (string[] args) throws IOException {/*.
Use the POI version: 3.10-final*//* Create a new Hssfworkbook object * * * Hssfworkbook WB = Newer hssfworkbook ();
* * Create a new Sheet object/hssfsheet sheet = wb.createsheet ("Summary page");
Hssfrow row = Sheet.createrow ((short) 0);
/* Connection Jump/Hssfcell Likecell = Row.createcell ((short) 0); HyperlInk hyperlink = new Hssfhyperlink (hyperlink.link_document); "#" indicates that the "detail page" of this document indicates that the sheet page name "A10" represents the first few rows of the column hyperlink.setaddress ("#明细页面!").
A10 ");
Likecell.sethyperlink (hyperlink);
Click to jump Likecell.setcellvalue ("1");
/* Set as Hyperlink style * * Hssfcellstyle Linkstyle = Wb.createcellstyle ();
Hssffont cellfont= Wb.createfont ();
Cellfont.setunderline ((byte) 1);
Cellfont.setcolor (HSSFColor.BLUE.index);
Linkstyle.setfont (Cellfont);
Likecell.setcellstyle (Linkstyle); * * Create a second sheet object/hssfsheet Sheet2 = wb.createsheet ("detail page"); Create a new sheet object for (int i = 0; i < i++) {Hssfrow row2 = Sheet2.createrow (short)
i);
Hssfcell cell2 = Row2.createcell ((short) 0);
Cell2.setcellvalue ("Test First" + (i+1) + "line"); /* Output File/* FileOutputStream fileout = new FilEoutputstream ("d:\\ totals and details. xls");
Wb.write (fileout);
Fileout.close ();
}
}