www.pudn.com > EXCEL.rar > ExcelTextDlg.cpp


// ExcelTextDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "ExcelText.h" 
#include "ExcelTextDlg.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	//}}AFX_DATA 
 
	// ClassWizard generated virtual function overrides 
	//{{AFX_VIRTUAL(CAboutDlg) 
	protected: 
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
	//{{AFX_MSG(CAboutDlg) 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	//}}AFX_DATA_INIT 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
		// No message handlers 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CExcelTextDlg dialog 
 
CExcelTextDlg::CExcelTextDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CExcelTextDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CExcelTextDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CExcelTextDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CExcelTextDlg) 
	DDX_Control(pDX, IDC_LIST1, m_ListMain); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CExcelTextDlg, CDialog) 
	//{{AFX_MSG_MAP(CExcelTextDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CExcelTextDlg message handlers 
 
BOOL CExcelTextDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Add "About..." menu item to system menu. 
 
	// IDM_ABOUTBOX must be in the system command range. 
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 
	ASSERT(IDM_ABOUTBOX < 0xF000); 
 
	CMenu* pSysMenu = GetSystemMenu(FALSE); 
	if (pSysMenu != NULL) 
	{ 
		CString strAboutMenu; 
		strAboutMenu.LoadString(IDS_ABOUTBOX); 
		if (!strAboutMenu.IsEmpty()) 
		{ 
			pSysMenu->AppendMenu(MF_SEPARATOR); 
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 
		} 
	} 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	// TODO: Add extra initialization here 
	m_ListMain.InsertColumn(0,"0",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(1,"1",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(2,"2",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(3,"3",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(4,"4",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(5,"5",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(6,"6",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(7,"7",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(8,"8",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(9,"9",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(10,"10",LVCFMT_CENTER,50); 
	m_ListMain.InsertColumn(11,"11",LVCFMT_CENTER,50); 
	m_ListMain.SetExtendedStyle(LVS_EX_GRIDLINES); 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CExcelTextDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
	{ 
		CAboutDlg dlgAbout; 
		dlgAbout.DoModal(); 
	} 
	else 
	{ 
		CDialog::OnSysCommand(nID, lParam); 
	} 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CExcelTextDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CExcelTextDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CExcelTextDlg::OnButton1()  
{ 
	// TODO: Add your control notification handler code here 
	CMyExcel ExcelMain; 
	MyAlignment Xalign; 
	MyNumberFormat Xnumber; 
	MyBorder Xborder; 
	MyFont Xfont; 
	int i; 
	//边框线 
	Xborder.Color=RGB(0,0,0); 
	Xborder.LineStyle=xlContinuous; 
	Xborder.Weight=xlThin; 
	//对齐方式 
	Xalign.HorizontalAlignment=xlCenter; 
	Xalign.VerticalAlignment=xlTop; 
	//数据类型 
	Xnumber.GetText(); 
	//字体 
	Xfont.Bold=TRUE; 
	Xfont.ForeColor=RGB(64,130,230); 
	Xfont.Shadow=TRUE; 
	Xfont.size=20; 
	ExcelMain.Open(); 
	ExcelMain.AddSheet("新建1"); 
	ExcelMain.GetRange("A1","L1"); 
	ExcelMain.SetMergeCells(TRUE); 
	ExcelMain.SetAlignment(Xalign); 
	ExcelMain.SetNumberFormat(Xnumber); 
	ExcelMain.SetFont(Xfont); 
	ExcelMain.SetItemText(1,1,"导出生成表"); 
	ExcelMain.GetRange("A2","L2"); 
	ExcelMain.SetAlignment(Xalign); 
	ExcelMain.SetNumberFormat(Xnumber); 
	Xfont.size=16; 
	Xfont.ForeColor=RGB(0,0,0); 
	ExcelMain.SetFont(Xfont); 
	ExcelMain.SetBorderLine(xlEdgeBottom,Xborder); 
	ExcelMain.SetBorderLine(xlEdgeLeft,Xborder); 
	ExcelMain.SetBorderLine(xlEdgeRight,Xborder); 
	ExcelMain.SetBorderLine(xlEdgeTop,Xborder); 
	ExcelMain.SetBorderLine(xlInsideHorizontal,Xborder); 
	ExcelMain.SetBorderLine(xlInsideVertical,Xborder); 
	for(i=1;i<=12;i++) 
	{ 
		CString str; 
		str.Format("%4d",i); 
		ExcelMain.SetItemText(1,i,str); 
	} 
	ExcelMain.GetRange("A3","A13"); 
	Xnumber.GetDBNumber(TRUE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"23456"); 
	} 
	ExcelMain.GetRange("B3","B13"); 
	Xnumber.GetDBNumber(FALSE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"23456"); 
	} 
	ExcelMain.GetRange("C3","C13"); 
	Xnumber.GetDateTime(TRUE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"6000.5345"); 
	} 
	ExcelMain.GetRange("D3","D13"); 
	Xnumber.GetDateTime(FALSE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"8000.63456"); 
	} 
	ExcelMain.GetRange("E3","E13"); 
	Xnumber.GetDateTime(FALSE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"8000.63456"); 
	} 
	ExcelMain.GetRange("F3","F13"); 
	Xnumber.GetTime(TRUE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"3245.676"); 
	} 
	ExcelMain.GetRange("G3","G13"); 
	Xnumber.GetTime(FALSE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"3455.897"); 
	} 
	ExcelMain.GetRange("H3","H13"); 
	Xnumber.GetDate(TRUE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"8770"); 
	} 
	ExcelMain.GetRange("I3","I13"); 
	Xnumber.GetDate(FALSE); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"9540"); 
	} 
	ExcelMain.GetRange("J3","J13"); 
	Xnumber.GetPost(10); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"9540"); 
	} 
	ExcelMain.GetRange("K3","K13"); 
	Xnumber.GetNumber(TRUE,2); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"9540"); 
	} 
	ExcelMain.GetRange("L3","L13"); 
	Xnumber.GetTechNumBer(2); 
	ExcelMain.SetNumberFormat(Xnumber); 
	for(i=1;i<=10;i++) 
	{ 
		ExcelMain.SetItemText(i,1,"9540"); 
	} 
	ExcelMain.GetRange("A3","L12"); 
	ExcelMain.SetBorderLine(xlEdgeBottom,Xborder); 
	ExcelMain.SetBorderLine(xlEdgeLeft,Xborder); 
	ExcelMain.SetBorderLine(xlEdgeRight,Xborder); 
	Xborder.LineStyle=xlDot; 
	Xborder.Color=RGB(0,0,0); 
	Xborder.Weight=xlThin; 
	ExcelMain.SetBorderLine(xlInsideHorizontal,Xborder); 
	ExcelMain.SetBorderLine(xlInsideVertical,Xborder); 
	ExcelMain.AutoRange(); 
	ExcelMain.AutoColFit(); 
	ExcelMain.SaveAs(ExcelMain.GetAppPath()+"\\Test.xls"); 
} 
void CExcelTextDlg::OnButton2()  
{ 
	// TODO: Add your control notification handler code here 
	int i,j,k=0; 
	CMyExcel ExcelMain; 
	CString strText; 
	if(ExcelMain.IsFileExist(ExcelMain.GetAppPath()+"\\Test.xls",FALSE)) 
	{	 
		ExcelMain.Open(ExcelMain.GetAppPath()+"\\Test.xls"); 
		ExcelMain.OpenSheet("新建1"); 
		ExcelMain.AutoRange(); 
		for(i=3;i<13;i++) 
		{ 
			for(j=1;j<13;j++) 
			{ 
				strText=ExcelMain.GetItemText(i,j); 
				if(j==1)  
					k=m_ListMain.InsertItem(k,strText); 
				else 
					m_ListMain.SetItemText(k,j-1,strText); 
			} 
 
		} 
		ExcelMain.Exit(); 
	} 
	else 
	{ 
		MessageBox("请先生成EXCEL文件","提示",MB_OK|MB_ICONINFORMATION); 
	} 
 
}