欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

QAxBase Excel生成单元格超链接

程序员文章站 2022-04-29 17:46:08
...

excel中增加超链接的接口,一直不知道第一个参数Anchor在Qt中要怎么体现。

QAxBase Excel生成单元格超链接

翻看帮助文件,发现一个asVariant方法可以返回一个Range接口

QAxBase Excel生成单元格超链接

接下来的代码就简单了:

QAxObject *p_application = new QAxObject("Excel.Application");
p_application->dynamicCall("SetVisible(bool)", false);
p_application->setProperty("DisplayAlerts", false);
QAxObject *p_workbooks = p_application->querySubObject("Workbooks");
p_workbooks->dynamicCall( "Open(const QString &)", "D:/demo.xls" );
QAxObject *p_workbook = p_application->querySubObject("ActiveWorkBook");
QAxObject *pSheet = p_workbook->querySubObject( "Worksheets(int)", 1 );

QString s_fn = "file:///d:\\image\\1.jpg";

QAxObject *range = pSheet->querySubObject("Cells(int,int)", 1, 1);
QAxObject *hyperlinks = range->querySubObject("Hyperlinks");
hyperlinks->dynamicCall("Add(QVariant, QString, QString, QString, QString)", range->asVariant(), s_fn, "", "", QString("123"));
p_workbook->dynamicCall( "SaveAs( const QString&, int, const QString&, const QString&, bool, bool )", "D:\\demo.xls", 56, QString(""), QString(""), false, false );
p_workbook->dynamicCall( "Close()" );
p_application->dynamicCall("Quit()");