DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DA::DAAxObjectWordWrapper类 参考

word操作封装 更多...

#include <DAAxObjectWordWrapper.h>

类 DA::DAAxObjectWordWrapper 继承关系图:

class  PrivateData
 

Public 成员函数

 DAAxObjectWordWrapper (QObject *par=nullptr)
 
void reloadApp ()
 这是调用quit后,如果还要继续操作,可以调用此函数
 
bool open (const QString &docfile, bool isvisible=false)
 打开
 
bool isInitialize () const
 是否初始化完成
 
bool isHaveDocument () const
 是否存在文档
 
void quit ()
 退出,正常用户无需手动调用
 
void close ()
 关闭
 
void save ()
 保存
 
bool saveAs (const QString &docfile)
 另存
 
bool replaceMark (const QString &markName, const QVariant &replaceContent)
 替换标签内容
 
bool insertTextAtMark (const QString &markName, const QString &replaceContent)
 在mark(书签)位置添加文本
 
bool insertPictureAtMark (const QString &markName, const QString &picturePath)
 在mark(书签)位置添加图片
 
DAAxObjectWordTableWrapper insertTableAtMark (const QString &markName, int rowCount, int colCount)
 在书签处插入表格
 

详细描述

word操作封装

下面这个例子是用dot模板实现word的修改的案例,提前准备好一个word的模板,并定义好标签,通过replaceMark , 以及insertPictureAtMark 等函数即可实现模板的修改

QString templatePath;
...
DAAxObjectWordWrapper word;
if (!word.isInitialize()) {
return;
}
if (!word.open(templatePath)) {
return;
}
word.replaceMark("da_create_year", QDate::currentDate().year());
word.replaceMark("da_create_month", QDate::currentDate().month());
word.insertPictureAtMark("da_picture_air_topology", mTopologyPicturePath);

针对有表格的操作,可以通过insertTableAtMark 函数插入一个表格,返回一个

参见
DAAxObjectWordTableWrapper 对象 ,通过操作
DAAxObjectWordTableWrapper 对象实现表格的插入
DAColumnTable< QString > table; // 这是一个内存表
......
DAAxObjectWordTableWrapper tableAx = word->insertTableAtMark(mark,table.rowCount() + 1, table.columnCount());
if (!tableAx.isNull()) {
//先写表头
int cc = table.columnCount();
QStringList header = table.columnNames();
for (int i = 0; i < cc; ++i) {
tableAx.setCellText(0, i, header[ i ]);
}
//写表内容
int rr = table.rowCount();
for (int r = 0; r < rr; ++r) {
for (int c = 0; c < cc; ++c) {
tableAx.setCellText(r + 1, c, table.cell(r, c));
}
}
}
针对word的表格的封装
Definition DAAxObjectWordTableWrapper.h:12
bool isNull() const
判断是否为空
Definition DAAxObjectWordTableWrapper.cpp:14
void setCellText(int row, int col, const QString &text)
设置文本,注意,row,col从0开始算
Definition DAAxObjectWordTableWrapper.cpp:95
列族表
Definition DAColumnTable.hpp:19
int rowCount() const
表的行数
Definition DAColumnTable.hpp:228
T cell(int r, int c) const
获取单元格
Definition DAColumnTable.hpp:266
int columnCount() const
表的列数
Definition DAColumnTable.hpp:234
QStringList columnNames() const
colNames
Definition DAColumnTable.hpp:499

成员函数说明

◆ close()

void DA::DAAxObjectWordWrapper::close ( )

关闭

参数
on

◆ insertPictureAtMark()

bool DA::DAAxObjectWordWrapper::insertPictureAtMark ( const QString &  markName,
const QString &  picturePath 
)

在mark(书签)位置添加图片

参数
markName书签名
picturePath图片路径
返回

◆ insertTableAtMark()

DAAxObjectWordTableWrapper DA::DAAxObjectWordWrapper::insertTableAtMark ( const QString &  markName,
int  rowCount,
int  colCount 
)

在书签处插入表格

参数
markName书签名
rowCount行数
colCount列数
返回

◆ insertTextAtMark()

bool DA::DAAxObjectWordWrapper::insertTextAtMark ( const QString &  markName,
const QString &  replaceContent 
)

在mark(书签)位置添加文本

参数
markName书签名
replaceContent内容
返回

◆ isHaveDocument()

bool DA::DAAxObjectWordWrapper::isHaveDocument ( ) const

是否存在文档

返回

◆ isInitialize()

bool DA::DAAxObjectWordWrapper::isInitialize ( ) const

是否初始化完成

返回

◆ open()

bool DA::DAAxObjectWordWrapper::open ( const QString &  docfile,
bool  isvisible = false 
)

打开

参数
docfile
isvisible
返回

◆ replaceMark()

bool DA::DAAxObjectWordWrapper::replaceMark ( const QString &  markName,
const QVariant &  replaceContent 
)

替换标签内容

参数
markName标签名
replaceContent标签内容
返回

◆ saveAs()

bool DA::DAAxObjectWordWrapper::saveAs ( const QString &  docfile)

另存

参数
docfile

该类的文档由以下文件生成: