Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Excel Column Width

Reply
Thread Tools

Excel Column Width

 
 
=?Utf-8?B?SmltIEhlYXZleQ==?=
Guest
Posts: n/a
 
      10-11-2004
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!!!
 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      10-11-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!!!



 
Reply With Quote
 
 
 
 
rightsideofwrong rightsideofwrong is offline
Junior Member
Join Date: Oct 2010
Posts: 1
 
      10-11-2010
@Martin: It solved my problem as well.. Spot on!
 
Reply With Quote
 
qvo178 qvo178 is offline
Junior Member
Join Date: Aug 2008
Posts: 29
 
      10-20-2010
Thanks. excellent work.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically Resize Gridview Width Property (NOT Column Width) Hartman_Ralph@Hotmail.com ASP .Net 0 06-02-2009 03:59 PM
picture width decides table column width David Basford HTML 3 09-30-2007 10:49 PM
fixed-width column and variable-width columns mixed ssk HTML 5 10-30-2006 07:50 AM
Textbox width scaling to width of data not width of page? AndrewF ASP .Net 1 10-10-2005 04:38 PM
DG Column Width vs Table Column Width Carl Howarth ASP .Net Datagrid Control 1 10-24-2004 08:48 AM



Advertisments