POI implement the function of clicking a hyperlink in an Excel file to jump to a row of a sheet page __java

Source: Internet
Author: User

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 ();
 }  
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.