_variant_t("A1"),_variant_t("Q2")),TRUE); m_ExlRge.Merge(_variant_t((long)0)); break; } ////////设置表格内容//////// m_ExlRge.AttachDispatch(m_ExlSheet.GetUsedRange());//加载已使用的单元格 m_ExlRge.SetWrapText(_variant_t((long)1));//设置单元格内的文本为自动换行 //设置齐方式为水平垂直居中 //水平对齐:默认=1,居中=-4108,左=-4131,右=-4152 //垂直对齐:默认=2,居中=-4108,左=-4160,右=-4107 m_ExlRge.SetHorizontalAlignment(_variant_t((long)-4108)); m_ExlRge.SetVerticalAlignment(_variant_t((long)-4108)); ///////设置整体的字体、字号及颜色////// Font ft; ft.AttachDispatch(m_ExlRge.GetFont()); ft.SetName(_variant_t("宋体"));//字体 ft.SetColorIndex(_variant_t((long)1));//字的颜色 ft.SetSize(_variant_t((long)10));//字号 ///////////设置标题字体及颜色////////// m_ExlRge.AttachDispatch(m_ExlSheet.GetRange(_variant_t("A1"),_variant_t("H2"))); ft.AttachDispatch(m_ExlRge.GetFont()); ft.SetBold(_variant_t((long)1));//粗体 ft.SetSize(_variant_t((long)13)); ft.SetColorIndex(_variant_t((long)1)); CellFormat cf; cf.AttachDispatch(m_ExlRge.GetCells()); // //////////////设置底色///////////////// // // Interior it; // // it.AttachDispatch(m_ExlRge.GetInterior()); // // it.SetColorIndex(_variant_t((long)11));//标题底色 // // ////表格内容的底色//// // // m_ExlRge.AttachDispatch(m_ExlSheet.GetRange(_variant_t("A2"),_variant_t("D5"))); // // it.AttachDispatch(m_ExlRge.GetInterior()); // // it.SetColorIndex(_variant_t((long)15)); //////////////为表格设置边框///////////// Range UnitRge; CString CellName; for(int i=1;i<=nConfirmNum+3;i++) { for(int j=1;j<=nMaxChuCount+1;j++) { CellName.Format("%c%d",j+64,i);//单元格的名称 UnitRge.AttachDispatch(m_ExlRge.GetRange(_variant_t(CellName),_variant_t(CellName)));//加载单元格 //LineStyle=线型 Weight=线宽 ColorIndex=线的颜色(-4105为自动) UnitRge.BorderAround(_variant_t((long)1),_variant_t((long)2),_variant_t((long)-4105),vtMissing);//设置边框 } } //释放对象(相当重要!) m_ExlRge.ReleaseDispatch(); m_ExlSheet.ReleaseDispatch(); m_ExlSheets.ReleaseDispatch(); m_ExlBook.ReleaseDispatch(); m_ExlBooks.ReleaseDispatch(); //m_ExlApp一定要释放,否则程序结束后还会有一个Excel进程驻留在内存中,而且程序重复运行的时候会出错 m_ExlApp.ReleaseDispatch(); //退出程序 m_ExlApp.Quit(); // CDialog::OnOK(); } 摘自 开心
|