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

📄 excelsheetview.cpp

📁 用vc编写的将数据导入到excel的程序
💻 CPP
字号:
// excelsheetView.cpp : implementation of the CExcelsheetView class
//

#include "stdafx.h"
#include "excelsheet.h"

#include "excelsheetDoc.h"
#include "excelsheetView.h"

#include "abaoExcel.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CExcelsheetView

IMPLEMENT_DYNCREATE(CExcelsheetView, CFormView)

BEGIN_MESSAGE_MAP(CExcelsheetView, CFormView)
	//{{AFX_MSG_MAP(CExcelsheetView)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExcelsheetView construction/destruction

CExcelsheetView::CExcelsheetView()
	: CFormView(CExcelsheetView::IDD)
{
	//{{AFX_DATA_INIT(CExcelsheetView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here
	n=1;

}

CExcelsheetView::~CExcelsheetView()
{
}

void CExcelsheetView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExcelsheetView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BOOL CExcelsheetView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CExcelsheetView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

	if (CoInitialize(NULL)!=0) 
	{ 
		AfxMessageBox("初始化COM支持库失败!"); 
		exit(1); 
	} 

}

/////////////////////////////////////////////////////////////////////////////
// CExcelsheetView printing

BOOL CExcelsheetView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CExcelsheetView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CExcelsheetView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CExcelsheetView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CExcelsheetView diagnostics

#ifdef _DEBUG
void CExcelsheetView::AssertValid() const
{
	CFormView::AssertValid();
}

void CExcelsheetView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CExcelsheetDoc* CExcelsheetView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExcelsheetDoc)));
	return (CExcelsheetDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CExcelsheetView message handlers

void CExcelsheetView::OnButton1() 
{
	// TODO: Add your control notification handler code here

	AbaoExcel a;

//	CFileFind finder;
	
	CString str;
	CTime currenttime=CTime::GetCurrentTime();

	str=currenttime.Format("e:\\sheet\\%Y%m%d_%H%M%S");
//	str1=currenttime.Format("%H%M%S");
	

//	if (finder.FindFile(str))      //判断文件是否存在,若存在则打开,若不存在则创建新文件
//	{
//		a.Add(str);
//	}
//	else
//	{
//		a.Add(CString(""));
// 	}

	a.Add(CString(""));
//	a.SetVisible(true);
//	a.Copy(a.SelectSheet(n));
//	n++;
//	a.ActiveSheet().SetName(str1);
//	a.SelectSheet("sheet1");
	a.SelectSheet("sheet1").SetName("123");
	a.SetCell(1,1,3.14159267,6);
	long t=1000;
 	a.SetCell(1,1,t);
	a.SetCell(1,3,CString("CString"));
	a.SetCell(1,4,"C Style string");
	AbaoRange b(a.GetRange("A1:B1"));
	b.Merge();
	b.Border();
	b.SetHAlign(HAlignCenter);
	b.SetVAlign(VAlignTop);
	b=a.GetRange("B2");
	b.Border();
	b="123456";
	b=a.GetRange("C2");
	b=CString("CString");
	b=a.GetRange("D2");
	b="C Style string";
	b=a.GetRange("C1:D2");
	b.SetHAlign(HAlignCenter);
//	a.SelectSheet(1);
// 	a.SetCell(1,1,"内容都在sheet1里面呢");

	a.SaveAs(str);

	
}

⌨️ 快捷键说明

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