日期:2014-05-17 浏览次数:21024 次
private Excel.Workbooks m_objBooks = null;
private Excel._Workbook m_objBook = null;
private Excel.Sheets m_objSheets = null;
private Excel._Worksheet m_objSheet = null;
private Excel.Application xlsApp = null;
private Excel.Range xlsRan = null;
private object m_objOpt = System.Reflection.Missing.Value;
xlsApp = new Excel.Application();
if (xlsApp == null)
{
MessageBox.Show("无法找到Excel应用程序!");
return;
}
xlsApp.Application.Workbooks.Add(true);
//初始化
m_objBooks = (Excel.Workbooks)xlsApp.Workbooks;
m_objBook = (Excel._Workbook)(m_objBooks.Add(m_objOpt));
m_objSheets = (Excel.Sheets)m_objBook.Worksheets;
m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(1));
xlsRan = m_objSheet.get_Range(xlsApp.Cells[5, 1], xlsApp.Cells[6, 1]);
xlsRan.MergeCells = true; //合并
m_objSheet.Cells[5, 1] = "序号";
xlsRan.Font.Size = 10;
xlsRan.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; //对齐
xlsRan.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.