C#/vb. NET add a hyperlink to an Excel picture

Source: Internet
Author: User

In the daily work, when editing the document, in order to facilitate their own or boss can be in real time to see the desired page or document, you need to enter the text in Excel hyperlink, then for some of the images inserted in Excel How do we implement hyperlinks, the following to share a method:


first, a quick look at a component called Spire.xls, which is a standalone Excel component released by E-iceblue, has the greatest advantage of not relying on Microsoft Excel, It can be used in various. NET frameworks, including. NET applications related to ASP. Interested friends can on the E-iceblue official website to learn more details, you can also download the free version of Excel components.


Using C # as a hyperlink to a picture in Excel, you can refer to the steps below, where you need to use some code, but you can do it in a few steps:

Step one : Create a workbook, get the First Worksheet

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


Step Two : Add text content within a specific cell

Sheet. Range ("A1"). Text = "Excel picture hyperlink"; sheet. Range ("A1"). Style.verticalalignment = Verticalaligntype.top;

Step three : Insert a picture and add a hyperlink

String Picpath = "C:\\users\\administrator\\desktop\\tupian.jpg"; Excelpicture picture = sheet. Pictures.add (1, 1, picpath);p icture. Sethyperlink ("https://github.com/", true);

Step four : Set the first column width and the first row height

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

Step five : Save the file

Wb. SaveToFile ("Imagehyperlink.xlsx", excelversion.version2013);

The following output results are obtained after the operation is completed :


650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/A4/D4/wKioL1myOauhdxcAAACe85A9mwc950.png "title=" Hyperlinks. png "alt=" Wkiol1myoauhdxcaaace85a9mwc950.png "width=" 720 "height=" 414 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:720px;height:414px; "/> so, to achieve a hyperlink to the picture, just need to complete the above steps on it.

Similarly, in vb.net, you can also implement hyperlinks to Excel images.

The complete code is as follows, for reference:

C#:

Using spire.xls;using system.text;using system.linq;using system.collections.generic;using  system;namespace excel_image_hyperlink {        class  Program {                 private static void main (String[] args)           {            workbook wb =  new workbook ();             worksheet  SHEET = WB. Worksheets (0);             sheet. Range ("A1"). text =  "Excel picture HYPERLINK";             sheet. Range ("A1"). Style.verticalalignment = verticalaligntype.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.net:

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 picture HYPERLINK"             sheet. Range ("A1"). style.verticalalignment = verticalaligntype.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 of some help to you.

Thanks for reading!



C#/vb. NET add a hyperlink to an Excel picture

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.