⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 celldoc.h

📁 类似Excel的设计器源代码,基本实现电子图表的功能
💻 H
字号:
// CellDoc.h : interface of the CCellDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_CELLDOC_H__25F3EA4E_CDE8_401B_8DEF_2879BC0ADCBF__INCLUDED_)
#define AFX_CELLDOC_H__25F3EA4E_CDE8_401B_8DEF_2879BC0ADCBF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxtempl.h>
#define MAXROWS 640
#define MAXCOLS 64

//m_dwFlags;//相关标志
#define CELL_AUTODISP		0x00000001	//自动显示
#define CELL_TXTWORDBREAK	0X00000020	//自动折行
#define CELL_DATAOK			0X00000040	//数据有效

#define CELL_FRMLEFT		0X00000100	//左边线
#define CELL_FRMRIGHT		0X00000200	//左边线
#define CELL_FRMTOP			0X00000400	//左边线
#define CELL_FRMBOTTOM		0X00000800	//左边线
#define CELL_FRMLT2RB		0X00001000	//左上->右下
#define CELL_FRMLB2RT		0X00002000	//左下->右上

#define CELL_DATA_NOERR		0//OK
#define CELL_DATA_NOTREADY	1//数据没准备号
#define CELL_DATA_NODATA	2//非数据单元
#define CELL_DATA_FUNERROR	3//公式错误




//m_dwTxtAdjust;//文本对齐方式
#define CELL_TXTLEFT		0X0001//左对齐
#define CELL_TXTRIGHT		0X0002//右对齐
#define CELL_TXTHMID		0X0003//水平居中

#define CELL_TXTTOP			0X00010000//上对齐
#define CELL_TXTVMID		0X00020000//垂直居中
#define CELL_TXTBOTTOM		0X00030000//下对齐

//单元格内容定义
#define CELL_TXT			0//文本
#define CELL_DIGTAL			1//数字
#define CELL_FUN			2//公式

//函数
#define FUN_ERROR			-1//公式错误
#define FUN_NONE			0//无此公式
#define FUN_SUM				1//求和
#define FUN_MAX				2//最大值
#define FUN_MIN				3//最小值
#define FUN_AVERAGE			4//最小值
#define FUN_CURDATE			5//当前日期
#define FUN_GETDATAMEM		6//内存中数据
#define FUN_GETDATABASE		7//数据库数据


///////////////////////////////////////////////////////////////
//CellObj类
class CCellObj : public CObject
{
protected:
	DECLARE_SERIAL(CCellObj);
	CCellObj();

// Constructors
public:
// Attributes
	BOOL m_bSelected;

	DOUBLE m_dblVal;//值
	CString m_szDef;//定义,数字、字符串、公式(公式以=开头)

	CString m_szDisp;//显示内容

	DWORD		m_dwFlags;//相关标志
	DWORD		m_dwTxtAdjust;//文本对齐方式

	LONG		m_lDot;//小数位数
	
	COLORREF	m_clrTxt;//文字颜色
	COLORREF	m_clrBk;//填充背景色
	
	DWORD	GetTxtAdjust(void);
	DWORD	SetTxtAdjust(DWORD dwFlag);
	BOOL	IsAutoDisp(void);
	BOOL	IsTxtWordBreak(void);
	BOOL	IsDataOk(void);//DrawText

	void	DelAutoDisp(void);
	void	DelTxtWordBreak(void);
	void	DelDataOk(void);//DrawText
	
	void	SetTxtUnderLine(BOOL bk);
	void	SetTxtFat(BOOL bk);
	void	SetTxtXt(BOOL bk);

	LOGFONT *GetLogFont(void);
	void	SetLogFont(LOGFONT *pFont);
	void	SetFontSize(int nH);
// Operations
	int		CalDrawFmtAndRect(CDC *pDC,UINT *uFmt,CRect &rtDraw,CString &szTxt,BOOL *bExtend);//计算显示格式、所占区域大小、显示用文本,返回字符串高度,-1表示字符串空
	int		Draw(CDC *pDC,CRect &rtCell);//现实单元内容
	int		DrawBk(CDC *pDC,CRect &rtCell);//画背景
	int		DrawFrm(CDC *pDC,CRect &rtCell);//边框
// Implementation
public:
	virtual ~CCellObj();
	virtual void Serialize(CArchive& ar);
//#ifdef _DEBUG
//	void AssertValid();
//#endif

