C# 在NPOI中添加指向图像的链接
我使用NOPI生成Excel文件,并使用以下代码将图像添加到Excel:C# 在NPOI中添加指向图像的链接,c#,npoi,C#,Npoi,我使用NOPI生成Excel文件,并使用以下代码将图像添加到Excel: //the drawing patriarch will hold the anchor and the master information HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch(); //store the coordinates of which cell and where in the cell the ima
//the drawing patriarch will hold the anchor and the master information
HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
//store the coordinates of which cell and where in the cell the image goes
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, 0, startRow, 1, startRow + 1);
//types are 0, 2, and 3. 0 resizes within the cell, 2 doesn't
anchor.AnchorType = 2;
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData(GetProductImage(manufacturerId, photoName));
//add the byte array and encode it for the excel file
int index = hssfworkbook.AddPicture(imageBytes, PictureType.JPEG);
HSSFPicture signaturePicture = (HSSFPicture)patriarch.CreatePicture(anchor, index);
这是工作得很好,但我现在还需要添加一个链接到这些图片,以便用户可以下载更大的版本
有人能够做到这一点吗?我担心HSSF的实施不可能做到这一点。afaik,您只能向单元格添加超链接。但是,它可以通过形状、超链接和与
NPOI
officeopenxml实现(XSSF)的关系来实现(请参见)。不过,Excel二进制格式规范支持它们。请参阅第921页的“VtHyperlink的应用程序数据”一节,了解如何执行此操作。您可以基于NPOI
创建自定义类来添加此功能。