Search code examples
excelcopypowerpointscale

How does excel+powerpoint decide to rescale ranges pasted as images?


I've noticed that when you copy a range in excel (copy as a picture - as shown on screen) and paste it into PowerPoint, the resulting image is not scaled 100% to the original image (right click on image, go to format settings and go to size to see scale info).

In addition, this scaling differs on different computers (might be related to graphics card). If you have different versions of Office the scaling also differs per computer (i.e. in Office 03, scaling is 100% of original, in Office 07, Scaling is ~75% of original for both height and width <---these values may differ on your own computer).

Is there some rhyme and reasoning to how these scalings are determined internally by Office? I ask because I am automating this copy+paste feature through c# (using the interop stuff). I use the CopyAsPicture method to get the height x width of the range selected and save the image as an .emf file. I then load the image into a PowerPoint shape using the dimensions I stored earlier as the dimensions of the shape. It pastes it in without an error, but when I compare it to a native ctrl+c and ctrl+v of excel's paste as picture, the size is different. I've concluded it is because of this weird scaling issue.

As an aside, in c#, if you tell some shape to be 100x100 in size, and insert it (using AddPicture method of shapes), it won't actually be 100x100 in PowerPoint. If you then copy and paste that image into paint to see the dimensions, it'll be something entirely different (for my machine, it upscales it by 135%).

Anyone got any idea what is going on? Or how office decides these scaling issues?

Thanks, Shark


Solution

  • I figured out a flaw in my logic: instead of looking at scaling, I should've looked at absolute size. One one of the things I noticed was that regardless of the scaling, the size of the pasted image through the native copy and paste was consistent throughout all the versions of office on all machines. With further analysis, I discovered that the size was determined in two ways:

    1) If you selected "copy as image" with the setting for "as shown on screen", I divided the image's height and width (in pixels) by 96 (dpi) to get the size of the image in inches. I believe this DPI is the default value the Office uses. Then to get it into dots, I needed to multiply this image by 72, since I needed to convert it into the unit that PowerPoint expects on the insert operation. After doing this, the image through my code matched that of the native procedure.

    2) If you had selected "as shown when printed" option, my original method worked as we discussed above using the metafiles resolution's to help get the size.

    Summary:

    For As Shown On Screen

    x = (metafile.height / 96) * 72
    
    y = (metafile.width / 96) * 72
    

    For As Shown When Printed

    x = (metafile.height / metafile.HorizontalResolution) * 72
    
    y = (metafile.height / metafile.VerticalResolution) * 72