cell组件

操作 友华表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();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值