操作 友华表cell组件 ,使用前需下载安装。
用visual studio打开.rc文件显示在对话框,右键选择 “插入ActiveX控件(X)”》cell50control(U)
为cell控件绑定变量
初始化grid参考安装目录下的Example
设置grid颜色样式,.h文件
/*
* 用友华表cell控件的自定义样式设置类
*/
class CCellStyle
{
private:
CCellStyle(void){};
public:
static CCellStyle& GetInstance();
/*
* 设置cell控件总体颜色样式,在初始化grid数据之前设置总体颜色样式
* @param cell[in] cell控件变量
*/
void SetColorStyle(CUfSoftCell2000 &cell);
/*
* 设置cell控件边框颜色样式。由于边框与具体数据相关,需要在grid数据设置完毕之后设置。
* @param cell[in] cell控件变量
*/
void SetFrameColorStyle(CUfSoftCell2000 &cell);
};
.cpp
#include "stdafx.h"
#include "CellStyle.h"
#include "UfSoftCell2000.h"
CCellStyle& CCellStyle::GetInstance()
{
static CCellStyle m_cellStyle;
return m_cellStyle;
}
/*
* 设置第0行第0列的单元格背景颜色,第0行或第0列只能逐个单元格设置颜色
* @param cell [in|out] cell组件变量
* @param color[in] RGB
*/
void SetZeroCellBackColor(CUfSoftCell2000 &cell,long nSheetIndex,const COLORREF& color)
{
int nRow = cell.GetRows(0);
int nCol = cell.GetCols(0);
for (int i = 0; i < nRow; ++i)
{
cell.SetCellBackColor(0, i, nSheetIndex, cell.FindColorIndex(color, 1));
}
for (int i = 0;i < nCol; ++i)
{
cell.SetCellBackColor(i, 0, nSheetIndex, cell.FindColorIndex(color, 1));
}
}
/*
* 设置第0行第0列的单元格字体颜色,第0行或第0列只能逐个单元格设置颜色
* @param cell [in|out] cell组件变量
* @param color[in] RGB
*/
void SetZeroCellTextColor(CUfSoftCell2000 &cell,long nSheetIndex,const COLORREF& color)
{
int nRow = cell.GetRows(0);
int nCol = cell.GetCols(0);
for (int i = 0; i < nRow; ++i)
{
cell.SetCellTextColor(0, i, nSheetIndex, cell.FindColorIndex(color, 1));
}
for (int i = 0;i < nCol; ++i)
{
cell.SetCellTextColor(i, 0, nSheetIndex, cell.FindColorIndex(color, 1));
}
}
/*
* 设置指定列的单元格背景颜色
* @param cell [in|out] cell组件变量
* @param color [in] RGB
* @param nBegin [in] 起始列
* @param nEnd [in] 结束列
*/
void SetColumnBackColor(CUfSoftCell2000 &cell,long nSheetIndex,int nBegin, int nEnd,const COLORREF& color)
{
for (int i = nBegin; i < nEnd;++i)
{
cell.SetCellBackColor(i, -1, 0, cell.FindColorIndex(color, 1));
}
}
/*
* 设置指定列的单元格字体颜色
* @param cell [in|out] cell组件变量
* @param color [in] RGB
* @param nBegin [in] 起始列
* @param nEnd [in] 结束列
*/
void SetColumnTextColor(CUfSoftCell2000 &cell,long nSheetIndex,int nBegin, int nEnd,const COLORREF& color)
{
for (int i = nBegin; i < nEnd;++i)
{
cell.SetCellTextColor(i, -1, 0, cell.FindColorIndex(color, 1));
}
}
void CCellStyle::SetColorStyle(CUfSoftCell2000 &cell)
{
long nSheetIndex = cell.GetCurSheet();
long nCol = cell.GetCols(nSheetIndex);
cell.SetWndBkColor(color);
cell.SetSheetGridLineColor(nSheetIndex,color);
SetColumnTextColor(cell,nSheetIndex,0, nCol,color);
SetColumnBackColor(cell,nSheetIndex,0, nCol,color);
}
void CCellStyle::SetFrameColorStyle(CUfSoftCell2000 &cell)
{
SetZeroCellTextColor(cell,nSheetIndex,color);
SetZeroCellBackColor(cell,nSheetIndex,color);
}
最后设置颜色样式
//设置数据前
CCellStyle::GetInstance().SetColorStyle();
//设置数据后
CCellStyle::GetInstance().SetFrameColorStyle();