m_objExcel = new Excel.Application();
m_objExcel.Visible = true;
Excel.Workbook m_objBook = m_objExcel.Application.Workbooks.Add(FileWrite);
m_objBook = m_objExcel.Workbooks.Add(Missing.Value);
Excel.Worksheet m_objSheet = (Excel.Worksheet)(m_objBook.Worksheets[1]);
m_objRange = m_objSheet.get_Range("A5", Type.Missing);
//存放报表数据的二维数组
object[,] objdate = new object[rownum, 9];
.......................
.......................
m_objRange = m_objSheet.get_Range("A5", Missing.Value);
m_objRange = m_objRange.get_Resize(rownum, 9);
//水平对齐--右对齐
m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
//文本格式
m_objRange.NumberFormat = "@";
m_objRange.Value2 = objdate;
//保存并施放EXECL资源
m_objBook.Saved = true;
m_objExcel.DisplayAlerts = false;
m_objSheet._Saves (FileWrite,Missing.Value,Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Missing.Value,Missing.Value);
m_objBook.Close(false, Missing.Value, Missing.Value);
if (m_objExcel != null)
{
m_objExcel.Workbooks.Close();
m_objExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
System.GC.Collect();
}
if (m_objSheet != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheet);
System.GC.Collect();
}
GC.Collect();
这样写可以 VS2008测试通过