Qt ActiveX QAxObject格式Excel单元格注释
Qt ActiveX QAxObject format Excel cell comment
我想格式化Microsoft Excel 2010单元格注释(例如更改字体、粗体等)使用Qt 5。
我可以使用以下代码向单元格添加注释:
QAxObject* cellRange = m_activeWorksheet->querySubObject("Cells(int, int)", row, col);
cellRange->dynamicCall("AddComment(const QVariant&)", comment);
我还可以设置单元格注释的AutoSize属性:
QAxObject* axComment = cellRange->querySubObject("Comment");
QAxObject* shape = axComment->querySubObject("Shape");
shape->querySubObject("TextFrame")->setProperty("AutoSize", autosize);
但我无法更改"更深层次"的评论属性,例如TextFrame.Characters.Font.Bold.
设置单元格注释后,命令
shape->querySubObject("TextFrame")
返回一个非零指针,但是
shape->querySubObject("TextFrame")->querySubObject("Characters")
返回NULL。
如何使用QAxObject
格式化单元格注释?是否描述了不同QAxObject
的属性/子对象QAxObject
可访问?
以下代码没有任何效果:
shape->setProperty("AutoShapeType", 5);
-
问题可能是TextFrame没有属性
Characters
。相反,它有方法Characters
,但它的完整签名是Characters(Start, Length)
Qt文档说您应该指定完整签名,所以您可能应该使用查询值
shape->querySubObject("TextFrame")->querySubObject("Characters(Start,Length)")
-
不能将
AutoShapeType
设置为5
。AutoShapeType
的类型为MsoAutoShapeType,并且只允许指定值。
浏览Qt文档后,QAxBase dynamicCAll部分介绍了如何设置Excel单元格注释的形状使用动态调用:
QString comment("My comment");
QAxObject* cellRange = m_activeWorksheet->querySubObject("Cells(int, int)", cellRow, cellColumn);
cellRange->dynamicCall("AddComment(const QVariant&)", comment);
QAxObject* axComment = cellRange->querySubObject("Comment");
QAxObject* shape = axComment->querySubObject("Shape");
shape->dynamicCall("AutoShapeType", 5);
该值可以从Lol4t0的链接中找到:MsoAutoShapeType枚举。这里5用于获得一个圆角矩形(msoShapeRoundedRectangle)。下面是更改文本注释格式的剩余代码:
QAxObject* textFrame = shape->querySubObject("TextFrame");
QAxObject* chars = textFrame->querySubObject("Characters(int, int)", 1, comment.size());
QAxObject* font = chars->querySubObject("Font");
font->setProperty("Bold", false);
shape->querySubObject("TextFrame")->querySubObject("Characters(2, 3)")->querySubObject("Font")->setProperty("Size", 24);
相关文章:
- 将QIcon添加到QTableView单元格
- 当用户在qtablewidget中输入单元格时,如何获得信号?C++
- 查找矩阵中单元格的相邻元素
- C++:在多个线程中访问同一数组/向量的不同单元格是否会产生数据竞赛?
- 当我使用需要计算数组单元格地址的模板时,奇怪的C++行为
- PyQT - 在 QTableWidget 单元格中显示垂直文本
- 2D 数组,某些单元格保存特定数据
- 为什么通过定义另一个指针单元格,整个代码停止工作?
- CLI/C++dataGridView示例-设置comobox单元格列表的索引
- 用单元格表示迷宫
- 为什么不能使用 setData() 在 QTreeView 中设置单元格的背景颜色?
- 将 GtkTreeView 中的单元格设置为以编程方式编辑模式
- 如何防止Qt中的当前单元格更改信号或跳过"processing"?
- 将当前多边形数据单元与下一个多边形单元格 - VTK 进行比较
- VTK:尝试使用 vtkrubberbandpick&vtkHardwareSelector 选择区域中的可见单元格
- QTableWiget::cellChanged 信号不会为具有 QTableWidgetItem 的单元格发出
- 当存在空单元格时,用于 c++ 的 Tsv 文件解析器会突然结束
- C++ unordered_map<T,int> 如何区分空单元格和 0
- 基于单元格代替QTableWidget中的一行
- Qt ActiveX QAxObject格式Excel单元格注释