Coder Social home page Coder Social logo

mfc-excel's Introduction

MFC-Excel

MFC表格操作模板

使用说明

0.1 在项目中添加以下两个文件

CExcelOperation.h

CExcelOperation.cpp


1.1 右键CExcelOperation.cpp,选择属性

1.2 C/C++ -> 预编译头 ->不使用预编译头


2.1 选中MFC项目中,右键添加类,选择TypeLib

2.2 来源 -> 注册表,可用库类型 -> Microsoft Excel xx

2.3 接口选择以下七项

_Application

_Workbook

_Worksheet

Workbooks

Worksheets

Sheets

Rangs

2.4 将新生成的七个头文件中的"#import "...EXCEL.EXE" no_namespace"去掉

2.5 将CRange.h中的VARIANT DialogBox()改成VARIANT _DialogBox()


注意事项

1 如果在写操作后出现程序退出后,Excel进程没有退出。

可以在int CExcelOperation::closeExcelFile()试试添加m_wbExcelBook.Save();

int CExcelOperation::closeExcelFile()
{
	m_rangeBasicCells.ReleaseDispatch();
	m_wsSheet.ReleaseDispatch();
	m_wbExcelBook.Save();
	m_wbExcelBook.ReleaseDispatch();
	m_wbsExcelBooks.Close();
	m_wbsExcelBooks.ReleaseDispatch();
	m_appExcelServer.Quit();
	m_appExcelServer.ReleaseDispatch();
	return 0;
}

2 写操作示例

void MyCallBack(void *hFun)
{
	CExcelOperation *pExcelOper= (CExcelOperation*)hFun;
	long i = 0;
	long j = 0;
	CString csPortTmp;
	long lMaxRowNum = pExcelOper->getMaxRowNum();
	long lMaxColNum = pExcelOper->getMaxColNum();
	CRange rangeBasicCells = pExcelOper->getCell();
	CRange rangeTempCells;
	COleVariant covResult;
	string strValue = "abcdefghijklmn";

	i = 1;
	j = 1;
	rangeTempCells.AttachDispatch(rangeBasicCells.get_Item(COleVariant(i), COleVariant(j)).pdispVal);
	rangeTempCells.put_NumberFormat(COleVariant(strValue.c_str()));
}

mfc-excel's People

Contributors

featherw avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.