Free Support Forum - aspose.com

Positioning picture properly inside cells that use merge and center

I am using the .net version 17.7 currently.

I am inserting a small graphic of a signature into a set of cells within an excel “template”. The template group of cells has a border, and is centered across the 2 cells that the graphic is being inserted into.

Currently the inserted graphic is left aligned within the first cell, and sits on top of the cell border.
There must be a few steps I can use to fix this. Here is the basic code right now

ws is the worksheet

It is reszing down to 20 % of the original graphic size

    idx = ws.Pictures.Add(row, col, filename, 20, 20)

It is sizing correctly, but how do I get it to position itself correctly within the merged cells and not sit on top of the cellborder?

@durhamcas,

Thanks for your query.

Please share your sample file and code snippet with us for our testing. We will reproduce the problem and provide our feedback after analysis.

This is the test code, the image inserts properly regardless of whether or not any of the range content is included, so its all commented out below. What appears to happen is that the image sits in front of the borders on the z axis. What I want to do is scale the picture to fit within the range, and have the original range borders still visible. Any help is appreciated

    '        Dim rn As Aspose.Cells.Range = ws.Cells.CreateRange(2, 2, 6, 4)
    ' Height is number of columns
    ' Width is number of rows
    ' ScaleRatio is percentage of the original picture size

    Dim idx As Integer

    idx = ws.Pictures.Add(toprow - 1, Leftcol - 1, strFile, scaleratio, scaleratio)

    '        Dim pic As Aspose.Cells.Drawing.Picture = ws.Pictures(idx)

    '''Dim rn As Aspose.Cells.Range = ws.Cells.CreateRange(toprow - 1, Leftcol - 1, height, width)

    '''rn.Merge()

    '''Dim RNStyle As Aspose.Cells.Style = ws.Cells(toprow - 1, Leftcol - 1).GetStyle
    ''''        RNStyle = wb.Styles(wb.Styles.Add())

    '''RNStyle.HorizontalAlignment = Aspose.Cells.TextAlignmentType.Right

    ''''        RNStyle.SetBorder(b
    '''rn.SetStyle(RNStyle)
    ''''        PictureCell(toprow, Leftcol, strFile, scaleratio, ws)

    '''If blnBorder = True Then
    '''    rn.SetOutlineBorder(Aspose.Cells.BorderType.TopBorder, 1, Color.Black)
    '''    rn.SetOutlineBorder(Aspose.Cells.BorderType.LeftBorder, 1, Color.Black)
    '''    rn.SetOutlineBorder(Aspose.Cells.BorderType.RightBorder, 1, Color.Black)
    '''    rn.SetOutlineBorder(Aspose.Cells.BorderType.BottomBorder, 1, Color.Black)
    '''End If

@durhamcas,

Thank you for providing us the code snippet but we are not able to observe the exact issue using it. Please share a simple console application(runnable) along with the template Excel file, sample image which is being inserted into the Excel file and program output at your end using latest version Aspose.Cells for .NET 18.11.0. You may provide us the expected output Excel file which is created using MS Excel for our comparison with the program output. A comparison image will also be helpful which shows differences between the actual output and expected output file.