MFC 下开发Office Word2010报表生成方法-- 一、准备工作

官方开发接口帮助文档

https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word(v=office.14).aspx



//枚举对应值

enum WdUnits
{
    wdCharacter = 1,
    wdWord = 2,
    wdSentence = 3,
    wdParagraph = 4,
    wdLine = 5,
    wdStory = 6,
    wdScreen = 7,
    wdSection = 8,
    wdColumn = 9,
    wdRow = 10,
    wdWindow = 11,
    wdCell = 12,
    wdCharacterFormatting = 13,
    wdParagraphFormatting = 14,
    wdTable = 15,
    wdItem = 16
};


//值对应的描述


Member name

Description

wdCharacter

A character.

wdWord

A word.

wdSentence

A sentence.

wdParagraph

A paragraph.

wdLine

A line.

wdStory

A story.

wdScreen

The screen dimensions.

wdSection

A section.

wdColumn

A column.

wdRow

A row.

wdWindow

A window.

wdCell

A cell.

wdCharacterFormatting

Character formatting.

wdParagraphFormatting

Paragraph formatting.

wdTable

A table.

wdItem

The selected item.



1、自己封装的类包含以下接口。(往任意书签位置插入字符,往任意书签位置插入图片,往任意位置插入表格,不过插入表格需要自己根据需要插入的数据数量动态绘制)

      满足报表生成的基本功能。不需要从头到尾用代码繁琐的绘制word文档。只需要提前准备一份模板。然后在指定的位置插入文字、图片、表格就OK了。


/************************************************************************** 
*  @Copyright (c) 2016, QGM, All rights reserved. 

*  @file     : MyWord.h
*  @version  : ver 1.0

*  @author   : qgm
*  @date     : 2016/7/14 17:15:13
*  @describe : 小光封装 office word2010文档操作类
*  @modify   : 无

**************************************************************************/ 
#pragma once
#include <vector>
using namespace std;
#include "ShareHead.h"

#include "CApplication.h"
#include "CWindow0.h"
#include "CView0.h"
#include "CRange.h"
#include "CSelection.h "
#include "CDocuments.h"
#include "CDocument0.h"
#include "CBookmarks.h"
#include "CBookmark0.h"
#include "CFields.h"
#include "CField.h"
#include "CSections.h"
#include "CSection.h"
#include "CnlineShapes.h"
#include "CnlineShape.h"
#include "CTables0.h"
#include "CTable0.h"
#include "CBorders.h"
#include "CBorder.h"
#include "CCells.h"
#include "CCell.h"
#include "CParagraphFormat.h"





class CMyWord
{
public:
	CMyWord(void);
	~CMyWord(void);

protected:
	//--------声明   
	CApplication	m_wordApp;     //Word应用程序对象   
	CDocuments		m_wordDocs;    //文档对象集合   
	CDocument0		m_wordDoc;     //文档      
	CWindow0		window;   
	CView0			view;     
	CRange			range;  
	CSections		sections;
	CSection		section;
	CBookmarks      bookmarks;		//书签集对象   
	CBookmark0      bookmark;       //书签
	CFields			fields;         //域对象   
	CField			field; 
	CTables0		tables;
	CTable0			table;			//表
	CCells			cells;
	CCell			cell;			//单元格
	CParagraphFormat paragraphFormat; //对齐方式
	CSelection		 selection;		//选择区域


	COleVariant  m_vUnit;	//((long)1);
	COleVariant  m_vCount;	//((long)nDelta);
	COleVariant  m_vExtend;	//((long)1);

public:

	bool InitWord();

	void OpenWord(CString wordDotPaht);

	/** 
	* @describe:   往书签位置插入字符串内容
	* @param[in]:  strbookmark 书签名称
	* @param[in]:  strContent 内容
	* @return:      
	*/
	void InsertBookMark(CString strbookmark,CString strContent);


	/** 
	* @describe:   往书签位置插入图片
	* @param[in]:  strbookmark 书签名称
	* @param[in]:  strPicPath 图片路径
	* @return:     无
	*/
	void InsertPicture(CString strbookmark,CString strPicPath);


	/** 
	* @describe:   插入信道占用度数据到表中
	* @param[in]:  strbookmark 书签名称
	* @param[in]:  map<int,SIGOCCSTRUCT> 
	* @return:     无
	*/
	void InsertSigOccTable(CString strbookmark,map<int,SIGOCCSTRUCT> tableData);



	/** 
	* @describe:   往书签出插入频段占用度表
	* @param[in]:  strbookmark 插入表格的书签处
	* @param[in]:  map<int,FREQSECTOCCSTRUCT> 频段占用度数据
	* @return:     无
	*/
	void InsertFreqSectOccTable(CString strbookmark,vector<CString> porvAndCity,map<int,FREQSECTOCCSTRUCT> tableData);




	/** 
	* @describe:   往书签出插入信号覆盖率表
	* @param[in]:  strbookmark 
	* @param[in]:  porvAndCity 
	* @param[in]:  map<int,SIGCOVERRATESTRUCT> 
	* @return:     无
	*/
	void InsertSigCoverRateTable(CString strbookmark,vector<CString> porvAndCity,map<int,SIGCOVERRATESTRUCT> tableData);



	void CreateTable(CString strbookmark,long rowCount, long colCount);


	/** 
	* @describe:   文档保存
	* @param[in]:  filePath 保存路径
	* @return:      
	*/
	bool SaveCurDocTo(CString filePath);

	/** 
	* @describe:   退出关闭word显示
	* @return:      
	*/
	void QuitWord();


	//位置移动
	bool MoveRight(int nCells);
	bool MoveLeft(int nCells);
	bool MoveUp(int nCells);
	bool MoveDown(int nCells);
	bool MoveEnd(void);

	bool MoveToDocEnd(void);

protected:
	CString GetAppPath(void);

};

效果图:




他人参考资料:http://blog.csdn.net/xiangjianbo127/article/category/1350852

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值