Camera feature

do you have the equivalent of excel camera feature?


I need to convert part of worksheet to image.


Hi,


Thank you for contacting Aspose support.

You can use the SheetRender class to convert a range of cells to image format. Please check the following article elaborating the usage.

thank

unfortunately one issue with SheetRender.
the image is larger than original.

I try to modify WidthScale but with no effect


my code

sheet.PageSetup.PrintArea = “A1:” + CellsHelper.CellIndexToName(sheet.Cells.MaxDisplayRange.RowCount-1, sheet.Cells.MaxDisplayRange.ColumnCount-1);

sheet.PageSetup.LeftMargin = 0;
sheet.PageSetup.RightMargin = 0;
sheet.PageSetup.TopMargin = 0;
sheet.PageSetup.BottomMargin = 0;
sheet.PageSetup.FooterMargin = 0;
sheet.PageSetup.BottomMargin = 0;
sheet.PageSetup.ClearHeaderFooter();

ImageOrPrintOptions options = new ImageOrPrintOptions();
options.OnePagePerSheet = true;
options.ImageFormat = ImageFormat.Bmp;
SheetRender sr = new SheetRender(sheet, options);

MemoryStream lg = new MemoryStream();
sr.ToImage(0, lg);
sheet2.Pictures.Add(0, 1,sr);
sheet2…Pictures[0].WidthScale = 75;

Hi,

Thanks for your posting and using Aspose.Cells.

Please change this code

sheet.PageSetup.PrintArea = “A1:” +
CellsHelper.CellIndexToName(sheet.Cells.MaxDisplayRange.RowCount-1,
sheet.Cells.MaxDisplayRange.ColumnCount-1);

to the range of cells like this

sheet.PageSetup.PrintArea = “A1:C3”;

And it will now convert only A1:C3 into an image.

If your problem still occurs, then please provide us your source Excel file which you are converting to image. We will look into it and help you asap.

Hi,


I must use CellsHelper.CellIndexToName(sheet.Cells.MaxDisplayRange.RowCount-1, sheet.Cells.MaxDisplayRange.ColumnCount-1);
as I need to calculate the print area with this formula.

anyway the print area is correctly render. the problem is only with the quality as the image is more larger than the original

Hi,


Thank you for writing back.

We need your sample spreadsheet to properly evaluate the presented scenario and to investigate the cause of scaled image as discussed in your post. It would be of great help if you can share the spreadsheet along with the image generated on your end for our review.

Hi,


Thank you for providing the sample spreadsheet for our testing.

SheetRender class renders the cell range to slightly enlarged image. however it is the expected behavior. You may avoid this situation by setting the scale size while adding the image to another worksheet. Please check the following piece of code for better elaboration.

C#

ImageOrPrintOptions options = new ImageOrPrintOptions();
options.OnePagePerSheet = true;
options.ImageFormat = ImageFormat.Emf;
SheetRender sr = new SheetRender(sheet, options);
sr.ToImage(0, “D:/output.emf”);
Worksheet sheet2 = book.Worksheets[1];
sheet2.Pictures.Add(0, 1, “D:/output.emf”, 75,75 );
book.Save(“D:/output.xlsx”);

In above provide code snippet, the ImageFormat is set to EMF in order to get the best quality image. Moreover, the code is writing the image on disc and then using the same file to add a picture to another worksheet. You may change the aforesaid settings according to your application requirements. Most important point is the overloaded version of Picture.Add method that accepts the scale parameters (last 2 integer type values) using which you can set the desired scale for the newly inserted image.

Please note, we are performing all tests using the latest version of Aspose.Cells for .NET 8.3.2.2. In case you are not getting the expected results with your current version of the API, we would suggest you to test the case with latest version.

perfect, thank

Hi,


It is good to know that you are up & running again. Please feel free to contact us back in case you need our further assistance with Aspose APIs.