Using Excel Interop via VS.NET 2005 to create and save a new Excel

Using Excel Interop via VS.NET 2005 to create and save a new Excel

am 28.01.2008 20:18:39 von sitexcite

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[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!

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

am 28.01.2008 20:44:29 von mark

"J'son" wrote in message
news:9b1ba0cb-1486-4ec4-91c0-363053c4398e@q21g2000hsa.google groups.com...

> Please help.. I'm at my wits end! Yes, this is for an ASP.NET app

Let me stop you right there...

Server-side Office Automation is not supported by Microsoft because it is so
risky and unstable:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257 757#kb2
http://support.microsoft.com/default.aspx/kb/288367

Use this instead: http://www.aspose.com/Products/Aspose.Cells/Default.aspx
and all your problems will disappear.


--
Mark Rae
ASP.NET MVP
http://www.markrae.net