www.pudn.com > Excel_To_Access.rar > Excel_To_AccessDlg.cpp
// Excel_To_AccessDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Excel_To_Access.h"
#include "Excel_To_AccessDlg.h"
#include "CSpreadSheet.h"
#include "CSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExcel_To_AccessDlg dialog
CExcel_To_AccessDlg::CExcel_To_AccessDlg(CWnd* pParent /*=NULL*/)
: CDialog(CExcel_To_AccessDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CExcel_To_AccessDlg)
m_BFYYBH = 0;
m_XZBJCS = 1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CExcel_To_AccessDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExcel_To_AccessDlg)
DDX_Control(pDX, IDC_PROGRESS_EXCEL_TO_ACCESS, m_EXCEL_TO_ACCESS_PROGRESS);
DDX_Control(pDX, IDC_BUTTON_EXCEL_OPEN, m_EXCELOPENB);
DDX_Control(pDX, IDC_BUTTON_EXCEL_TO_ACCESS, m_EXCELTOACCESSB);
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDC_LISTACCESS, m_AccessList);
DDX_Text(pDX, IDC_EDIT_BFYYBH, m_BFYYBH);
DDV_MinMaxUInt(pDX, m_BFYYBH, 0, 20);
DDX_Text(pDX, IDC_EDIT_XZBJCS, m_XZBJCS);
DDV_MinMaxUInt(pDX, m_XZBJCS, 1, 100);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExcel_To_AccessDlg, CDialog)
//{{AFX_MSG_MAP(CExcel_To_AccessDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_EXCEL_OPEN, OnButtonExcelOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExcel_To_AccessDlg message handlers
BOOL CExcel_To_AccessDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CExcel_To_AccessDlg::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 CExcel_To_AccessDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CExcel_To_AccessDlg::OnButtonExcelOpen()
{
// TODO: Add your control notification handler code here
CSpreadSheet SS("d:\\电话号码\\Temp.xls", "Sheet1");
CStringArray Rows, Column;
CString tempString = "";
CCSet mySet;
UpdateData();
m_AccessList.ResetContent();
{
int iColumn = 2;
int iCols = SS.GetTotalColumns();
int iRows = SS.GetTotalRows();
// 读取一列数据,并按行读出
for (int i = 1; i <= SS.GetTotalRows(); i++)
{
// 读取一行
SS.ReadRow(Rows, i);
CString strContents = "";
for (int j = 1; j <= Rows.GetSize(); j++)
{
if(j == 1)
strContents = Rows.GetAt(j-1);
else
strContents = strContents + " --> " + Rows.GetAt(j-1);
m_EXCEL_TO_ACCESS_PROGRESS.SetPos(0);
}
m_EXCEL_TO_ACCESS_PROGRESS.StepIt();
m_EXCELTOACCESSB.SetWindowText(strContents);
m_AccessList.AddString(strContents);
}
m_EXCEL_TO_ACCESS_PROGRESS.SetPos(0);
m_EXCELTOACCESSB.SetWindowText("数据导入完成!请关闭程序!");
m_EXCELOPENB.EnableWindow(FALSE);
m_AccessList.AddString("已将上述电话号码导入数据库中!");
}
}