How to add images (generated by Sheet-to-image feature) into new Excel worksheets using Aspose.Cells APIs

@catalparue,

We are not sure about your issue. Kindly elaborate it with sample Excel files (input file and output file) and sample code (runnable) to reproduce the issue on our end, we will check it soon.

PS. please zip the files prior attaching here.

tempPic.zip (226.0 KB)
hi, please see the Zip File. you can see original excel sheet, output excel sheet. The image we inserted into output excel sheet. The image because very small after inserting to new sheet! We would like the image display as its original size.

_workbook.Worksheets[sheetName].Pictures.Add(0, 0, “C:\TEMP\temp1.TIFF”);

@catalparue,

Thanks for the file(s). We will check and get back to you soon.

@catalparue,
Can you please try to increase height and width scale in percntage with below code and let us know your feedback.

_workbook.Worksheets[sheetName].Pictures.Add(0, 0, “C:\TEMP\temp1.TIFF”,400,400);

hi, yes the image is bigger. However, this need us to manual set the image size. Our image is dynamic generating every time with different content. Hence the length size might be very different. Is there any way Aspose can detect original image size ? Or before Apose saved image from sheet, Aspose can return the size of the image?

@catalparue,

To evaluate your issue precisely, we need your template Excel files (input file and output files with image files, etc.). Also, share your sample code (runnable) on how are you generating image files based Excel sheets via Aspose.Cells APIs. It would be better if you could create a sample console demo application (runnable), zip the project and post us to show the issue (generate images for sheets and insert images in new sheets but images are small in size), we will check it soon.

AsposeImage.zip (206.4 KB)
here you go! I would like the inserted image size look same as original sheet content.
current we need to manual set the size… it might be incorrect since the content might be different!
incorrect Size.PNG (178.2 KB)

@catalparue,
We have noted the issue where all other type of images are added with original size whereas TIFF images are displayed quite smaller than the original size in the output Excel file. This issue is logged into our database for further investigation. You will be notified here once any update is ready for sharing.

This issue is logged as:
CELLSNET-48144 - Height and width scales are not effective for TIFF images in Worksheet.Pictures.Add() function

hi, thanks for the investigation.
I changed to other image format and see how it works.

  1. TIFF => display too small.
  2. GIF => display too big.
  3. JPEG => display ok!

in this case, can I use JPEG for the large image size? will it be any performance issue? is TIFF an ideal choose for bigger image?

@catalparue,
Thanks for the feedback. We will soon share our feedback after investigating this issue.

@catalparue,
This is to inform you that we have fixed your issue now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

SourceFile.zip (259.6 KB)
thanks. Can you please make sure this works?
same sample code as previous attachment. Just change the source code as following…

  1. target sheet to Disclosure2
  2. format changed to Png or JPEG… both image size is incorrect.
  3. using MemoryStream to insert the file.

the inserted picture size will be wrong! Can you please investigate.

        var _workbook = new Workbook("Source\\SourceFile.xlsx");


        Worksheet sheet = _workbook.Worksheets["Disclosure2"];

        ImageOrPrintOptions options = new ImageOrPrintOptions();
        options.HorizontalResolution = 400;
        options.VerticalResolution = 400;
        options.ImageType = Aspose.Cells.Drawing.ImageType.Png;
        options.IsImageFitToPage = true;
        options.IsCellAutoFit = true;
        options.PrintingPage = PrintingPageType.IgnoreBlank;
        options.OnePagePerSheet = true;


        MemoryStream stream = new MemoryStream();
        SheetRender sr = new SheetRender(sheet, options);
        for (int j = 0; j < sr.PageCount; j++)
        {

            sr.ToImage(j, stream);

        }
        _workbook.Worksheets["Target"].Pictures.Add(0, 0, stream);
        _workbook.Save("TargetFile.xlsx");

@catalparue,
We have analyzed this information and have logged it with ticket for further investigation. We will write back here to share our feedback soon.

thanks! let me know when i can get the feedback. :slight_smile:

@catalparue
Please try the latest fix 21.6.1
Aspose.Cells21.6.1 For .Net2_AuthenticodeSigned.Zip (5.5 MB)
Aspose.Cells21.6.1 For .Net4.0.Zip (5.5 MB)
Aspose.Cells21.6.1 For .NetStandard20.Zip (5.5 MB)

@catalparue
1, If ImageOrPrintOptions.OnePagePerSheet is true, all data has to compressed into one page, so the size of generated picture is Letter.
And the page setting(Page Layout -> Size -> More Paper sizes in MS Excel), Fit to one page wide by one tall.
2,It’s better that you can upload an excepted file, then we can check it ASAP.

hi, what is 21.6.1 fix for? is that for ticket CELLSNET-48144?
will it address the issue i mention above?

thanks. Can you please make sure this works?
same sample code as previous attachment. Just change the source code as following…

  1. target sheet to Disclosure2
  2. format changed to Png or JPEG… both image size is incorrect.
  3. using MemoryStream to insert the file.

the inserted picture size will be wrong! Can you please investigate.

hi, I have uploaded everything there! (attachment: SourceFile.zip (259.6 KB)) can you please check!

@catalparue,

Yes, kindly do try v21.6.1 and let us know your feedback.

Also, see details regarding "ImageOrPrintOptions.OnePagePerSheet " in the post (as you specified OnePagePerSheet option to true). In short, when you set this option in code, the image size would be letter.

In case, you still find any significant issue with new fix regarding generated picture’s size, please share an Excel file having the picture with your desired size, we will check it further.

The issues you have found earlier (filed as CELLSNET-48144) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao