(C #) Can I programmatically set the XLSX cell to image / image?

I hope to create tables containing some images (embed images from files), and I started watching EPPlus (looks like a big library)

However, it seems that the images are not attached to the cell, but rather to the x, y coordinates.

Is there a way with EPPlus or another way to set the cell in the picture (and then control the cell size?)

Setposition

+5
source share
4 answers

, .Top .Left, .Top .Left . .RowHeight , , .height ( ). .ColumnWidth , - :

myColumn.ColumnWidth = myColumn.ColumnWidth / myColumn.Width * myPicture.Width

, , .ColumnWidth, .

+2

...

, :

Excel . . " ", , , . .

, , .

,

, /.

, pics , .

private static void AddImage(ExcelWorksheet ws, int rowIndex, String imageFile)
{
    ExcelPicture picture = null;
    Bitmap image = new Bitmap(imageFile);

    if (image != null)
    {
        picture = ws.Drawings.AddPicture("pic" + rowIndex.ToString(), image);                
        picture.From.Column = 0;
        picture.From.Row = rowIndex-1;
        picture.SetSize(320, 240);
    }
}
+4

I do not think you can do this in Excel itself; when you add an image to an Excel worksheet, it is a floating object, it is not attached to a specific cell.

+1
source

Found in the documentation EPPLUSshould be possible with setting EditAsto value TwoCell.

picture.EditAs = eEditAs.TwoCell;

"Indicates that the current drawing should be moved and resized to support its bindings for rows and columns (i.e. the object is anchored to the actual from and to the row and column).

0
source

All Articles