0

I am using NOPI to generate Excel files and I am adding images to the Excel using the following code:

//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);

This is working well but I now also need to add a link to those images so users can download larger versions.

Anyone able to accomplish this?

Slee
  • 27,498
  • 52
  • 145
  • 243
  • I'm afraid this isn't possible with the HSSF implementation. You can only add hyperlinks to cells, afaik. It can be done with shapes, hyperlinks and relationships with the `NPOI` Office Open XML implementation (XSSF) however (see [SO post](http://stackoverflow.com/questions/16891714/how-to-add-hyperlink-to-excel-simple-shape-using-apache-poi)). – Genti Saliu Feb 19 '16 at 11:58
  • The Excel binary format specification supports them, though. See page 921, section *Application Data For VtHyperlink* of the [Excel Binary File Format (.xls) Structure](https://msdn.microsoft.com/en-us/library/office/cc313154(v=office.12).aspx) to see how it can be done. You could create custom classes based off `NPOI` to add this functionality. – Genti Saliu Feb 19 '16 at 12:24

0 Answers0