Resize image after pasting into excel sheet

I want to resize an image after pasting it on an excel sheet. I insert the image as follows:

Excel.Pictures p = myWorkSheet.Pictures(System.Type.Missing) as Excel.Pictures; Excel.Picture pic = null; pic = p.Insert(path + pic_name + ".png", System.Type.Missing); pic.Left = Convert.ToDouble(picPosition.Left); pic.Top = picPosition.Top; 

I tried resizing the image before pasting, but it lost quality.

+4
source share
1 answer

Solved !!! I just added the following three lines to the code above:

 pic.ShapeRange.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoCTrue; pic.ShapeRange.Width = 170; pic.ShapeRange.Height = 170; 

So now it looks like this:

 Excel.Pictures p = myWorkSheet.Pictures(System.Type.Missing) as Excel.Pictures; Excel.Picture pic = null; pic = p.Insert(path + pic_name + ".png", System.Type.Missing); pic.ShapeRange.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoCTrue; pic.ShapeRange.Width = 170; pic.ShapeRange.Height = 170; pic.Left = Convert.ToDouble(picPosition.Left); pic.Top = picPosition.Top; 

and it works great.

+1
source

Source: https://habr.com/ru/post/1439383/


All Articles