473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Excel Column Width

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!!!
Nov 18 '05 #1
1 6547
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" <Ji*******@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
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!!!

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
0
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading...
3
by: implicate_order | last post by:
Greetings, I'm new to python and am in the process of writing a script to parse some CSV data, spread it across multiple Excel worksheets and then generate charts. I searched the internet to...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
2
by: RP | last post by:
I am exporting certain records to Excel 2007 using C# code. I want to adjust the cell width accordingly so that when the record gets transferred to a cell, it is clearly visible. I want to...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
by: JRough | last post by:
Hi, I have a page with a form that is included into a php page. It has some php variables which are headers based on the user choices. In the form I will send some mysql data columns but right...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.