3,245
社区成员
发帖
与我相关
我的任务
分享
Excels::Font ft;
ft.AttachDispatch(range.GetFont());
ft.SetName(_variant_t("verdona"));
ft.SetSize(_variant_t("12"));
ft.SetColorIndex(COleVariant((short)4));
void CExcelOWCManager::SetColor(int iRF ,int iRL ,int iCF ,int ICL,wstring strSheet,long lColor)
{
CImain* pImain = (CImain*)AfxGetApp();
ASSERT(m_pDocDisp);
log_info(_T("CExcelOWCManager::SetContIn called!"));
try
{
Excels::_Workbook m_excelBook = NULL;
Excels::_Worksheet m_excelSheet = NULL;
Excels::Worksheets m_excelSheets = NULL;
Excels::_Application m_excelApp = NULL;
m_excelBook.AttachDispatch(m_pDocDisp,TRUE);
m_excelSheets.AttachDispatch(m_excelBook.GetSheets(),FALSE);
int iCount = m_excelSheets.GetCount();
BOOL bFound = FALSE;
for (int i = 1 ; i <= iCount ; i++)
{
m_excelSheet.AttachDispatch(m_excelSheets.GetItem(COleVariant((long)i)),FALSE);
CString strSheetTemp = m_excelSheet.GetName();
CStrConverter strConv(strSheetTemp);
wstring strSheetName(strConv.pResult);
if (strSheetName == strSheet)
{
bFound = TRUE;
break;
}
m_excelSheet.ReleaseDispatch();
}
if (!bFound)
{
log_error(_T("CExcelOWCManager::SetContIn failed! can not find the specified sheet."));
m_excelSheets.ReleaseDispatch();
m_excelBook.ReleaseDispatch();
return;
}
for (int i = iRF ; i <= iRL ; i++)
{
for (int j = iCF ; j <= ICL ; j++)
{
try
{
CString strCell1 = _T("");
CString strCell2 = _T("");
strCell1.Format(_T("%d"),i);
strCell2.Format(_T("%d"),j);
CString strCell = GetCell(j+1,i+1);
Excels::Range range = NULL;
range.AttachDispatch(m_excelSheet.GetRange(COleVariant(strCell),COleVariant(strCell)),FALSE);
try
{
//Excels::Interior inter;
//inter.AttachDispatch(range.GetInterior());
//inter.SetColor(COleVariant((long)lColor));
Excels::Font ft;
ft.AttachDispatch(range.GetFont());
ft.SetName(_variant_t("verdona"));
ft.SetSize(_variant_t("12"));
ft.SetColorIndex(COleVariant((short)4));
}
catch (...)
{
}
range.ReleaseDispatch();
}
catch (...)
{
log_error(_T("CExcelOWCManager::SetContIn failed! SetValue failed"));
}
}
}
log_info(_T("before release excel resource"));
m_excelSheet.ReleaseDispatch();
m_excelSheets.ReleaseDispatch();
m_excelBook.ReleaseDispatch();
log_info(_T("after release excel resource"));
}
catch (...)
{
log_error(_T("CExcelOWCManager::SetContIn failed! release excel resource failed"));
return;
}
}