我正在使用Qt4.5和ActiveQt生成MS Word文档。我能够创建一个基于微软Word的VBA的ActiveX命令文档。但我无法在所需位置创建新页面。
我试过了
selection->dynamicCall("InsertBreak(const QString &)","wdPageBreak");
selection->dynamicCall("InsertParagraph(void)");
QAxObject *partTableParagraph = activeDocument->querySubObject("Paragraphs(1)");
partTableParagraph->setProperty("PageBreakBefore","True");
QAxObject *partTableRange = partTableParagraph->querySubObject("Range");
selection->dynamicCall("TypeText(const QString&)","second page contents");但我仍然无法在word文档中创建新页面。第二页的内容也是不可见的。也就是说second page contents是不可见的。
欢迎任何关于这方面的指点。
发布于 2011-04-02 14:59:42
我建议你先把它写成VBA宏。一旦你让它在VBA中工作,你应该能够将它直接翻译成ActiveQt。
发布于 2014-12-11 18:41:26
试试这段代码。我可以在调用此方法的任何地方插入一个新页面:
void insertNewPage() {
QAxObject* activeWindow = activeDocument->querySubObject( "ActiveWindow" );
QAxObject* selection = activeWindow->querySubObject( "Selection" );
selection->dynamicCall( "Collapse(int)", 0 );
selection->dynamicCall( "InsertNewPage()" );
selection->dynamicCall( "Collapse(int)", 0 );
}例如,假设您有一个要写入文档的write方法:
write( "This is a test. " );
write("With no newline but with a page break");
writePageBreak();
write("But this has a newline at the beginning and the end\n");您将以一个页面中的This is a test. With no newline but with a page break和另一个页面中的But this has a newline at the beginning and the end结束。
不过,我并没有检查NULL指针:)
至于为什么你的第二页是空白的.我使用下面的代码来写Word:
QAxObject* selection = activeWindow->querySubObject( "Selection" );
selection->dynamicCall( "InsertAfter(const QString&)",text);到目前为止,它已经奏效了。
https://stackoverflow.com/questions/3229043
复制相似问题