C# problem with Range.Top RRS feed

  • Question

  • Hi all,

    I am trying to create a little program which creates images and insert them into Excel.

    First I create all the rows and set their height, let's say to 82. Then I insert images and set their height to the height of the cell.

    This works fine. What does not work fine is the placement of the image on the cell : depending on the height of the cell, the images stagger little by little to the back or to the top. For example the 100th image will be staggered by half the height of a cell to the top or to the bottom.

    Any idea ?


    Here is the code : 

    Microsoft.Office.Interop.Excel.Range oRange = _oSheet.get_Range(range);
                // Left and Top of the range
                double left = (double)oRange.Left;
                double top = (double)oRange.Top;

                double lrgImage = 100; // Actually it is a computed value

                double htImage = 82; // Actually it is a computed value

    Microsoft.Office.Interop.Excel.Shape shapeExcel = _oSheet.Shapes.AddPicture(imagePath, MsoTriState.msoFalse, MsoTriState.msoCTrue, (float)left, (float)top, (float)lrgImage, (float)htImage);

    Monday, March 25, 2019 2:45 PM