使用C#和Excel进行报表开发(七)-设置单元格的显示格式

Excel.Applicationm_objExcel = null ;

Excel._Workbookm_objBook
= null ;

Excel.Sheetsm_objSheets
= null ;

Excel._Worksheetm_objSheet
= null ;

Excel.Rangem_objRange
= null ;


object m_objOpt = System.Reflection.Missing.Value;

try
{
m_objExcel
=newExcel.Application();

m_objBook
=m_objExcel.Workbooks.Open("e:\\1.xls",m_objOpt,m_objOpt,m_objOpt,
m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,
m_objOpt,m_objOpt,m_objOpt,m_objOpt);



m_objSheets
=(Excel.Sheets)m_objBook.Worksheets;

m_objSheet
=(Excel._Worksheet)(m_objSheets.get_Item(1));

m_objRange
=m_objSheet.get_Range("A1",m_objOpt);

m_objRange.NumberFormatLocal
="#";



m_objBook.SaveAs(
"e:\\22.xls",m_objOpt,m_objOpt,

m_objOpt,m_objOpt,m_objOpt,Excel.XlSaveAsAccessMode.xlNoChange,

m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt);
}


catch (Exceptionex)
{

MessageBox.Show(ex.Message);

}


finally
{

m_objBook.Close(m_objOpt,m_objOpt,m_objOpt);

m_objExcel.Workbooks.Close();

m_objExcel.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBook);

System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);

m_objBook
=null;

m_objExcel
=null;

GC.Collect();

}

你可能感兴趣的:(C++,c,C#,Excel)