Once we put some value in cell and then calculating the width in pixel with GetWidthOfValue it is not matching with GetColumnWidthPixel.
For instance, a particular column width comes 320 px and the cell (in same column) containing the value has width as 305 px. There is a mismatch in values. Please help me in understanding the variations and provide some fix.
@DivyanshuSrivastava31
Cells.GetColumnWidthPixel (11) obtains the width of the L column under column style. And cells[“L15”].GetWidthOfValue() obtains the text width measured under the current cell font for the text in cell L5. If you display the monitor at 100% scale, you can see that the right side of the text and the right side of the cell are not aligned, and there is a certain deviation.
Hi @John.He ,
I am attaching the excel sheet and it is based on standard 100% scale.
The observation made while debugging was-
a) After inserting value in Cell[L15] For Font: Calibri and Size: 14 the Cells.GetWidthOfValue() = 312 px
b) The width of Column L in pixels comes as GetColumnWidthPixel() = 312 px
Expectations:
Since the value inserted in Cell[L15] completely accommodate the Cell then ideally the Cell.GetWidthOfValue() should be same as Cell.GetColumnWidthPixel().
Reason
ColumnWidthInPixel() gives the width of the specified column in units of pixel. In this case it comes as 305 px but i am able to insert the values in cell thus Cell.GetWidthOfValue() gives 315 px. Ideally when the cell is acquired with the full capacity both ColumnWidthInPixel and GetWidthOfValue should match.
Please Help
DummySheet2.zip (11.3 KB)
@DivyanshuSrivastava31
When I opened your sample file in Excel 2016 and set the zoom ratio of the display to 100%, I could observe that the text in cell L15 exceeded the right boundary of column L. Please refer to the attachment (27.2 KB).
Can you please help me in understanding about the zoom ratio that you mentioned?
Is it referring to excel or the Display resolution?
@DivyanshuSrivastava31 ,
When both the zoom level of excel and display resolution are 100%, L15’s content exceeds column L. That means the width of value for L15 is greater than column width of L. If you find different result in ms excel with the same condition(100% for zoom level and display resolution), please provide us the screenshot and we will investigate further.
Keeping the same L15 content, which is 24 Qs, there are two observations below:
100% for zoom level and 100% for Display Resolution
Cells.GetWidthOfValue(): 312 px
100% for zoom level and 125% for Display Resolution
Cells.GetWidthOfValue(): 312 px
In both cases the same result of width is obtained. The Display resolution is altered though so we expect in the change of width value, please help
See the image (attached), we attached it previously.
ressult.png (27.2 KB)
Your expectations and assumptions are wrong. Please note, Cell.GetWidthOfValue() attribute will give you the width of the content/value independently, irrespective of what the column width is. You can clearly see (in MS Excel) that some part of the text has extended/crossed and is beyond column’s width boundary (which 305px), so the returned value (of the method) will be greater than column’s width (Cell.GetColumnWidthPixel()).
That thing is already conveyed by @John.He and @johnson.shi. Please read the conversation we had and based on the given info i had shared some latest observations.
Keeping the same L15 content, which is 24 Qs, there are two observations below:
100% for zoom level and 100% for Display Resolution
Cells.GetWidthOfValue(): 312 px
100% for zoom level and 125% for Display Resolution
Cells.GetWidthOfValue(): 312 px
In both cases the same result of width is obtained. The Display resolution is altered here so help me in understanding on Cells.GetWidthOfValue() behaves.
Could you share what should be expected stats when zoom level and display resolution are altered? We can check it further.
@DivyanshuSrivastava31
Calculating the width of value for different zoom values are complicated. Currently we can only support to calculate them for the zoom of 100%. We may investigate the rules of other zoom values later, but we are afraid it cannot be supported in near future.
@johnson.shi
Ok, thanks a lot for your help. If there is something which can help in measuring the cell width with respect to other Display resolution, please let us know.
@DivyanshuSrivastava31
Sure, we will share findings or the update here when we get progress on it. Thank you for your understanding.