C #/VB. NET add hyperlinks to EXCEL images,

Source: Internet
Author: User

C #/VB. NET add hyperlinks to EXCEL images,

In daily work, in order to make it easier for yourself or the Boss to view the required webpage or document in real time, You Need To hyperlink the text entered in Excel, how can we implement hyperlinks for some pictures inserted in Excel? Here is a way to share with you:

First, let's take a look at Spire. XLS component, which is an independent Excel component released by E-iceblue. Its biggest advantage is that it does not rely on Microsoft Excel and can be used in a variety. NET Framework, including ASP. NET and Windows Forms.. NET application with complete functions and ease of use. If you are interested, you can go to the E-iceblue official website to learn more, or download the free version of the Excel component from this website.

Use C # As a hyperlink to an image in Excel. You can refer to the procedure below. here you need to use some code, but you only need a few steps to complete it:

Procedure:

Step 1: Create a workbook and obtain the first Worksheet

Workbook wb = new Workbook();Worksheet sheet = wb.Worksheets[0];

Step 2: Add text content to a specific cell

Sheet. Range ["A1"]. Text = "Excel image HYPERLINK"; sheet. Range ["A1"]. Style. verticalignment = verticaligntype. Top;

Step 3: insert an image and add a hyperlink

string picPath = @"C:\Users\Administrator\Desktop\tupian.jpg";ExcelPicture picture = sheet.Pictures.Add(1, 1, picPath);picture.SetHyperLink("https://github.com/", true);

Step 4: Set the width of the first column and the height of the first row

sheet.Columns[0].ColumnWidth = 30;sheet.Rows[0].RowHeight = 150;
picture.TopRowOffset = 25;

Step 5: Save the file

wb.SaveToFile("ImageHyperlink.xlsx", ExcelVersion.Version2013);

After the operation is complete, the following output result is displayed:

 

 

Therefore, to achieve a hyperlink to an image, you only need to complete the above steps.

Similarly, in VB. NET, hyperlinks to Excel images can also be implemented.

The complete code is as follows for your reference:

C #:

Using System; using System. collections. generic; using System. linq; using System. text; using Spire. xls; namespace Excel_image_hyperlink {class Program {static void Main (string [] args) {Workbook wb = new Workbook (); Worksheet sheet = wb. worksheets [0]; sheet. range ["A1"]. text = "Excel image HYPERLINK"; sheet. range ["A1"]. style. verticalAlignment = verticaligntype. top; string picPath = @ "C: \ Users \ Administrator \ Desktop \ tupian.jpg"; ExcelPicture picture = sheet. pictures. add (1, 1, picPath); picture. setHyperLink ("https://github.com/", true); sheet. columns [0]. columnWidth = 30; sheet. rows [0]. rowHeight = 150; picture. topRowOffset = 25; wb. saveToFile ("ImageHyperlink.xlsx", ExcelVersion. version2013 );}}

 

VB:

Imports SystemImports System. collections. genericImports System. linqImports System. textImports Spire. xlsNamespace Excel_image_hyperlink Class Program Private Shared Sub Main (ByVal args () As String) Dim wb As Workbook = New Workbook Dim sheet As Worksheet = wb. worksheets (0) sheet. range ("A1 "). text = "Excel image HYPERLINK" sheet. range ("A1 "). style. verticalAlignment = verticaligntype. top Dim picPath As String = "C: \ Users \ Administrator \ Desktop \ tupian.jpg" Dim picture As ExcelPicture = sheet. pictures. add (1, 1, picPath) picture. setHyperLink ("https://github.com/", true) sheet. columns (0 ). columnWidth = 30 sheet. rows (0 ). rowHeight = 150 picture. topRowOffset = 25 wb. saveToFile ("ImageHyperlink.xlsx", ExcelVersion. version2013) End Sub End ClassEnd Namespace

 

I hope this method will be helpful to you.

Thank you for reading!

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.