LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel.Interop Not Saving Column Width Changes

Hi,

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.
Mark


using Excel=Microsoft.Office.Interop.Excel;

namespace ExcelWindowsTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

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

try
{
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];
range.AutoFit();

book.Save();
excel.Quit();
}
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");
}
}

--
Thanks
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Cell Width WITHOUT changing Column width dww701 Excel Discussion (Misc queries) 1 January 12th 09 10:52 PM
Column width not saving HADENUF Excel Discussion (Misc queries) 0 October 23rd 06 10:59 PM
Set Column Width Based On Total Width Of Other Columns rayneraingoaway Excel Programming 1 June 28th 06 11:10 PM
Excel Interop Catch Event for Saving a file as xls and as xml? m.ahrens Excel Programming 8 December 29th 04 02:11 PM


All times are GMT +1. The time now is 05:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"