-
Notifications
You must be signed in to change notification settings - Fork 891
Using Hyperlinks
Francois Botha edited this page Feb 26, 2018
·
3 revisions
var wb = new XLWorkbook();
var ws = wb.Worksheets.Add("Hyperlinks");
wb.Worksheets.Add("Second Sheet");
Int32 ro = 0;
// You can create a link with pretty much anything you can put on a
// browser: http, ftp, mailto, gopher, news, nntp, etc.
ws.Cell(++ro, 1).Value = "Link to a web page, no tooltip - Yahoo!";
ws.Cell(ro, 1).Hyperlink = new XLHyperlink(@"http://www.yahoo.com");
ws.Cell(++ro, 1).Value = "Link to a web page, with a tooltip - Yahoo!";
ws.Cell(ro, 1).Hyperlink = new XLHyperlink(@"http://www.yahoo.com", "Click to go to Yahoo!");
ws.Cell(++ro, 1).Value = "Link to a file - same folder";
ws.Cell(ro, 1).Hyperlink = new XLHyperlink("Test.xlsx");
ws.Cell(++ro, 1).Value = "Link to a file - relative address";
ws.Cell(ro, 1).Hyperlink = new XLHyperlink(@"../Test.xlsx");
ws.Cell(++ro, 1).Value = "Link to an address in this worksheet";
ws.Cell(ro, 1).Hyperlink = new XLHyperlink("B1");
ws.Cell(++ro, 1).Value = "Link to an address in another worksheet";
ws.Cell(ro, 1).Hyperlink = new XLHyperlink("'Second Sheet'!A1");
// You can also set the properties of a hyperlink directly:
ws.Cell(++ro, 1).Value = "Link to a range in this worksheet";
ws.Cell(ro, 1).Hyperlink.InternalAddress = "B1:C2";
ws.Cell(ro, 1).Hyperlink.Tooltip = "SquareBox";
ws.Cell(++ro, 1).Value = "Link to an email message";
ws.Cell(ro, 1).Hyperlink.ExternalAddress = new Uri(@"mailto:SantaClaus@NorthPole.com?subject=Presents");
// Deleting a hyperlink
ws.Cell(++ro, 1).Value = "This is no longer a link";
ws.Cell(ro, 1).Hyperlink.InternalAddress = "A1";
ws.Cell(ro, 1).Hyperlink.Delete();
// Setting a hyperlink preserves previous formatting:
ws.Cell(++ro, 1).Value = "Odd looking link";
ws.Cell(ro, 1).Style.Font.FontColor = XLColor.Red;
ws.Cell(ro, 1).Style.Font.Underline = XLFontUnderlineValues.Double;
ws.Cell(ro, 1).Hyperlink = new XLHyperlink(ws.Range("B1:C2"));
// List all hyperlinks in a worksheet:
var hyperlinksInWorksheet = ws.Hyperlinks;
// List all hyperlinks in a range:
var hyperlinksInRange = ws.Range("A1:A3").Hyperlinks;
ws.Columns().AdjustToContents();
wb.SaveAs("Hyperlinks.xlsx");
- How do I deliver an Excel file in ASP.NET?
- Does it support Excel 2003 and prior formats (.xls)?
- How can I insert an image?
- Text with numbers are getting converted to numbers, what's up with that?
- How do I get the result of a formula?
- Data Types
- Creating Multiple Worksheets
- Organizing Sheets
- Loading and Modifying Files
- Using Lambda Expressions
- Cell Values
- Workbook Properties
- Using Formulas
- Evaluating Formulas
- Creating Rows And Columns Outlines
- Hide Unhide Rows And Columns
- Freeze Panes
- Copying Worksheets
- Using Hyperlinks
- Data Validation
- Hide Worksheets
- Sheet Protection
- Tab Colors
- Conditional Formatting
- Pivot Table example
- Sparklines
- Copying IEnumerable Collections
- Inserting Data
- Inserting Tables
- Adding DataTable as Worksheet
- Adding DataSet
- Styles - Alignment
- Styles - Border
- Styles - Fill
- Styles - Font
- Styles - NumberFormat
- NumberFormatId Lookup Table
- Style Worksheet
- Style Rows and Columns
- Using Default Styles
- Using Colors
- ClosedXML Predefined Colors
- Excel Indexed Colors
- Using Rich Text
- Using Phonetics
- Defining Ranges
- Merging Cells
- Clearing Ranges
- Deleting Ranges
- Multiple Ranges
- Shifting Ranges
- Transpose Ranges
- Named Ranges
- Accessing Named Ranges
- Copying Ranges
- Using Tables
- Sorting Data
- Selecting Cells and Ranges
- Row Height and Styles
- Selecting Rows
- Inserting Rows
- Inserting and Deleting Rows
- Adjust Row Height and Column Width to Contents
- Row Cells
- Column Width and Styles
- Selecting Columns
- Inserting Columns
- Inserting and Deleting Columns
- Adjust Row Height and Column Width to Contents
- Column Cells
- Pages Tab
- Paper Size Lookup Table
- Margins Tab
- Headers and Footers Tab
- Sheet Tab
- Print Areas and Page Breaks