开发者

Adding a new page in MS Word using Qt

I am using Qt 4.5 and using ActiveQt to generate MS Word documents. I am able to create a document based on the ActiveX commands of VBA for MS Word. But I am not able to create a new page at the desired position.

I tried

selection->dynamicCall("InsertBreak(const QString &)","wdPageBreak");
selection->dynamicCall("InsertParagraph(void)");
QAxObject *partTableParagraph = activeDocument->querySubObject("Pa开发者_Python百科ragraphs(1)");
partTableParagraph->setProperty("PageBreakBefore","True");
QAxObject *partTableRange = partTableParagraph->querySubObject("Range");
selection->dynamicCall("TypeText(const QString&)","second page contents");

but still I am not able to create a new page in the word document. Also the contents aren't visible for the second page. i.e second page contents isn't visible.

Any pointers regarding this are welcome.


I recommend you write this as a VBA macro first. Once you have got it working in VBA, you should be able to translate it straight to ActiveQt.


Try this code. I'm able to insert a new page wherever I call this method:

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 );
}

For example, supposing you have a write method to write to your document:

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");

You'll end with This is a test. With no newline but with a page break in one page and But this has a newline at the beginning and the end in the other.

I'm not checking for NULL pointers, though :)

As for why your second page is blank... I use this to write to Word:

QAxObject* selection = activeWindow->querySubObject( "Selection" );
selection->dynamicCall( "InsertAfter(const QString&)",text);

and up until now it has worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