This project has moved and is read-only. For the latest updates, please go here.

How to set column width in excel?

Apr 17, 2013 at 3:21 PM
Edited Apr 17, 2013 at 4:02 PM
Does anyone know a convenient function how to set the column width of each column in the worksheet? If possible dpi-aware :) I want to set the column with pixels. E.g. 18pixels for column 1
Apr 17, 2013 at 3:45 PM
I have found a formula but not tried it
width = Truncate([{Number of Characters} * {Maximum Digit Width} + {5 pixel padding}] / {Maximum Digit Width} * 256) / 256
Apr 17, 2013 at 4:28 PM
Edited Apr 17, 2013 at 4:28 PM
Try the AutoFit()
foreach (Excel.Worksheet sheet in workbook.Sheets)
                    foreach (Excel.Shape shape in sheet.Shapes)
It will put itself the size that it requires and you don't need to manually do any calculations.