• 7670阅读
  • 6回复

[提问]QAxObject 操作Word文档表格,合并单元格 [复制链接]

上一主题 下一主题
离线loveabcc
 

只看楼主 倒序阅读 楼主  发表于: 2016-12-20
谁有这方面的经验,指教下,
取出Range,总是失败
错误是 QAxBase::Error calling IDispatch member Range:Unknown error

离线loveabcc

只看该作者 1楼 发表于: 2016-12-20
自顶一下,有知道这方面知识的吗,比如说 VBA对应QT的函数,应该怎么找到对应的.
离线圣域天子

只看该作者 2楼 发表于: 2016-12-20
我也卡在这个问题上没解决过~~~
楼主对Word操作的其它接口都搞定了吗?
开个源吧~~~学习学习
取 UsedRange 的一段代码,不知对楼主是否有用:
  1. void TcMSWord::getUsedRange(int *topLeftRow, int *topLeftColumn, int *bottomRightRow, int *bottomRightColumn)
  2. {
  3.     QAxObject* range = m_document->querySubObject("Range");
  4.     *topLeftRow = range->property("Row").toInt();
  5.     *topLeftColumn = range->property("Column").toInt();
  6.     QAxObject *rows = range->querySubObject("Rows");
  7.     *bottomRightRow = *topLeftRow + rows->property("Count").toInt() - 1;
  8.     QAxObject *columns = range->querySubObject("Columns");
  9.     *bottomRightColumn = *topLeftColumn + columns->property("Count").toInt() - 1;
  10. }


离线loveabcc

只看该作者 3楼 发表于: 2016-12-20
回 圣域天子 的帖子
圣域天子:我也卡在这个问题上没解决过~~~
楼主对Word操作的其它接口都搞定了吗?
开个源吧~~~学习学习
取 UsedRange 的一段代码,不知对楼主是否有用:
void TcMSWord::getUsedRange(int *topLeftRow, int *topLeftColumn, int *bottomRightRow, int *bottomRightColumn)
....... (2016-12-20 10:58) 

加个QQ吧495259090,基本属于刚开始弄,CSDN上找了一个代码。
离线loveabcc

只看该作者 4楼 发表于: 2016-12-21
回 圣域天子 的帖子
圣域天子:我也卡在这个问题上没解决过~~~
楼主对Word操作的其它接口都搞定了吗?
开个源吧~~~学习学习
取 UsedRange 的一段代码,不知对楼主是否有用:
void TcMSWord::getUsedRange(int *topLeftRow, int *topLeftColumn, int *bottomRightRow, int *bottomRightColumn)
....... (2016-12-20 10:58) 

已经解决合并单元格
例子 合并 第一行 1-9单元格
QAxObject* cell11 = table->querySubObject(Cell(1,2));
QAxObject* cell19 = table-queryObject(cell(1,9));
cell11->dynamicCall("Merge(QAxObject*)", cell12->asVariant);

https://msdn.microsoft.com/en-us/library/aa212374(v=office.11).aspx 这里面有 VBA方法
离线圣域天子

只看该作者 5楼 发表于: 2016-12-22
回 loveabcc 的帖子
loveabcc:已经解决合并单元格
例子 合并 第一行 1-9单元格
QAxObject* cell11 = table->querySubObject(Cell(1,2));
QAxObject* cell19 = table-queryObject(cell(1,9));
....... (2016-12-21 10:44) 

cell(..)函数代码能提供一下吗?
离线lirus1234

只看该作者 6楼 发表于: 2017-07-21
回 loveabcc 的帖子
loveabcc:已经解决合并单元格
例子 合并 第一行 1-9单元格
QAxObject* cell11 = table->querySubObject(Cell(1,2));
QAxObject* cell19 = table-queryObject(cell(1,9));
....... (2016-12-21 10:44) 

你好  看你这个例子有点乱  

QAxObject* cell11 = table->querySubObject(Cell(1,2));
QAxObject* cell19 = table-queryObject(cell(1,9));

这两句的意思是找到需要合并的单元格的位置

cell11->dynamicCall("Merge(QAxObject*)", cell12->asVariant);

最后一句的cell12又是什么?

方便的话顺便将Cell(int,int)这个方法一起贴出来一下

万分感谢
快速回复
限100 字节
 
上一个 下一个