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

Created Unassigned: Add images to cloned sheets [12518]

$
0
0
I'm using CloneSheet() to clone my first sheet from a workbook (template sheet which has images - e.g. company logo) and then I paste the data in the cloned sheet.

All seems to work ok until I paste images in my cloned sheet - if I paste images into the cloned sheet all the cloned images (company logo) from the original sheet, get deleted or something.. they are not there. and when I open the final xls file - I get an error saying "waring data may have been lost". I've read that there was a bug regarding cloning sheets and the behaviour was: clone sheet with images and the images are not present in the cloned sheet. I've also read in a release note that it has been fixed.
Have you encountered this before ? - I would appreaciate some help . My method for copying images in the cloned sheet is:

```
private void CopyImageToCell(HSSFWorkbook destinationWorkBook, ISheet sheetDestination, ICell destinationCell, string path)
{
int topLeftY = destinationCell.ColumnIndex;
int topLeftX = destinationCell.RowIndex;
destinationCell.SetCellValue("");
HSSFPatriarch patriarch = (HSSFPatriarch)sheetDestination.CreateDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, topLeftY, topLeftX, 10, 10);
anchor.AnchorType = 3;
HSSFPicture picture = (HSSFPicture)patriarch.CreatePicture(anchor, LoadImage(path, destinationWorkBook));
picture.Resize(0.8);
(picture.Anchor as HSSFClientAnchor).AnchorType = 3;
int rowsToAdd = (picture.Anchor as HSSFClientAnchor).Row2 - (picture.Anchor as HSSFClientAnchor).Row1;
sheetDestination.ShiftRows((picture.Anchor as HSSFClientAnchor).Row1, sheetDestination.LastRowNum, rowsToAdd);
}

private int LoadImage(string pathToImage, HSSFWorkbook destinationWorkBook)
{
FileStream file = new FileStream(pathToImage, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[file.Length];
file.Read(buffer,0, (int)file.Length);
return destinationWorkBook.AddPicture(buffer, PictureType.JPEG);
}
```

I'm using the lastest release pf NPOI - 2.0 Beta 1 [v2.0.1] (Feb, 2013) - and excel 2010

Vlad

Viewing all articles
Browse latest Browse all 1621

Trending Articles



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