Excel Screen Resolution

Hi Team,

I am working on requirement to generate excel reports using aspose. I want to fit in an image in a cell. I have given specific dimensions using SetRowHeightPixel and SetColumnWidthPixel methods. When the generated excel report is opened on different client machines having different display scale and display resolution, it has been noticed that the cell does not have required dimensions in pixels. Is this expected behaviour? Once the report has been generated, does cells pixel varies on the machine’s display scale and display resolution in the which the report is opened?

public void AddImage(byte[] val, Workbook _reportWorkbook, int sheetIndex,int rowNumber,int colNumber) {
MemoryStream ms = new MemoryStream();
ms.Write(val, 0, val.Length);
_reportWorkbook.Worksheets[sheetIndex].Cells.SetRowHeightPixel(rowNumber, ImageCellHeight);
_reportWorkbook.Worksheets[sheetIndex].Cells.SetColumnWidthPixel(colNumber, ImageCellWidth);
var index = _reportWorkbook.Worksheets[sheetIndex].Pictures.Add(rowNumber, colNumber, ms);
Picture pic = _reportWorkbook.Worksheets[sheetIndex].Pictures[index];
pic.Placement = PlacementType.FreeFloating;
pic.IsLockAspectRatio = true;
Cell imageCell = _reportWorkbook.Worksheets[sheetIndex].Cells[rowNumber, colNumber];
SetImagePlacement(imageCell,pic);
}

@Nikhil_Laad
About how to insert picture in cell, please refer to the following document.

Hi John.He,

Thanks for your response. I am not having issues to insert image in cell. I have issues that the cell pixel dimensions changes when I change the screen resolution and screen scale of my machine. Is this expected?
image.png (14.9 KB)

@Nikhil_Laad,

I think this is expected behavior. I seems Excel’s (internal) point-based measurement system, which is not pixel-perfect across devices/machines. So, when you use Cells.SetRowHeightPixel() and Cells.SetColumnWidthPixel(), you’re telling Aspose.Cells to set the height and width in pixels. But when Excel renders the file, it uses points internally, and Excel itself then adapts rendering to the system’s DPI (e.g., 100%, 125%, 150% scaling). Maybe, you could try setting to “move and resize with cells” option.

// Resize image to fit the cell (or a range of cells)
pic.Placement = PlacementType.MoveAndSize; 

Thanks @amjad.sahi for the response !

I have written dedicated methods to set the size and alignment of the image inside the cell. This methods are now deciding the image by column width points and row height points which does not depend on machine resolution and machine scaling.

Can you please confirm if this is a correct statement “column width points and row height points does not depend on machine resolution and machine scaling”.

1 column width point = number of characters that can be inserted with font size 10 and default font-type (typically Arial)

1 row height point = (1/72) inch

@Nikhil_Laad
In the Excel file, the row height is in unit of points, so the height in unit of pixels will be different in different screen resolutions. The column width is in unit of characters, so the width of the column will be auto changed in different screen resolution too. It’s the behavior of MS Excel. If the placement type is FreeFloating, the shape will be moved and keep the size if the screen resolution is changed. If you only want the image to be placed in the whole cell, you can set the placement as MoveAndSize, then it will be fixed in this cell. But if you only set the image as the part of the cell, we cannot get the same view in the different screen resolution.