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 ):