3,245
社区成员
发帖
与我相关
我的任务
分享
CRange m_cell; //µ¥Ôª¸ñ
CRange m_range; //ÇøÓò
CWorksheet m_sheet; //¹¤×÷±í
CWorksheets m_sheets; //¹¤×÷±í¼¯ºÏ
CComment m_comment; //Åú×¢
CWorkbook m_book; //¹¤×÷²¾
CWorkbooks m_books; //¹¤×÷²¾¼¯ºÏ
CApplication m_app; //excel½ø³Ì
CFont0 m_font; //×ÖÌå
CBorders m_borders; //±í¸ñ
BOOL CExcelOperations::GetCellFont(void)
{
try
{
m_font = m_cell.get_Font();
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetCellFont(LPCTSTR strFont)
{
try
{
if( !GetCellFont() )
return FALSE;
m_font.put_Name(COleVariant(strFont));
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetAutoFitWidth(void)
{
try
{
m_range.AttachDispatch( m_sheet.get_Cells(), TRUE );
m_range = m_range.get_EntireColumn();
m_range.AutoFit();
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetBorders(LPCTSTR strLeftUp, LPCTSTR strRightDown, short siLineStyle)
{
try
{
m_range = m_sheet.get_Range(COleVariant(strLeftUp),COleVariant(strRightDown));
m_borders = m_range.get_Borders();
m_borders.put_LineStyle(COleVariant((short)siLineStyle));
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetVerticalAlignment(LONG lAlignment)
{
try
{
m_range.put_VerticalAlignment(COleVariant((LONG)lAlignment));
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetHorizontalAlignment(LONG lAlignment)
{
try
{
m_range.put_HorizontalAlignment(COleVariant((LONG)lAlignment));
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetColumnWidth(LONG lWidth)
{
try
{
m_cell.put_ColumnWidth(COleVariant((LONG)lWidth));
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetRowHeight(LONG lHeight)
{
try
{
m_cell.put_RowHeight(COleVariant((LONG)lHeight));
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetFontSize(LONG lSize)
{
try
{
if( !GetCellFont() )
return FALSE;
m_font.put_Size(COleVariant((LONG)lSize));
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetCellColor(BYTE bRed, BYTE bGreen, BYTE bBlue)
{
try
{
if( !GetCellFont() )
return FALSE;
m_font.put_Color(COleVariant((LONG)RGB(bRed, bGreen, bBlue)));
}
catch (...)
{
return FALSE;
}
return TRUE;
}
BOOL CExcelOperations::SetCellBold(BOOL bBoolean)
{
try
{
if( !GetCellFont() )
return FALSE;
m_font.put_Bold(COleVariant((short)bBoolean));
}
catch (...)
{
return FALSE;
}
return TRUE;
}