你可以在哪里找到Qt操作的Word文档?

huangapple go评论54阅读模式
英文:

Where can I find the Qt operating Word document?

问题

Qt操作Word示例

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函数querySubObjectdynamicCall。我在谈论的是Word / ActiveX函数OpenSaveAsClose...

我只能瞥见一小部分这些函数在某些示例代码片段中。我在哪里可以找到完整的文档?

看起来像是ms-word函数,但考虑到Open(const QString&, bool),有QString,这消除了这个想法。

英文:

Qt operating Word example

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类型的转换以及相反的转换:QVariantToVARIANTVARIANTToQVariant

正确的解决方案是使用同一问题中的最高票答案,即:

  1. 在WinWord上运行dumpcpp.exe。它会创建你需要用于与Word一起工作的头文件,就像你在VBA上一样简单。
  2. 以与在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:

  1. run dumpcpp.exe on WinWord. It creates the header you need to work with Word as simply as if you were on VBA.
  2. 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.

huangapple
  • 本文由 发表于 2023年7月3日 13:04:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601953.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定