ZBLOG

QAxObject *currentCell = table->querySubObject("Cell(int,int)", row, cell)指向合并单元格是直接报错QAxBase: Error calling IDispatch member Cell: Exception thrown by server 且`mergeCells的前提是currentCell 已存在

这个错误通常是因为合并单元格的位置不正确导致的。建议在查询单元格之前,先获取所有已经合并过的单元格范围,然后判断当前要操作的单元格是否在这些范围内。

代码示例:

QAxObject *mergedCells = table->querySubObject("Range(const QVariant&)", "A1")->property("MergeArea");

if (mergedCells.isValid()) {
    int topRow = mergedCells.property("Row").toInt();
    int leftColumn = mergedCells.property("Column").toInt();
    int bottomRow = mergedCells.property("RowEnd").toInt();
    int rightColumn = mergedCells.property("ColumnEnd").toInt();

    if (row >= topRow && row <= bottomRow && cell >= leftColumn && cell <= rightColumn) {
        // 当前单元格在合并单元格内
        currentCell = table->querySubObject("Range(int,int)", topRow, leftColumn);
    } else {
        // 当前单元格不在合并单元格内
        currentCell = table->querySubObject("Cell(int,int)", row, cell);
    }
} else {
    // 没有合并单元格
    currentCell = table->querySubObject("Cell(int,int)", row, cell);
}

if (currentCell.isNull()) {
    qDebug() << "Failed to get the current cell!";
} else {
   // 操作当前单元格
}

需要注意的是,在以上代码示例中,“A1”指代了一个包含所有已经合并过的单元格的区域,你需要根据实际情况修改这个值。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=7063

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?