We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cells (.NET) - Incorrect column width

Hello, I have a purchased license.

I want to set exact column width using ‘SetColumnWidthInch’ or ‘SetColumnWidthPixels’. I use the following code to achieve that:

CellsHelper.DPI = 96;

var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];

worksheet.ViewType = ViewType.PageLayoutView;
worksheet.Cells.SetColumnWidthInch(0, 5);
worksheet.ViewType = ViewType.NormalView;


Result is Result - incorrect col width.zip (5.8 KB)

In Excel, result column size is 5.25, but expected to be 5.0 inches.
In LibreOffice Calc, result column size is 5.29, but expected to be 5.0 inches. Same results when i use ‘SetColumnWidthPixels’ method.

It seems like a bug, or I missing something? How to set exact column width?

Could you try to set your Windows DPI to 100% to see if this issue can be fixed?

My Windows DPI is 100% already.


After opening your shared “Result - incorrect col width.xlsx” with Microsoft Excel on my side(DPI is 100%), the width of Column A is 480 pixel, which is 5 inch(=480/96 inch). See screenshot Screenshot_columnWidth.png (16.0 KB)

Thanks for answer. Ok, maybe it somehow depends on my Windows settings (but I don’t figure out yet). However, why I get the same result using the following code:

CellsHelper.DPI = 96;

var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];

worksheet.Cells.SetColumnWidthPixel(0, 480);


result - incorrect col width using setColumnWidthPixel.zip (5.8 KB)

Expected column width - 480 pixels, but actual width is 614
image.png (4.5 KB)


I tried opening your output file on another machine with different MS Excel version, it still works fine. See the screenshot for your reference.
sc_shot1.png (52.6 KB)

Could you check your machine (OS) display settings, it should be “100%”.