Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

Created Unassigned: NPOI Adding Images to xlsx using XSSFWorkbook [13849]

$
0
0
Hi All.

I am trying to insert multiple images into a single spreadsheet but I am having a couple of issues as follows:

* Although I'm setting the anchor type as DontMoveAndResize you can still move and re-size the image.
* Random images are dropping\not showing on the resulting spreadsheet.

I can't post all my code but below is the section (which is in a loop) where I'm added the images to the workbook. I'm using Version 2.1.3 of NPOI as this was the latest stable version when I started development.

Any help would be appreciated as I'm fairly new to NPOI.

CODE c#
//Insert the image into the cell
int pictureIndex;
//Read the image into memory
FileStream inputStream = new FileStream(cellparams["Content"], FileMode.Open,FileAccess.Read);
byte[] bytes = IOUtils.ToByteArray(inputStream);
pictureIndex = xssfworkbook.AddPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG);

//Close the image file
inputStream.Close();

//create drawing and achor objects
XSSFCreationHelper helper = (XSSFCreationHelper)xssfworkbook.GetCreationHelper();
XSSFDrawing drawing = (XSSFDrawing)thisSheet.CreateDrawingPatriarch();
XSSFClientAnchor anchor = (XSSFClientAnchor)helper.CreateClientAnchor();

//Anchor the image to the current row and column
anchor.Col1 = currCell;
anchor.Row1 = currRow;

//set the anchor type so that the image can't be moved or resized
anchor.AnchorType = (int)AnchorType.DontMoveAndResize;

//Create the drawing partriarch
XSSFPicture pict = (XSSFPicture)drawing.CreatePicture(anchor, pictureIndex);

//Resize the image to it's actual size
pict.Resize();

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>