NPOI_2.1.3 _ Learning Record (3)-add content and hyperlink (URL, Email, and Sheet) to a specified cell in Excel, and npoi_2.1.3sheet

Source: Internet
Author: User

NPOI_2.1.3 _ Learning Record (3)-add content and hyperlink (URL, Email, and Sheet) to a specified cell in Excel, and npoi_2.1.3sheet

In the previous article, we created four sheets. Now we insert content to the specified cells and the Specified Cells in the specified Sheet and add links. In the code for creating a Sheet, we add code, as follows:

// Set the cell font style ICellStyle iCellStyle = hssfWorkbook. createCellStyle (); IFont iFont = hssfWorkbook. createFont (); iFont. color = HSSFColor. green. index; // set the color iFont. underline = FontUnderlineType. single; // set the link underline iCellStyle. setFont (iFont); // create a new row and column ICell iCell = sheet1.CreateRow (0) in sheet1 ). createCell (2); // set the cell value iCell. setCellValue ("this is a URL link"); // create a URL link HSSFHyperlink hssfHyperlink = new HSSFHyperlink (HyperlinkType. url) {Address = (" http://www.cnblogs.com/Murray ")}; ICell. hyperlink = hssfHyperlink; iCell. cellStyle = iCellStyle; // create Email link iCell = sheet1.CreateRow (1 ). createCell (0); iCell. setCellValue ("this is an Email link"); hssfHyperlink = new HSSFHyperlink (HyperlinkType. email) {Address = ("mailto: 398827547@qq.com? Subject = This is an Email link ")}; iCell. hyperlink = hssfHyperlink; iCell. cellStyle = iCellStyle; // link to the worksheet Sheet2sheet2. createRow (0 ). createCell (0 ). setCellValue ("right here"); iCell = sheet1.CreateRow (2 ). createCell (0); iCell. setCellValue ("this is the worksheet link"); hssfHyperlink = new HSSFHyperlink (HyperlinkType. document) {Address = ("'murray worksheet _ 2 '! A1 ")}; iCell. Hyperlink = hssfHyperlink; iCell. CellStyle = iCellStyle;

As shown in the following figure (the link effect will not be available here ):

Related Article

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.