Hi,
Try this:
using Microsoft.Office.Interop.Excel;
ApplicationClass NewExcelApplication =
new ApplicationClass();
NewExcelApplication.DisplayAlerts = false;
Workbook book =
NewExcelApplication.Workbooks.Open(@"C:\Book1.xls" ,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Worksheet sheet1 =
(Worksheet)book.Worksheets.get_Item(1);
((Range)sheet1.Columns["C", Type.Missing]).ColumnWidth = 30;
book.Save();
NewExcelApplication.Quit();
Greetings
Martin
"Jim Heavey" <> wrote in message
news:115DD01C-E11B-4F5C-8B23-...
> I am creating an excel file and a I am wanting to set a column with to
> something, say 9.20. When I run the Macro recorder, I get code which
looks
> like the following:
> Columns("C:C").Select
> Selection.ColumnWidth = 8.6
>
> If I create an instance the the Sheet object, I would have expected that I
> could just say...
>
> mySheet.Columns["C:C"].Select
> mySheet.ColumnWidth = 9.20
>
> But it does not seem to like that. I am also guessing that I should not
use
> the "Select", as there is no reason to activate a selection, I believe
that
> this inefficient. What is the proper way to do this... And why is it that
> the code above will not work. I am using C#, so I guess I should be
using
> [] instead of ( ).
>
> Thanks in advance for your assistnace!!!
|