static void Hyperlinks(Stream stream, XlDocumentFormat documentFormat) { // Create an exporter instance. IXlExporter exporter = XlExport.CreateExporter(documentFormat); // Create a new document. using (IXlDocument document = exporter.CreateDocument(stream)) { document.Options.Culture = CultureInfo.CurrentCulture; #region #Hyperlinks // Create a worksheet. using (IXlSheet sheet = document.CreateSheet()) { using (IXlColumn column = sheet.CreateColumn()) { column.WidthInPixels = 300; } // Create a hyperlink to a cell in the current workbook. using (IXlRow row = sheet.CreateRow()) { using (IXlCell cell = row.CreateCell()) { cell.Value = "Local link"; cell.Formatting = XlCellFormatting.Hyperlink; XlHyperlink hyperlink = new XlHyperlink(); hyperlink.Reference = new XlCellRange(new XlCellPosition(cell.ColumnIndex, cell.RowIndex)); hyperlink.TargetUri = "#Sheet1!C5"; sheet.Hyperlinks.Add(hyperlink); } } // Create a hyperlink to a cell located in the external workbook. using (IXlRow row = sheet.CreateRow()) { using (IXlCell cell = row.CreateCell()) { cell.Value = "External file link"; cell.Formatting = XlCellFormatting.Hyperlink; XlHyperlink hyperlink = new XlHyperlink(); hyperlink.Reference = new XlCellRange(new XlCellPosition(cell.ColumnIndex, cell.RowIndex)); hyperlink.TargetUri = "linked.xlsx#Sheet1!C5"; sheet.Hyperlinks.Add(hyperlink); } } // Create a hyperlink to a web page. using (IXlRow row = sheet.CreateRow()) { using (IXlCell cell = row.CreateCell()) { cell.Value = "External URI"; cell.Formatting = XlCellFormatting.Hyperlink; XlHyperlink hyperlink = new XlHyperlink(); hyperlink.Reference = new XlCellRange(new XlCellPosition(cell.ColumnIndex, cell.RowIndex)); hyperlink.TargetUri = "http://www.devexpress.com"; sheet.Hyperlinks.Add(hyperlink); } } } #endregion #Hyperlinks } }
internal void RaiseFollowHyperlinkEvent(object Target) { if (null == FollowHyperlink) { Marshal.ReleaseComObject(Target); return; } XlHyperlink hl = new XlHyperlink(this, Target); ListChildReferences.Add(hl); FollowHyperlink(hl); }