How to Copy as Picture - As shown when printed in Aspose

Hi,



In Excel, when selecting a range of cells, we’ve got an option in the “Copy” button to select a simple “Copy” or “Copy as Picture”. When clicking on “Copy as Picture”, there will be a option dialog allowing user to select the picture is “As shown on screen” or “As shown when printed”. These two options will produce pictures in different size (but all in .emf format), you could find the difference in my screenshots. Looks like “As shown on screen” depends on screen’s DPI while “As shown when printed” does not.



I could see Aspose.Cells renders image in the same size as “As shown on screen” option, but there are cases where the size of “As shown when printed” is needed and it is important. Could you please tell me how to use Aspose to achieve this “Copy as Picture - As shown when printed” function in Excel?





Thanks

Hi John,


Thank you for contacting Aspose support.

You can control the rendering using the ImageOrPrintOptions class as demonstrated below.

C#

Workbook wb = new Workbook(“d:/temp/test.xlsx”);
Worksheet sheet = wb.Worksheets[0];
PageSetup pageSetup = sheet.PageSetup;
//the cell area that you want to copy
pageSetup.PrintArea = “B4:D7”;
//set margins to zero
pageSetup.TopMargin = 0;
pageSetup.LeftMargin = 0;
pageSetup.RightMargin = 0;
pageSetup.BottomMargin = 0;

ImageOrPrintOptions shownAsOnScreenImgOpt = new ImageOrPrintOptions();
shownAsOnScreenImgOpt.ImageFormat = ImageFormat.Png;
shownAsOnScreenImgOpt.OnlyArea = true;
SheetRender showAsOnScreenSr = new SheetRender(sheet, shownAsOnScreenImgOpt);
showAsOnScreenSr.ToImage(0, “d:/temp/testAsOnScreen.png”);

ImageOrPrintOptions shownAsWhenPrintedImgOpt = new ImageOrPrintOptions();
shownAsWhenPrintedImgOpt.ImageFormat = ImageFormat.Png;
shownAsWhenPrintedImgOpt.OnePagePerSheet = true;
SheetRender showAsWhenPrintedSr = new SheetRender(sheet, shownAsWhenPrintedImgOpt);
showAsWhenPrintedSr.ToImage(0, “d:/temp/testAsWhenPrinted.png”);