Picture Size

Hello,


I’m using Apose.Cells version 7.1.0 and I’m having an issue when inserting an image into a worksheet. The size of the image is affected by the height and width of the cells. Is there a way to prevent this? I have tried setting the Placement Property to Free Floating, but that doesn’t seem to work.

Please advise.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and use the latest version:
Aspose.Cells
for .NET v7.3.2.3


You should add the image and then adjust the row’s and column’s height accordingly.

Please see the code below it inserts a picture inside some cell and adjust the cell’s height and width accordingly.

I have attached the source image, output file and the screenshot for your reference. You can modify this code according to your needs.

C#


public static void AddPicture(Worksheet Sheet, int Row, int Column, int Width, int Height, string PicPath)

{

//Set the height of the first row

Sheet.Cells.SetRowHeightPixel(Row, Height); //height equals to picture height


//Set the width of the first and second column

Sheet.Cells.SetColumnWidthPixel(Column, Width);


//Add a picture inside cell at this row and column

int picId = Sheet.Pictures.Add(Row, Column, PicPath);

     Picture pic = Sheet.Pictures[picId];<br>


//Set the height and width of picture

pic.Height = Height;

pic.Width = Width;

}


public static void Run()

{

//Create a workbook

Workbook workbook = new Workbook();


//Access first sheet

Worksheet worksheet = workbook.Worksheets[0];


//Add a picture inside a cell

     AddPicture(worksheet, 4, 4, 300, 200, @"f:\downloads\image-koala.jpg");<br>


//Write the output

workbook.Save(@“f:\downloads\output.xlsx”, SaveFormat.Xlsx);

}


Screenshot & Source Image: