Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 10th, 2007, 09:21 PM
Authorized User
Points: 83, Level: 1
Points: 83, Level: 1 Points: 83, Level: 1 Points: 83, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel Interop Issue


I need to open an Excel file using Interop, resize a column and then save the file, insuring that the worksheet retains the newly resized column width. As I step through the code all is working fine. But when I reopen the file the new column width has not been saved. If I open the file manually, resize the column, then save, the file retains the new column width. Any suggestions? I should also add that I tried reading the column width after the AutoFit was called and then explicitly set the column width to that value, then I saved the file This also did not work.

Here is the code I used. I have done this in Winforms.

Thanks for your help.

using Excel=Microsoft.Office.Interop.Excel;

namespace ExcelWindowsTest
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, System.EventArgs e)
            Excel.Application excel;
            Excel.Workbook book;
            Excel.Worksheet sheet;
            Excel.Range range;

                excel = new Excel.Application();
                excel.Visible = true;

                book = (Excel.Workbook)(excel.Workbooks.Add(@"C:\Document s and Settings\Mark\My Documents\Visual Studio 2005\Projects\ExcelWindowsTest\ExcelWindowsTest\Po rtDeliveryWorkBook.xls"));
                excel.DisplayAlerts = false;
                sheet = (Excel.Worksheet)book.ActiveSheet;
                range = (Excel.Range)sheet.Columns["A", Type.Missing];

            catch (Exception theException)
                String errorMessage;
                errorMessage = "Error: ";
                errorMessage = String.Concat(errorMessage, theException.Message);
                errorMessage = String.Concat(errorMessage, " Line: ");
                errorMessage = String.Concat(errorMessage, theException.Source);

                MessageBox.Show(errorMessage, "Error");
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed regarding excel interop livehed ASP.NET 2.0 Basics 0 November 26th, 2006 10:31 AM
Help needed regarding Excel Interop livehed C# 0 November 20th, 2006 02:25 PM
Problem activating Excel Interop lagyossarian ASP.NET 2.0 Basics 1 July 21st, 2006 02:36 AM
Issue with Office Interop karveajit .NET Framework 1.x 1 November 28th, 2005 06:56 AM
ASP.NET Interop issue? lmcgann ASP.NET 1.0 and 1.1 Professional 0 October 24th, 2003 03:55 PM

All times are GMT -4. The time now is 12:27 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.