void excelsave() { try { ApplicationClass app = new ApplicationClass(); // the Excel application. Workbook book = null; Worksheet sheet = null; Range range = null; // the range object is used to hold the data app.Visible = false; app.ScreenUpdating = false; app.DisplayAlerts = false; string execPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); book = app.Workbooks.Open(@"E:\SSIS\ABC\Book1.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); sheet = (Worksheet)book.Worksheets[1]; range = sheet.get_Range("A1", Missing.Value); range.Columns.ColumnWidth = 22.34; range = sheet.get_Range("B1", Missing.Value); range.Columns.ColumnWidth = 22.34; book.SaveAs(@"E:\SSIS\ABC\Book1.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } catch (Exception ex) { } }
Here I open an excel sheet that is trying to increase the width of the column and should make the column headings bold and save the document, now the document is not saved. I am using vs 2008, C # 3.5
Is there something I'm doing wrong here? any help would be a great solution
source share