www.pudn.com > Excel_To_Access.rar > Excel_To_AccessView.cpp
// Excel_To_AccessView.cpp : implementation of the CExcel_To_AccessView class
//
#include "stdafx.h"
#include "Excel_To_Access.h"
#include "Excel_To_AccessSet.h"
#include "Excel_To_AccessDoc.h"
#include "Excel_To_AccessView.h"
#include "CSpreadSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExcel_To_AccessView
IMPLEMENT_DYNCREATE(CExcel_To_AccessView, CRecordView)
BEGIN_MESSAGE_MAP(CExcel_To_AccessView, CRecordView)
//{{AFX_MSG_MAP(CExcel_To_AccessView)
ON_BN_CLICKED(IDC_BUTTON_EXCEL_OPEN, OnButtonExcelOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExcel_To_AccessView construction/destruction
CExcel_To_AccessView::CExcel_To_AccessView()
: CRecordView(CExcel_To_AccessView::IDD)
{
//{{AFX_DATA_INIT(CExcel_To_AccessView)
m_pSet = NULL;
m_BFYYBH = 0;
m_XZBJCS = 1;
m_SQH = _T("默认");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CExcel_To_AccessView::~CExcel_To_AccessView()
{
}
void CExcel_To_AccessView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExcel_To_AccessView)
DDX_Control(pDX, IDC_BUTTON_EXCEL_OPEN, m_EXCELOPENB);
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);
DDX_Text(pDX, IDC_EDIT_SQH, m_SQH);
//}}AFX_DATA_MAP
}
BOOL CExcel_To_AccessView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CExcel_To_AccessView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_excel_To_AccessSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CExcel_To_AccessView diagnostics
#ifdef _DEBUG
void CExcel_To_AccessView::AssertValid() const
{
CRecordView::AssertValid();
}
void CExcel_To_AccessView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CExcel_To_AccessDoc* CExcel_To_AccessView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExcel_To_AccessDoc)));
return (CExcel_To_AccessDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExcel_To_AccessView database support
CRecordset* CExcel_To_AccessView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CExcel_To_AccessView message handlers
void CExcel_To_AccessView::OnButtonExcelOpen()
{
// TODO: Add your control notification handler code here
CSpreadSheet SS("d:\\电话号码\\Temp.xls", "Sheet1");
CStringArray Rows, Column;
CString tempString = "";
CExcel_To_AccessSet mySet;
UpdateData(TRUE);
m_AccessList.ResetContent();
mySet.Open();
CTime t(2030,1,1,1,1,1);
{
int iColumn = 2;
int iCols = SS.GetTotalColumns();
int iRows = SS.GetTotalRows();
//CString str;
//str.Format("%d",iRows);
//AfxMessageBox(str);
// 读取一列数据,并按行读出
for (int i = 2; 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);
strContents = Rows.GetAt(0);
strContents.Replace(".0","");
}
if(strContents!="")
{
mySet.AddNew();
mySet.m_column5=strContents;
mySet.m_column12=m_XZBJCS;
mySet.m_column7=m_BFYYBH;
mySet.m_column11=t;
mySet.m_column3=m_SQH;
mySet.Update();
m_AccessList.AddString(strContents);
}
}
mySet.Close();
m_EXCELOPENB.EnableWindow(FALSE);
m_AccessList.AddString("已将上述电话号码导入数据库中!");
}
}