|
@@ -2,15 +2,15 @@
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
|
-#include <QDateTime>
|
|
|
-#include <QFileDialog>
|
|
|
-#include <QFile>
|
|
|
-#include <QTextStream>
|
|
|
-#include <ActiveQt/QAxObject>
|
|
|
-#include <ActiveQt/QAxWidget>
|
|
|
-#include <QTextStream>
|
|
|
-#include <ActiveQt/QAxBase>
|
|
|
-#include <QTextFormat>
|
|
|
+# include <QDateTime>
|
|
|
+# include <QFileDialog>
|
|
|
+# include <QFile>
|
|
|
+# include <QTextStream>
|
|
|
+# include <ActiveQt/QAxObject>
|
|
|
+# include <ActiveQt/QAxWidget>
|
|
|
+# include <QTextStream>
|
|
|
+# include <ActiveQt/QAxBase>
|
|
|
+# include <QTextFormat>
|
|
|
|
|
|
QWord::QWord(QObject *parent)
|
|
|
{
|
|
@@ -96,11 +96,17 @@ bool QWord::openword(bool bVisable)
|
|
|
{
|
|
|
m_word = new QAxObject();
|
|
|
bool bFlag = m_word->setControl("word.Application");
|
|
|
- if (!bFlag) { bFlag = m_word->setControl("kwps.Application"); }
|
|
|
- if (!bFlag) { return false; }
|
|
|
+ if (!bFlag) {
|
|
|
+ bFlag = m_word->setControl("kwps.Application");
|
|
|
+ }
|
|
|
+ if (!bFlag) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
m_word->setProperty("Visible", bVisable);
|
|
|
QAxObject *documents = m_word->querySubObject("Documents");
|
|
|
- if (!documents) { return false; }
|
|
|
+ if (!documents) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
documents->dynamicCall("Add(QString)", m_strFilePath);
|
|
|
m_bOpened = true;
|
|
|
return m_bOpened;
|
|
@@ -134,8 +140,10 @@ void QWord::close() //关闭 退出 析构时候也会自动调用一次
|
|
|
// m_document->dynamicCall("Close (boolean)",false);
|
|
|
// if(m_word)
|
|
|
// m_word->dynamicCall("Quit (void)");
|
|
|
- if (m_documents) delete m_documents;
|
|
|
- if (m_word) delete m_word;
|
|
|
+ if (m_documents)
|
|
|
+ delete m_documents;
|
|
|
+ if (m_word)
|
|
|
+ delete m_word;
|
|
|
m_document = NULL;
|
|
|
m_documents = NULL;
|
|
|
m_word = NULL;
|
|
@@ -151,7 +159,9 @@ void QWord::saveAs()
|
|
|
void QWord::setPageOrientation(int flag) //设置页面1 横向 还是 0竖向
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QString page;
|
|
|
switch (flag) {
|
|
|
case 0:
|
|
@@ -166,7 +176,9 @@ void QWord::setPageOrientation(int flag) //设置页面1 横向 还是 0竖
|
|
|
void QWord::setWordPageView(int flag)
|
|
|
{
|
|
|
QAxObject *viewPage = m_word->querySubObject("ActiveWindow");
|
|
|
- if (nullptr == viewPage) { return; }
|
|
|
+ if (nullptr == viewPage) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QString view;
|
|
|
switch (flag) {
|
|
|
case 1:
|
|
@@ -199,13 +211,17 @@ void QWord::setWordPageView(int flag)
|
|
|
void QWord::insertMoveDown() //插入回车
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
selection->dynamicCall("TypeParagraph(void)");
|
|
|
}
|
|
|
void QWord::insertText(const QString &text)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
selection->dynamicCall("TypeText(const QString&)", text);
|
|
|
}
|
|
|
|
|
@@ -213,7 +229,9 @@ QString QWord::GetText()
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
QString str;
|
|
|
- if (nullptr != selection) { str = selection->dynamicCall("GetText(void)").toString(); }
|
|
|
+ if (nullptr != selection) {
|
|
|
+ str = selection->dynamicCall("GetText(void)").toString();
|
|
|
+ }
|
|
|
|
|
|
return str;
|
|
|
}
|
|
@@ -221,7 +239,9 @@ QString QWord::GetText()
|
|
|
void QWord::setParagraphAlignment(int flag)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (flag == 0) {
|
|
|
selection->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphCenter");
|
|
|
} else if (flag == 1) {
|
|
@@ -234,13 +254,21 @@ void QWord::setParagraphAlignment(int flag)
|
|
|
void QWord::setRowAlignment(int tableIndex, int row, int flag)
|
|
|
{
|
|
|
QAxObject *tables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == tables) { return; }
|
|
|
+ if (nullptr == tables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = tables->querySubObject("Item(int)", tableIndex);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *Row = table->querySubObject("Rows(int)", row);
|
|
|
- if (nullptr == Row) { return; }
|
|
|
+ if (nullptr == Row) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *range = Row->querySubObject("Range");
|
|
|
- if (nullptr == range) { return; }
|
|
|
+ if (nullptr == range) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
Row->querySubObject("Alignment(int)", flag);
|
|
|
if (flag == 0) {
|
|
|
range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphCenter");
|
|
@@ -255,63 +283,95 @@ void QWord::setRowAlignment(int tableIndex, int row, int flag)
|
|
|
void QWord::setFontSize(int fontsize) //设置字体大小
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
selection->querySubObject("Font")->setProperty("Size", fontsize);
|
|
|
}
|
|
|
void QWord::setFontBold(bool flag)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
selection->querySubObject("Font")->setProperty("Bold", flag);
|
|
|
}
|
|
|
void QWord::setFontName(const QString &fontName)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
selection->querySubObject("Font")->setProperty("Name", fontName);
|
|
|
}
|
|
|
void QWord::setSelectionRange(int start, int end)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
selection->dynamicCall("SetRange(int, int)", start, end); //第1个字符后开始,到第9个字符结束范围
|
|
|
}
|
|
|
void QWord::getUsedRange(int *topLeftRow, int *topLeftColumn, int *bottomRightRow, int *bottomRightColumn)
|
|
|
{
|
|
|
QAxObject *range = m_document->querySubObject("Range");
|
|
|
- if (nullptr == range) { return; }
|
|
|
+ if (nullptr == range) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
*topLeftRow = range->property("Row").toInt();
|
|
|
- if (nullptr == topLeftRow) { return; }
|
|
|
+ if (nullptr == topLeftRow) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
*topLeftColumn = range->property("Column").toInt();
|
|
|
- if (nullptr == topLeftColumn) { return; }
|
|
|
+ if (nullptr == topLeftColumn) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *rows = range->querySubObject("Rows");
|
|
|
- if (nullptr == rows) { return; }
|
|
|
+ if (nullptr == rows) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
*bottomRightRow = *topLeftRow + rows->property("Count").toInt() - 1;
|
|
|
- if (nullptr == bottomRightRow) { return; }
|
|
|
+ if (nullptr == bottomRightRow) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *columns = range->querySubObject("Columns");
|
|
|
- if (nullptr == columns) { return; }
|
|
|
+ if (nullptr == columns) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
*bottomRightColumn = *topLeftColumn + columns->property("Count").toInt() - 1;
|
|
|
- if (nullptr == bottomRightColumn) { return; }
|
|
|
+ if (nullptr == bottomRightColumn) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void QWord::intsertTable(int row, int column)
|
|
|
{
|
|
|
QAxObject *tables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == tables) { return; }
|
|
|
+ if (nullptr == tables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *range = selection->querySubObject("Range");
|
|
|
- if (nullptr == range) { return; }
|
|
|
+ if (nullptr == range) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QVariantList params;
|
|
|
params.append(range->asVariant());
|
|
|
params.append(row);
|
|
|
params.append(column);
|
|
|
tables->querySubObject("Add(QAxObject*, int, int, QVariant&, QVariant&)", params);
|
|
|
QAxObject *table = selection->querySubObject("Tables(int)", 1);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
table->setProperty("Style", "网格型");
|
|
|
QAxObject *Borders = table->querySubObject("Borders");
|
|
|
- if (nullptr == Borders) { return; }
|
|
|
+ if (nullptr == Borders) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
Borders->setProperty("InsideLineStyle", 1);
|
|
|
Borders->setProperty("OutsideLineStyle", 1);
|
|
|
/*QString doc = Borders->generateDocumentation();
|
|
@@ -323,21 +383,31 @@ void QWord::intsertTable(int row, int column)
|
|
|
void QWord::intsertTable(int tableIndex, int row, int column)
|
|
|
{
|
|
|
QAxObject *tables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == tables) { return; }
|
|
|
+ if (nullptr == tables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *range = selection->querySubObject("Range");
|
|
|
- if (nullptr == range) { return; }
|
|
|
+ if (nullptr == range) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QVariantList params;
|
|
|
params.append(range->asVariant());
|
|
|
params.append(row);
|
|
|
params.append(column);
|
|
|
tables->querySubObject("Add(QAxObject*, int, int, QVariant&, QVariant&)", params);
|
|
|
QAxObject *table = selection->querySubObject("Tables(int)", tableIndex);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
table->setProperty("Style", "网格型");
|
|
|
QAxObject *Borders = table->querySubObject("Borders");
|
|
|
- if (nullptr == Borders) { return; }
|
|
|
+ if (nullptr == Borders) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
Borders->setProperty("InsideLineStyle", 1);
|
|
|
Borders->setProperty("OutsideLineStyle", 1);
|
|
|
/*QString doc = Borders->generateDocumentation();
|
|
@@ -350,15 +420,21 @@ void QWord::intsertTable(int tableIndex, int row, int column)
|
|
|
void QWord::setColumnWidth(int column, int width) //设置列宽
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = selection->querySubObject("Tables(1)");
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
table->querySubObject("Columns(int)", column)->setProperty("Width", width);
|
|
|
}
|
|
|
void QWord::setCellString(int nTable, int row, int column, const QString &text)
|
|
|
{
|
|
|
QAxObject *pTables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == pTables) { return; }
|
|
|
+ if (nullptr == pTables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = pTables->querySubObject("Item(int)", nTable);
|
|
|
if (table) {
|
|
|
table->querySubObject("Cell(int,int)", row, column)
|
|
@@ -369,14 +445,22 @@ void QWord::setCellString(int nTable, int row, int column, const QString &text)
|
|
|
void QWord::MergeCells(int tableIndex, int nStartRow, int nStartCol, int nEndRow, int nEndCol) //合并单元格
|
|
|
{
|
|
|
QAxObject *tables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == tables) { return; }
|
|
|
+ if (nullptr == tables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = tables->querySubObject("Item(int)", tableIndex);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (table) {
|
|
|
QAxObject *StartCell = table->querySubObject("Cell(int, int)", nStartRow, nStartCol);
|
|
|
QAxObject *EndCell = table->querySubObject("Cell(int, int)", nEndRow, nEndCol);
|
|
|
- if (nullptr == StartCell) { return; }
|
|
|
- if (nullptr == EndCell) { return; }
|
|
|
+ if (nullptr == StartCell) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (nullptr == EndCell) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
StartCell->querySubObject("Merge(QAxObject *)", EndCell->asVariant());
|
|
|
}
|
|
|
}
|
|
@@ -393,35 +477,53 @@ void QWord::MergeCells(int tableIndex, int nStartRow, int nStartCol, int nEndRow
|
|
|
void QWord::setColumnHeight(int nTable, int column, int height)
|
|
|
{
|
|
|
QAxObject *pTables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == pTables) { return; }
|
|
|
+ if (nullptr == pTables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = pTables->querySubObject("Item(int)", nTable);
|
|
|
- if (table) { table->querySubObject("Columns(int)", column)->setProperty("Hight", height); }
|
|
|
+ if (table) {
|
|
|
+ table->querySubObject("Columns(int)", column)->setProperty("Hight", height);
|
|
|
+ }
|
|
|
}
|
|
|
void QWord::setRowHeight(int nTable, int Row, int height)
|
|
|
{
|
|
|
QAxObject *pTables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == pTables) { return; }
|
|
|
+ if (nullptr == pTables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = pTables->querySubObject("Item(int)", nTable);
|
|
|
|
|
|
- if (table) { table->querySubObject("Rows(int)", Row)->setProperty("Hight", height); }
|
|
|
+ if (table) {
|
|
|
+ table->querySubObject("Rows(int)", Row)->setProperty("Hight", height);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void QWord::setColumnHeight(int column, int height) //设置列高
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = selection->querySubObject("Tables(1)");
|
|
|
- if (table) { table->querySubObject("Columns(int)", column)->setProperty("Hight", height); }
|
|
|
+ if (table) {
|
|
|
+ table->querySubObject("Columns(int)", column)->setProperty("Hight", height);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void QWord::setCellString(int row, int column, const QString &text)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = selection->querySubObject("Tables(1)");
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *rows = table->querySubObject("Rows");
|
|
|
- if (rows) { return; }
|
|
|
+ if (rows) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
int Count = rows->dynamicCall("Count").toInt();
|
|
|
table->querySubObject("Cell(int, int)", row, column)
|
|
|
->querySubObject("Range")
|
|
@@ -431,17 +533,25 @@ void QWord::setCellString(int row, int column, const QString &text)
|
|
|
void QWord::setCellFontBold(int row, int column, bool isBold) //设置内容粗体 isBold控制是否粗体
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = selection->querySubObject("Tables(1)");
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
table->querySubObject("Cell(int, int)", row, column)->querySubObject("Range")->dynamicCall("SetBold(int)", isBold);
|
|
|
}
|
|
|
void QWord::setCellFontSize(int row, int column, int size) //设置文字大小
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = selection->querySubObject("Tables(1)");
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
table->querySubObject("Cell(int, int)", row, column)
|
|
|
->querySubObject("Range")
|
|
|
->querySubObject("Font")
|
|
@@ -458,13 +568,17 @@ int QWord::getTableCount()
|
|
|
{
|
|
|
QAxObject *tables = m_document->querySubObject("Tables");
|
|
|
int val;
|
|
|
- if (nullptr != tables) { val = tables->property("Count").toInt(); }
|
|
|
+ if (nullptr != tables) {
|
|
|
+ val = tables->property("Count").toInt();
|
|
|
+ }
|
|
|
return val;
|
|
|
}
|
|
|
void QWord::moveForEnd()
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QVariantList params;
|
|
|
params.append(6);
|
|
|
params.append(0);
|
|
@@ -473,36 +587,54 @@ void QWord::moveForEnd()
|
|
|
void QWord::insertCellPic(int row, int column, const QString &picPath)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = selection->querySubObject("Tables(1)");
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *range = table->querySubObject("Cell(int, int)", row, column)->querySubObject("Range");
|
|
|
- if (nullptr == range) { return; }
|
|
|
+ if (nullptr == range) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
range->querySubObject("InlineShapes")->dynamicCall("AddPicture(const QString&)", picPath);
|
|
|
}
|
|
|
void QWord::setTableAutoFitBehavior(int flag)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = selection->querySubObject("Tables(1)");
|
|
|
- if (nullptr == table) { return; }
|
|
|
- if (0 <= flag && flag <= 2) table->dynamicCall("AutoFitBehavior(WdAutoFitBehavior)", flag);
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (0 <= flag && flag <= 2)
|
|
|
+ table->dynamicCall("AutoFitBehavior(WdAutoFitBehavior)", flag);
|
|
|
}
|
|
|
void QWord::deleteSelectColumn(int column)
|
|
|
{
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = selection->querySubObject("Tables(1)");
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *columns = table->querySubObject("Columns(int)", column);
|
|
|
- if (nullptr == columns) { return; }
|
|
|
+ if (nullptr == columns) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
columns->dynamicCall("Delete()");
|
|
|
}
|
|
|
|
|
|
void QWord::setOptionCheckSpell(bool flags)
|
|
|
{
|
|
|
QAxObject *opetions = m_word->querySubObject("Options");
|
|
|
- if (!opetions) return;
|
|
|
+ if (!opetions)
|
|
|
+ return;
|
|
|
opetions->setProperty("CheckGrammarAsYouType", flags);
|
|
|
opetions->setProperty("CheckGrammarWithSpelling", flags);
|
|
|
opetions->setProperty("ContextualSpeller", flags);
|
|
@@ -512,11 +644,17 @@ void QWord::setOptionCheckSpell(bool flags)
|
|
|
void QWord::addTableRow(int tableIndex, int nRow, int rowCount)
|
|
|
{
|
|
|
QAxObject *tables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == tables) { return; }
|
|
|
+ if (nullptr == tables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = tables->querySubObject("Item(int)", tableIndex);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *rows = table->querySubObject("Rows");
|
|
|
- if (nullptr == rows) { return; }
|
|
|
+ if (nullptr == rows) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
int Count = rows->dynamicCall("Count").toInt();
|
|
|
if (0 < nRow && nRow <= Count) {
|
|
|
for (int i = 0; i < rowCount; ++i) {
|
|
@@ -538,14 +676,22 @@ void QWord::insertTable(int tableIndex, int row, int column)
|
|
|
{
|
|
|
|
|
|
QAxObject *tables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == tables) { return; }
|
|
|
+ if (nullptr == tables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = tables->querySubObject("Item(int)", tableIndex);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
// QAxObject* rows =table->querySubObject("Rows");
|
|
|
QAxObject *selection = m_word->querySubObject("Selection");
|
|
|
- if (nullptr == selection) { return; }
|
|
|
+ if (nullptr == selection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *range = selection->querySubObject("Range");
|
|
|
- if (nullptr == range) { return; }
|
|
|
+ if (nullptr == range) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QVariantList params;
|
|
|
params.append(range->asVariant());
|
|
|
params.append(row);
|
|
@@ -555,7 +701,9 @@ void QWord::insertTable(int tableIndex, int row, int column)
|
|
|
table->setProperty("Style", "网格型");
|
|
|
|
|
|
QAxObject *Borders = table->querySubObject("Borders");
|
|
|
- if (nullptr == Borders) { return; }
|
|
|
+ if (nullptr == Borders) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
Borders->setProperty("InsideLineStyle", 1);
|
|
|
Borders->setProperty("OutsideLineStyle", 1);
|
|
|
}
|
|
@@ -563,20 +711,30 @@ void QWord::insertTable(int tableIndex, int row, int column)
|
|
|
void QWord::setColumnWidth(int nTable, int column, int width)
|
|
|
{
|
|
|
QAxObject *pTables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == pTables) { return; }
|
|
|
+ if (nullptr == pTables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = pTables->querySubObject("Item(int)", nTable);
|
|
|
- if (table) { table->querySubObject("Columns(int)", column)->setProperty("width", width); }
|
|
|
+ if (table) {
|
|
|
+ table->querySubObject("Columns(int)", column)->setProperty("width", width);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//在表格中插入图片
|
|
|
void QWord::insertCellPic(int nTable, int row, int column, const QString &picPath)
|
|
|
{
|
|
|
QAxObject *pTables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == pTables) { return; }
|
|
|
+ if (nullptr == pTables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = pTables->querySubObject("Item(int)", nTable);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *range = table->querySubObject("Cell(int,int )", row, column)->querySubObject("Range");
|
|
|
- if (nullptr == range) { return; }
|
|
|
+ if (nullptr == range) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
range->querySubObject("InlineShapes")->dynamicCall("AddPicture(const QString&)", picPath);
|
|
|
}
|
|
|
|
|
@@ -584,18 +742,26 @@ void QWord::insertCellPic(int nTable, int row, int column, const QString &picPat
|
|
|
void QWord::setCellFontBold(int nTable, int row, int column, bool isBold)
|
|
|
{
|
|
|
QAxObject *pTables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == pTables) { return; }
|
|
|
+ if (nullptr == pTables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = pTables->querySubObject("Item(int)", nTable);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
table->querySubObject("Cell(int,int )", row, column)->querySubObject("Range")->dynamicCall("SetBold(int)", isBold);
|
|
|
}
|
|
|
//设置文字大小
|
|
|
void QWord::setCellFontSize(int nTable, int row, int column, int size)
|
|
|
{
|
|
|
QAxObject *pTables = m_document->querySubObject("Tables");
|
|
|
- if (nullptr == pTables) { return; }
|
|
|
+ if (nullptr == pTables) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
QAxObject *table = pTables->querySubObject("Item(int)", nTable);
|
|
|
- if (nullptr == table) { return; }
|
|
|
+ if (nullptr == table) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
table->querySubObject("Cell(int,int)", row, column)
|
|
|
->querySubObject("Range")
|
|
|
->querySubObject("Font")
|
|
@@ -604,7 +770,9 @@ void QWord::setCellFontSize(int nTable, int row, int column, int size)
|
|
|
|
|
|
void QWord::setVisible(bool isVisible)
|
|
|
{
|
|
|
- if (m_word != nullptr) { m_word->setProperty("Visible", isVisible); }
|
|
|
+ if (m_word != nullptr) {
|
|
|
+ m_word->setProperty("Visible", isVisible);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endif
|