hi. i m working an excel object by c#. i want to autofit colunms. but like this: i want that columns width is 5 bigger than autofit mehod set. but how can i do this. how can i know width that autofit method set.
+1
A:
Assuming that you are on cell A1 & have long text in it, following code will make the column Autofit and then increase the width by 5 characters.
Selection.Columns.Autofit
Selection.Columns(1).ColumnWidth = Selection.Columns(1).ColumnWidth + 5
shahkalpesh
2009-08-28 07:09:05
+1
A:
If you wish to use Selection and have IntelliSense and early binding, you need to cast the Selection object to a Range first:
Excel.Range selectedRange = (Excel.Range)myExcelApp.Selection;
selectedRange.Columns.AutoFit();
foreach (Excel.Range column in selectedRange.Columns)
{
column.ColumnWidth = (double)column.ColumnWidth + 5;
}
-- Mike
Mike Rosenblum
2009-08-28 16:29:11