Using Excel Interop via VS.NET 2005 to create and save a new Excelworksheet.. please help!
Guys,
Sorry for crossing multiple groups but I am at my wits end... Please help! Below is my code in C# (VS.NET 2005.. I have tried every combo I can think of. Every "SaveAs" call results in the strange HRESULT 0x800A03EC error. I have verified that the folder path exists and that "Everyone" has Full Control on it. I have also tried Missing.Value in place of nulls. :( Thanx! J'son CODE: //create initial excel sheet GC.Collect(); //clear out any earlier instances Excel._Application application = new Excel.Application(); application.Visible = false; Excel._Workbook workbook = application.Workbooks.Add(Missing.Value); Excel._Worksheet sheet = (Excel._Worksheet)workbook.ActiveSheet; //format the titles DataColumnCollection columns = results.Tables[0].Columns; for (int i = 0; i < columns.Count; i++) { string rangeHeader = ColumnLetter(i + 1) + "1"; Excel.Range range = (Excel.Range)sheet.get_Range(rangeHeader, rangeHeader); range.Font.Bold = true; range.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; range.Value2 = columns[i].ColumnName; range.EntireColumn.AutoFit(); } //save the workbook for now -- ERROR HITS HERE! application.ActiveWorkbook.SaveAs(_filePath, Excel.XlFileFormat. xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode. xlNoChange, false, false, null, null, null); workbook.Close(null, null, null); application.Quit(); Thanx! |
All times are GMT +1. The time now is 08:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com