Found CRange AutoFormat function of a class, but the experiment many times, didn't find the line height and setting method of the font is my parameters in the wrong? There are other functions
The VARIANT AutoFormat (long Format, VARIANT& Number, VARIANT& The Font, VARIANT& Alignment, VARIANT& Border, VARIANT& The Pattern, VARIANT& Width)
CodePudding user response:
Line height and column width problem is solved, the question now is how to set up a line or an area of the font style?CodePudding user response:
The CSDN to yellow booth?CodePudding user response:
Record macro manual EXCEL, stop the recording, and then edit the macro, according to the macro code changeCodePudding user response:
Write a class before,with the reference of
BOOL CExcelOperations: : SetCellFont (LPCTSTR strFont)
{
Try
{
If (! GetCellFont ())
return FALSE;
M_font. Put_Name (COleVariant (strFont));
}
The 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 ();
}
The 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));
}
The catch (... )
{
return FALSE;
}
Return TRUE;
}
BOOL CExcelOperations: : SetVerticalAlignment (LONG lAlignment)
{
Try
{
M_range. Put_VerticalAlignment (COleVariant ((LONG) lAlignment));
}
The catch (... )
{
return FALSE;
}
Return TRUE;
}
BOOL CExcelOperations: : SetHorizontalAlignment (LONG lAlignment)
{
Try
{
M_range. Put_HorizontalAlignment (COleVariant ((LONG) lAlignment));
}
The catch (... )
{
return FALSE;
}
Return TRUE;
}
BOOL CExcelOperations: : SetColumnWidth (LONG lWidth)
{
Try
{
M_cell. Put_ColumnWidth (COleVariant ((LONG) lWidth));
}
The catch (... )
{
return FALSE;
}
Return TRUE;
}
BOOL CExcelOperations: : SetRowHeight (LONG lHeight)
{
Try
{
M_cell. Put_RowHeight (COleVariant ((LONG) lHeight));
}
The catch (... )
{
return FALSE;
}
Return TRUE;
}
BOOL CExcelOperations: : SetFontSize (LONG lSize)
{
Try
{
If (! GetCellFont ())
return FALSE;
M_font. Put_Size (COleVariant ((LONG) lSize));
}
The 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)));
}
The catch (... )
{
return FALSE;
}
Return TRUE;
}
BOOL CExcelOperations: : SetCellBold (BOOL bBoolean)
{
Try
{
If (! GetCellFont ())
return FALSE;
M_font. Put_Bold (COleVariant ((short) bBoolean));
}
The catch (... )
{
return FALSE;
}
Return TRUE;
}
CodePudding user response:
CRange m_cell;//mu RMB? A????
CRange m_range;//?? Oo
CWorksheet m_sheet;//1 because x present + I
CWorksheets m_sheets;//1 because x present - I? ˉ o?
CComment m_comment;//? U * ¢
CWorkbook m_book;//1 because x present 2?
CWorkbooks m_books;//1 because x present 2?? ˉ o?
CApplication m_app;//excel?? 3 I
CFont0 m_font;//x? I?
CBorders m_borders;//+ I??
BOOL CExcelOperations: : GetCellFont (void)
{
Try
{
M_font=m_cell. Get_Font ();
}
The catch (... )
{
return FALSE;
}
Return TRUE;
}