Skip to main content

Posts

Showing posts from May, 2012

Google Search

Custom Search

Live Search

Yahoo Search


Search the web Search this site

Automatically Sizing Excel Columns

Today while trying to do some formatting on Excel using .Net I came up with an error. One of the things I tried is to make Excel columns automatically size according to the content having on them. As all of you might know we can get this done in Excel by simply double clicking on the column’s right margin. While doing this in code I got the following exception.ExcelSheet.get_Range("A1", "E10")' threw an exception of type 'System.Runtime.InteropServices.COMException'
base {System.Runtime.InteropServices.ExternalException}: {"Exception from HRESULT: 0x800401A8"}The code involved in generating this error is as below.(ExcelSheet.get_Range("A1", "E10")).EntireColumn.AutoFit(); Later I found the reason for this error. Error will occur when we use AutoFit () on empty cells. Because initially I did not have anything in my excel sheet I kept on getting this. So to overcome this error use the same code to auto fit the cell contents …