Hi,
Hi Jay,
Thank you for using Aspose products, and welcome to Aspose.Cells support forum.
I would like to address your concerns in prescriptive of Aspose.Cells API. Your provided code snippet to insert a picture in spreadsheet cells seems to be fine. Although you may also require some additional settings for placing the picture as elaborated in below linked detailed technical article.
http://www.aspose.com/docs/display/cellsnet/Adding+Pictures
If you are exporting the same spreadsheet (with picture) to PDF format then you will not require Aspose.Pdf for .NET API. Recent releases of Aspose.Cells for .NET has improved a lot, and now you can convert the spreadsheets to PDF format with ease and high visual fidelity while using only Aspose.Cells APIs. Please check the following documentation link for your reference, and give a try to the latest version of Aspose.Cells for .NET 7.7.2.2 on your end.
http://www.aspose.com/docs/display/cellsnet/Converting+Excel+to+PDF+Files
In case you have a different scenario that requires Aspose.Pdf API then please post the related questions in Aspose.Pdf support forum for quick turnaround.
Hi Babar,
I checked in the link that you mentioned for Aspose.Cells API , and tried with all the available options in that link:
Adding Pictures based on :Upper Left Row Index and Upper Left Column Index and filename
Proportional PositioningAbsolute Positioning
Inserting a Picture based on Cell Reference and also with all the available options like setting some fixed height and width for the picture object as well. ( code snippet is added below). but still I am facing the same issue. Please help.
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
sheet.Pictures[picIndex].Height = 94;
sheet.Pictures[picIndex].Width= 175; AND all the available options in
sheet.Pictures[picIndex].
Thanks,
Jay
Hi Jay,
I’m sorry to know that previous discussion didn’t help for your situation. In order to move forward with our investigation, I would request you to please provide the sample spreadsheet containing all the mentioned images and the resultant PDF file, both generated with Aspose.Cells for .NET API. Please provide the said images separately as well so we could thoroughly evaluate the presented scenario on our end, and log appropriate tickets if required.
Thank you for your cooperation and understanding.
Hi Babar,
Please find the attachment for the sample files and images.
Please provide us a generic setting which works for all the images.
Thanks,
Jay
Hi Jay,
Thank you for providing the requested images, and sorry for a bit delayed response.
I have worked with your provided images and encountered the same problem as discussed in this thread. The image (FAS8060.png) seems to have same dimensions as of other images but it does not fit well unless resized (set picture height and width) using the Aspose.Cells for .NET API. I am further looking into this matter before logging an appropriate ticket for thorough investigation.
In the meanwhile, you can opt to resize the image after inserting it in the worksheet. Please check the below code and attached output files for your reference.
C#
var book = new Workbook(myDir + “ControllerSpecifications.xls”);
//Get the first worksheet
var worksheet = book.Worksheets[0];
//Declare variables to store static size
var height = 95;
var width = 175;
//Add a picture to the B2 cell
int index = worksheet.Pictures.Add(1, 1, myDir + “FAS6220.png”);
//Get the picture object
Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index];
//Resize the picture
pic.Height = height;
pic.Width = width;
//Add a picture to the C2 cell
index = worksheet.Pictures.Add(1, 2, myDir + “FAS6290.png”);
//Get the picture object
pic = worksheet.Pictures[index];
//Resize the picture
pic.Height = height;
pic.Width = width;
//Add a picture to the D2 cell
index = worksheet.Pictures.Add(1, 3, myDir + “FAS8060.png”);
//Get the picture object
pic = worksheet.Pictures[index];
//Resize the picture
pic.Height = height;
pic.Width = width;
//Save the Excel file
book.Save(myDir + “picture.xlsx”);
//Save the PDF file
book.Save(myDir + “picture.pdf”, SaveFormat.Pdf);
Hi Babar,
Thanks a lot for the above code snippet. I have another issue with it. I have some more images with 175 X 48 resolution which needs to be displayed in the same row along with the sample images that I provided. Currently I am looping through all the images and adding them to the cell. Not as adding individual image and setting it’s dimensions.
So if I set the, var height = 95;
var width = 175; variables and assign them to pic object like
pic.Height = height;
pic.Width = width; , The images with dimension 175 X 48 will lose their aspect ratio and look distorted. (attached the FAS2240-2.png image with dimensions 175X48 and the sample excel file with expected way )
Is there any generic way where we could resolve the issue without hard coding the image height and width properties. ?
Please help.
Thanks,
Jay
Hi Jay,
First of all, please accept my apology for a bit delayed response.
The code snippet provided in my previous post was in reference to your previously shared images. This is actually a workaround for the situation when same sized images appear differently when injected in spreadsheet. Unfortunately, the code snippet will not work with your recently shared image because it has different dimensions as compared to other images, therefore after insertion it may appear distorted. Further more, I have worked to find a common settings/configurations to inject images of different size in spreadsheet without applying skew or scale. I am afraid, I wasn’t able to come up with a solution, and I believe no such settings could be accomplished. You may have to resize the images or crop them accordingly, whereas the later option will lead to loss of visual data.
I have logged an investigative ticket (CELLSNET-42435) in our bug tracking system regarding the original issue where similar sized images are appearing differently in spreadsheets/PDF. I have also requested the development team to check your recent concerns, and if possible share a solution. Please spare us little time to check the issue thoroughly on our end.
Hi Babar,
I have attached 2 images with same dimensions (175 X 94) but with different DPI .The image with 300 DPI is working fine in both pdf/excel, whereas the image with 72 DPI fails to work in both.
I hope this might help you to investigate the issue at the earliest. Please update me the exact issue that’s causing the image to overflow out of cells.
Thanks,
Jay
Hi Jay,
Thank you for providing more samples.
I have verified the samples on my end, and have attached them to the ticket (CELLSNET-42435) already associated with this thread. Unfortunately, the ticket hasn’t been analyzed yet but it is in the queue with other tasks and hopefully we will check it soon. As soon as we have some updates in this regard, we will post here for you kind reference. In the meanwhile, you may use the workaround shared earlier in this thread to insert similarly sized images in the spreadsheet.
Hi,
We have evaluated your issue further. Well, Aspose.Cells works same as MS Excel. For confirmation, please insert the FAS6220.png, FAS6290.png, FAS8060.png images to an Excel file in MS Excel, you will get the similar results. The original width and height of the pictures are in unit of points in MS Excel, so if the resolution of the pictures are different, each picture’s width and height will be different too.
Thank you.