Using Excel Interop via VS.NET 2005 to create and save a new Excelworksheet.. please help!


J

J'son

Guys,

Please help.. I'm at my wits end! Yes, this is for an ASP.NET app and
I've already posted this to the vstool.office group too but no help
there..

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.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!
 
Ad

Advertisements


Top