原創(chuàng)|其它|編輯:郝浩|2012-09-03 14:36:33.000|閱讀 2916 次
概述:Aspose.Cells是怎樣為電子表格添加圖片并為圖片設(shè)置超鏈接的呢?答案就在這里。本文為大家提供了最簡單的代碼來實現(xiàn)圖片鏈接設(shè)置。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Cells是怎樣為電子表格添加圖片并為圖片設(shè)置超鏈接的呢?答案就在這里。本文為大家提供了最簡單的代碼來實現(xiàn)圖片鏈接設(shè)置。OK,下面就讓慧都小編來和大家一起學(xué)習(xí)吧:
[C#]
//Instantiate a new workbook
Workbook workbook = new Workbook();
//Get the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Insert a string value to a cell
worksheet.Cells["C2"].PutValue("Image Hyperlink");
//Set the 4th row height
worksheet.Cells.SetRowHeight(3, 100);
//Set the C column width
worksheet.Cells.SetColumnWidth(2, 21);
//Add a picture to the C4 cell
int index = worksheet.Pictures.Add(3, 2, 4, 3, "f:\\test\\school.jpg");
//Get the picture object
Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index];
//Set the placement type
pic.Placement = PlacementType.FreeFloating;
//Add an image hyperlink
Aspose.Cells.Hyperlink hlink = pic.AddHyperlink("");
//Specify the screen tip
hlink.ScreenTip = "Click to go to Aspose site";
//Save the excel file
workbook.Save("f:\\test\\ImageHyperlink.xls");
[VB]
'Instantiate a new workbook
Dim workbook As New Workbook()
'Get the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Insert a string value to a cell
worksheet.Cells("C2").PutValue("Image Hyperlink")
'Set the 4th row height
worksheet.Cells.SetRowHeight(3, 100)
'Set the C column width
worksheet.Cells.SetColumnWidth(2, 21)
'Add a picture to the C4 cell
Dim index As Integer = worksheet.Pictures.Add(3, 2, 4, 3, "f:\test\school.jpg")
'Get the picture object
Dim pic As Aspose.Cells.Drawing.Picture = worksheet.Pictures(index)
'Set the placement type
pic.Placement = PlacementType.FreeFloating
'Add an image hyperlink
Dim hlink As Aspose.Cells.Hyperlink = pic.AddHyperlink("")
'Specify the screen tip
hlink.ScreenTip = "Click to go to Aspose site"
'Save the excel file
workbook.Save("f:\test\ImageHyperlink.xls")
簡單吧!生成的文件效果圖如下:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:本站原創(chuàng)