官方开发接口帮助文档
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
};
//值对应的描述
| 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