Click here to Skip to main content
15,893,487 members
Articles / Desktop Programming / MFC

Printing to Excel

Rate me:
Please Sign up or sign in to vote.
4.00/5 (8 votes)
20 Apr 20022 min read 252.8K   3.9K   55  
This article shows how to send data to Excel instead of a printer.
//	PrintExcel.h - Definition of the PrintExcel class
//


#ifndef __PRINTEXCEL_H
#define __PRINTEXCEL_H


#define	ID_EXCEL_INIT				50
#define	ID_EXCEL_CLOSE				51



#define ID_FORMAT_LEFT				0
#define ID_FORMAT_RIGHT				1
#define ID_FORMAT_CENTER			2

#define ID_FORMAT_NUMBER0			10
#define ID_FORMAT_NUMBER1			11
#define ID_FORMAT_NUMBER2			12
#define ID_FORMAT_NUMBER3			13
#define ID_FORMAT_NUMBER4			14
#define ID_FORMAT_NUMBER5			15
#define ID_FORMAT_NUMBER6			16

#define	ID_EXCEL_TYPBACKGROUND			0
#define ID_EXCEL_TYPTEXTFONT			1
#define ID_EXCEL_TYPTEXT				2

#define ID_EXCEL_TYPLINESINGLETOP		3
#define ID_EXCEL_TYPLINESINGLEBOTTOM	4
#define ID_EXCEL_TYPLINESINGLELEFT		5
#define ID_EXCEL_TYPLINESINGLERIGHT		6
#define ID_EXCEL_TYPLINEDOUBLETOP		7
#define ID_EXCEL_TYPLINEDOUBLEBOTTOM	8
#define ID_EXCEL_TYPLINEDOUBLELEFT		9
#define ID_EXCEL_TYPLINEDOUBLERIGHT		10

#define ID_FORMAT_PORTRAIT			20
#define ID_FORMAT_LANDSCAPE			21


class CPrintExcel {

// Construction
public:
	CPrintExcel ();
	~CPrintExcel ();

	
private:
	int		ExcelGetRowCol (CRect &rect, int *pnCol, int *pnRow, 
								 int *pnSorted, float *pfWidth, char *cCell,
								 int nArray, int nUseTop=FALSE);


// Operations
public:

	// transform CRect to cols
	int		CalcExcelCols (CRect &rect);	
	// send different data to excel
	int		PrintExcel (int	nFunction, CRect *pRect=NULL, const char *cText=NULL, 
						COLORREF nColor=0, LOGFONT *pLogFont=NULL, 
						int nFormat=0);


// Attributes
private:
	CObArray	m_ExcelCols;
	CObArray	m_ExcelRows;
	int			m_nExcelRowHeight;

	int	m_nCurrentRow;
	int	m_nCurrentCol;
	int	m_nSorted;
	int	m_nTop;
	int	m_nBottom;

	int	m_nError;

	int	m_nGerman;	// decimalsign and thousand sign are in german different
	
	
};

#endif	// __SERIAL_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions