2010-07-12 176 views
2

我正在使用Qt 4.5并使用ActiveQt生成MS Word文档。我能够基于MS Word的VBA的ActiveX命令创建文档。但我无法在所需位置创建新页面。使用Qt在MS Word中添加新页面

我试图

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不可见。

任何关于这个指针是值得欢迎的。

回答

0

我建议你先把它写成VBA宏。一旦你在VBA中使用它,你应该可以直接将它翻译成ActiveQt。

0

试试看看这个代码。我能够插入新的页面,无论我调用这个方法:

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

和到现在为止它已经工作。