英文:
Where can I find the Qt operating Word document?
问题
QAxObject *document = documents->querySubObject("Open(const QString&, bool)", inFile1, true);
QAxObject *selection = axObject.querySubObject("Selection");
...
document->dynamicCall("SaveAs(const QString&)", outFile);
document->dynamicCall("Close()");
我不是在谈论这些Qt函数querySubObject
和dynamicCall
。我在谈论的是Word / ActiveX函数Open
、SaveAs
和Close
...
我只能瞥见一小部分这些函数在某些示例代码片段中。我在哪里可以找到完整的文档?
看起来像是ms-word函数,但考虑到Open(const QString&, bool)
,有QString
,这消除了这个想法。
英文:
QAxObject *document = documents->querySubObject("Open(const QString&, bool)", inFile1, true);
QAxObject *selection = axObject.querySubObject("Selection");
...
document->dynamicCall("SaveAs(const QString&)", outFile);
document->dynamicCall("Close()");
I'm not talking about these Qt functions querySubObject
, dynamicCall
. I'm talking about the Word / ActiveX functions Open
, SaveAs
, Close
...
I only can glimpse a small part of these functions in some example code fragment. Where can I find the full document?
It seems ms-word functions, but considering Open(const QString&, bool)
, there's QString
, that dispels the idea.
答案1
得分: 1
显然,你链接的问题已经回答了你的问题,但是看到被接受的答案没有任何解释,所以让我们首先看看那里缺少什么,然后是正确的解决方案(被接受的答案不是)。
你需要知道的是,Qt提供了转换函数(在ActiveQt的几个文件中)。以下是用于说明QString
的示例:
static inline BSTR QStringToBSTR(const QString &str)
{
return SysAllocStringLen(reinterpret_cast<const OLECHAR*>(str.unicode()), UINT(str.length()));
}
对于QAxBase::querySubObject
来说,重要的是另外一些函数对于该方法的所有参数的Qt到ActiveX类型的转换以及相反的转换:QVariantToVARIANT
和VARIANTToQVariant
。
正确的解决方案是使用同一问题中的最高票答案,即:
- 在WinWord上运行dumpcpp.exe。它会创建你需要用于与Word一起工作的头文件,就像你在VBA上一样简单。
- 以与在VBA中相同的方式使用
Word
命名空间中的类。
在上述最高票答案和Qt文档之间,应该清楚地看到这种方法有多简单。
英文:
Obviously, the question you linked alredy answers yours but seeing how the accepted answer comes with no explanations at all -> Let us first go through what is missing there, then the correct solution (which the accepted answer is not).
What you need to know is that Qt provides conversion functions (in several files from ActiveQt). Example to illustrate QString
:
static inline BSTR QStringToBSTR(const QString &str)
{
return SysAllocStringLen(reinterpret_cast<const OLECHAR*>(str.unicode()), UINT(str.length()));
}
What matters for QAxBase::querySubObject
is elsewhere: the pair of functions QVariantToVARIANT
and VARIANTToQVariant
manage the conversion from Qt to ActiveX type and back for all the method's parameters.
The correct solution is to use the most voted answer from that same question, that is:
- run dumpcpp.exe on WinWord. It creates the header you need to work with Word as simply as if you were on VBA.
- Use the classes in the
Word
namespace the same way you would do in VBA.
Between the above most voted answer and Qt documentation, it should be clear how much more simple this approach is.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论