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