How to insert image into excel camera?

My task is to put the image from the URL in a specific cell on an excel sheet. I am using NetOffice with C # for this.

My main problem is that I cannot find a way to insert the image exactly into the cell. When I use Sheet.Shapes.AddPicture (), I have to calculate the coordinates where to place the image. Of course, I have no problems with this (I created some kind of workaround), but I would like to ask if my approach to solving this problem is suitable or if there is some other method in which I could insert the image into the cell.

Here is my way:

var floatLeft = FloatLeftPixelsCalculation(rowNumber);
var floatTop = FloatTopPixelsCalculation(rowNumber);
Worksheet.Shapes.AddPicture(urlCellValue, MsoTriState.msoFalse, MsoTriState.msoTrue, floatLeft, floatTop, PictureWidth, PictureHeight);

public float FloatTopPixelsCalculation(int rowNumber)
        {
            float floatTop = 0;
            for (var rNumber = 1; rNumber < rowNumber; rNumber++)
            {
                var cellHeight = Convert.ToSingle(Worksheet.Cells[rNumber, ColumnIndex].RowHeight);
                floatTop = floatTop + cellHeight;
            }

            return floatTop;
        }

        public float FloatLeftPixelsCalculation(int rowNumber)
        {
            float floatLeft = 0;
            for (var columnNumber = 1; columnNumber < ColumnIndex; columnNumber++)
            {
                var cellWidth = Convert.ToSingle(Worksheet.Cells[rowNumber, columnNumber].ColumnWidth);
                floatLeft = floatLeft + cellWidth;
            }

            return floatLeft;
        }
+5
source share
1 answer

, , Excel , "" , , .

, , . A-Y , Z - . , , , , , .

Excel , :

  • . , , , , .

  • shape.Placement xlMove, xlMoveAndSize. MS, : xlFreeFloating (3) Object is free floating. xlMove (2) Object is moved with the cells. xlMoveAndSize (1) Object is moved and sized with the cells.

, .Placement xlMove xlMoveAndSize, , , . .Placement xlMoveAndSize, . , , . xlMoveAndSize, ShapeRange.LockAspectRatio = msoTrue, .

, , , . , .

+1

All Articles