I will not intentionally post any codes in this question as it is not needed to answer this question, for some reasons I need to set Height and Width of the cells in my worksheet via pixels value and not the standard activeWorksheet.Rows.RowHeight
which accept standard value.
How can I successfully set Height and Width of a cell via pixels? Thanks.
Asked
Active
Viewed 4,199 times
2

FabioEnne
- 732
- 1
- 14
- 43
-
`pixels = points * DPI / 72` could be reversed to `points = pixels / DPI * 72` – Jeremy Thompson Jul 25 '17 at 09:54
-
@JeremyThompson thanks for the reply, where and how I get the DPi? – FabioEnne Jul 25 '17 at 10:04
-
Mate, simply Google "c# get DPI" – Jeremy Thompson Jul 25 '17 at 10:05
-
1@JeremyThompson yes, you are right lol :) – FabioEnne Jul 25 '17 at 10:09
1 Answers
3
The formula:
pixels = points * DPI / 72
can be reversed to:
points = pixels / DPI * 72
This way you can set Row Height using pixels.

Jeremy Thompson
- 61,933
- 36
- 195
- 321
-
But the question is how you set it in Excel Interop: excWorksheet.Columns[1].ColumnWidth = pixels / DPI * 72; is way to many pixels when you put your mouse over the column in excel. – John Kurtz Jan 22 '19 at 22:54
-
@JohnKurtz you're talking about Column width, the question is about RowHeight. – Jeremy Thompson Jan 23 '19 at 03:52
-
Sorry, I just assumed that they would be measured the same way! Any insights on how the Columns Width IS handled? Title asks about height and width. – John Kurtz Jan 23 '19 at 15:15
-
For Arial 10, I found a good approximation to be: excWorksheet.Columns[1].ColumnWidth = 0.14286f * (pixels - 5); – John Kurtz Jan 23 '19 at 16:40