	// implementation data
protected:
	LOGFONT m_logfont;//字体
	
};


///////////////////////////////////////////////////////////////
//CellRow类
class CCellRow : public CObject
{
protected:
	DECLARE_SERIAL(CCellRow);
	CCellRow();

// Constructors
public:
// Attributes
	CCellRow(int nCellNum);
	CTypedPtrArray<CObArray, CCellObj*> m_ArrayCell;

// Operations
	
// Implementation
public:
	virtual ~CCellRow();
	virtual void Serialize(CArchive& ar);
//#ifdef _DEBUG
//	void AssertValid();
//#endif

	// implementation data
protected:

};
class CCellDoc : public CDocument
{
protected: // create from serialization only
	CCellDoc();
	DECLARE_DYNCREATE(CCellDoc)

// Attributes
public:
	int m_nWidthFixCol;//固定列宽
	int m_nHigthFixRow;//固定行高
	int m_nTopX;//单元格起点文档X
	int m_nTopY;//单元格起点文档Y

	int m_nTopLeftRowNo;//作上角行号
	int m_nTopLeftColNo;//作上角列号


	CDWordArray m_warrayCol;//列宽
	CDWordArray m_warrayRow;//行宽

	CTypedPtrArray<CObArray, CCellRow*> m_ArrayRow;

// Operations
public:
	void DrawCell(CDC *pDC,CCellObj *pCell,CRect &rtCell);
	
	void DrawFillSelect(CDC *pDC,CRect &rtCell);//标记选择

	void DrawAllCell(CDC *pDC,CRect &rtClient,BOOL bPrint=FALSE);
	BOOL GetCellRect(int nRow,int nCol,CRect &rtCell);//取单元格区域
	void Select(int nRow,int nCol,BOOL bSelect);
	void SelectInRect(CRect &rtSelect);
	void SelectAll(void);
	void RemoveAllSelectBut(int nRow,int nCol);
	int  GetSelectCellNum(int *nRows,int *nCols,int *nRow,int *nCol,CCellObj **pFirstObj=NULL);//获取当前选中单元的个数,行数,列数,第一个选中单元的坐标

	BOOL InsertRow(int nIndex);//在nIndex>0前插入行,-1末尾追加
	BOOL InsertCol(int nIndex);//在nIndex>0前插入列,-1末尾追加

	BOOL DelRow(int nIndex);//
	BOOL DelCol(int nIndex);//
	CCellObj *GetCell(int nRow,int nCol);

	int SetSelectAdjust(DWORD dwAdjust);//设置文本对齐,返回设置的个数
	int SetSelectAutoDisp(void);//设置文本自动现实,返回设置的个数
	int SetSelectFont(LOGFONT *pLogFont);//设置文本字体,返回设置的个数
	int SetSelectFontSize(int nw);//设置文本字号,返回设置的个数
	int SetSelectFontFat(BOOL bk);//
	int SetSelectFontXt(BOOL bk);//
	int SetSelectFontUnderLine(BOOL bk);//
	int SetSelectFrm(DWORD dwFrm,BOOL bSet=TRUE);//设置单元格边框

	int SetSelectFrmNone(void);//设置单元格边框无
	int SetSelectClolor(COLORREF clr,BOOL bBk=FALSE);//设置单元格颜色

	int SetSelectDot(int nDot);//设置单元格小数位数
	
	int GetCellVal(int nRow,int nCol,DOUBLE *pdblVal);//取单元格值,ret=CELL_DATA_XXX
	BOOL CalFun_Sum(LPCTSTR lpszArgs,DOUBLE *pdblVal);//求和
	BOOL CalFun_Average(LPCTSTR lpszArgs,DOUBLE *pdblVal);//求平均值

	BOOL CalFun_Max(LPCTSTR lpszArgs,DOUBLE *pdblVal);//求最大
	BOOL CalFun_Min(LPCTSTR lpszArgs,DOUBLE *pdblVal);//求最小

	void SetAllDataNoReady(void);//设置所有数据无效
	void SetDigtalCellData(void);//设置数据单元数据
	int  CalAllFunCell(void);//返回未计算的个数

	int ReCalAll(void);//计算所有
	
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCellDoc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CCellDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CCellDoc)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CELLDOC_H__25F3EA4E_CDE8_401B_8DEF_2879BC0ADCBF__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -