"SetViewColumnWidthPixel" results in wrong width

I use “SetViewColumnWidthPixel” in combination with “sheet.ViewType = ViewType.PageLayoutView” to set a centimeter width to cell columns - see thread https://forum.aspose.com/t/setcolumnwidthinch-issue/226518/4

A customer reported a bug: sometimes, the column widths are much smaller than expected. After a reboot, the error is gone. The same has happened some days ago for the same customer. I don’t know whether the report worked first and then started showing wrong results, or whether it was broken since the computer was started.

Our code uses only fixed values to convert the millimeter width to pixel, so there is nothing which could change:

ViewType viewTypeOriginal = workSheet.ViewType;
workSheet.ViewType = ViewType.PageLayoutView;
workSheet.Cells.SetViewColumnWidthPixel (column, millimeter / 10) * 0.39370 * 96)
workSheet.ViewType = viewTypeOriginal;

Do you have any idea what could cause this? Do you rely on any operating system information that might have changed in this situation?

I use version 21.4.0.0.

Best regards

Wolfgang

@wknauf,

It looks strange to us as the error occurs seldom (not very often) which you pointed out. What is the display settings of your os, does it change when it is restarted? Aspose.Cells works fine if your display settings of the os is 100% (100% DPI setting of the machine).

If you still think it is an issue with the APIs, kindly do share more details about the issue, sample code (runnable) and sample Excel file(s)(if any) with steps details to reproduce the issue on our end. Also, share your OS details and .NET framework version. We will check it soon.

I know that the machine still has Win7, but will be replaced soon. The display scale seems to be 100%.

I fear there is no chance to create a sample to reproduce it, as it happens rarely. And in the moment when it happens, the user would have to stop work and call me to create/test a sample app. That’s difficult to coordinate.

Hopefully, the new computer with Win10 will not have this problem. If it still occurs, I will reopen this post. I hoped that you would say something like “this is a know issue, do this and that to fix it” ;-).

Best regards

Wolfgang

@wknauf,

Yes, hopefully your issue won’t occur on upgraded Windows. And, sure, you may reopen this thread with more details, samples and findings if you still find the issue.

Sorry, but we did not find such an issue from other users before, so, it is not a known issue. Anyways, we would love to fix if this is an issue with the APIs. Also, we will discuss with other developers and let you update if anything is relevant or helpful to you.

To “finalize” this post:
I think I found the reason: Excel sometimes (randomly?) seems to pick a smaller zoom factor than 100% when opening the document, and does not downscale the cell font properly. Thus, the column width appeared to be too small because the text was clipped, but the issue was that excel rendered the font too large and thus wrapped/clipped the text.

So, it was probably only a view issue and not related to Aspose.Cells. But I could not check it on the user machine before.

@wknauf,

Thanks for sharing your findings.
And, yes, it might be due to Excel’s view issue on its own and not related to Aspose.Cells APIs.

Should you have further queries or issue, feel free to write us back.