none
The width and height problem of Shapes.AddPicture parameters RRS feed

  • 질문

  • Hi.

    I am testing my excel automation program in excel 2010.

    The problem is that image size inserted to excel sheet is different from raw image size.

    I think that real image size loaded from Image class and image size on excel sheet is different.

    For example, when I insert image with width 400 and height 400 of Image class on excel sheet, the image on excel sheet becomes more bigger about 600~700 and image itself is blur.

    How can I match two both?

    code is simple.

     object shapes = WorkSheet.GetType().InvokeMember("Shapes", BindingFlags.GetProperty, null, WorkSheet, null);
     shapes.GetType().InvokeMember("AddPicture", BindingFlags.InvokeMethod, null, shapes, new object[] { filename, 0, -1, sleft, stop, swidth, sheight });

    2012년 12월 6일 목요일 오전 4:58

답변

  • I found the solution.

    This link....

    www.spreadsheetgear.com/support/help/spreadsheetgear.net.3.0/SpreadsheetGear~SpreadsheetGear.Shapes.IShapes~AddPicture(String,Double,Double,Double,Double).html

    But I don't know why.

    In addition, I modified a little for accuracy.

    width = (int)((image.Width * 72.0 / image.HorizontalResolution) + 0.5); 
    height = (int)((image.Height * 72.0 / image.VerticalResolution) + 0.5);

    Thank link.


    • 편집됨 over programmar 2012년 12월 6일 목요일 오전 7:30 html tag removed
    • 답변으로 표시됨 Jina LeeModerator 2012년 12월 10일 월요일 오전 6:17
    2012년 12월 6일 목요일 오전 7:30