Hi Benj, Thanks for your reply. I have tried the following code and it works good.
((Range)excelSheet.Columns[1, Type.Missing]).AutoFit(); .... .... ..... Regards, Karthizen On Thu, Mar 12, 2009 at 7:21 AM, Benj Nunez <[email protected]> wrote: > > "I have tried the following codes,however it does not work out. > > excelSheet.Cells.CurrentRegion.Columns.AutoFit(); > > excelSheet.Cells.EntireColumn.AutoFit(); " > > > I think you need to specify a range as indicated here in this link: > > http://support.microsoft.com/kb/302084 > > Here's how I sum up the code as indicated in the url above: > > //declare a range variable: > Excel.Range oRng; > > ...//some code... > > //Get a new workbook. > oWB = (Excel._Workbook)(oXL.Workbooks.Add( Missing.Value )); > // get a worksheet > oSheet = (Excel._Worksheet)oWB.ActiveSheet; > > ...// some code... > > oRng = oSheet.get_Range("someColumn1","someColumn2"); > oRng.EntireColumn.AutoFit(); > > > > Cheers! > > > Benj > > > > > > On Mar 12, 6:38 am, Karthikeyan <[email protected]> wrote: > > Hi, > > > > I am developing a windows application in which I have exported data from > > dataset to an Excel. I need to adjust the text to fit within the cells > > without using wordwrap. > > > > I have tried the following codes,however it does not work out. > > > > excelSheet.Cells.CurrentRegion.Columns.AutoFit(); > > > > excelSheet.Cells.EntireColumn.AutoFit(); > > > > Can anyone help me out in accomplish this? > > > > Regards, > > > > karthizen > > > > -- > > Thanks & Regards, > > Karthikeyan > -- Thanks & Regards, Karthikeyan
