Solved How to use dynamicall to insert 2 documents right next to each other
-
Lets say i have 2 documents: a.docx and b.docx
a.docx has "A" in it.
b.docx has "B" in it.
when i useQString outFile("E:/aaaaaest.docx"); QString a("E:/a.docx"); QString b("E:/b.docx"); QAxObject axObject("Word.Application"); QAxObject *documents = axObject.querySubObject("Documents"); QAxObject *document = documents->querySubObject("Open(const QString&, bool)", a, true); // open a.docx QAxObject *selection = axObject.querySubObject("Selection"); selection->dynamicCall("InsertFile(QString&)", b); // insert b.docx document->dynamicCall("SaveAs(const QString&)", outFile); document->dynamicCall("Close()"); axObject.dynamicCall("Quit()");
The out put file looks like this
A
B
Whereas i want it to look like this:
AB
What function should i use to get that ? Providing the content a.docx is less than 10 characters ( letters only ) , b.docx always starts with words. -
@Dante-Pham More than likely you are selecting a newline with
selection()
, check the size of your selection and cut off the newline.This is just a guess though it may just be how it is made to append, but I'm guessing there's a newline being a docx and all.
-
@ambershark said in How to use dynamicall to insert 2 documents right next to each other:
selecting a newline with
selection()
I created a new .docx file and type in A, same thing with the other one. Im not sure what you mean there.
check the size of your selection
How exactly do i check that ?
-
@Dante-Pham Do you want to create a document with two columns (one column from a and one from b)? Or how is it supposed to work (how would you do it manually in Word)?
Your question is not really related to Qt as you're using Microsoft Word API not Qt. -
I already said in the previous article.
Take a look again.like this:
selection->dynamicCall("EndKey(QVariant&)", 6); selection->dynamicCall("InsertFile(QString&)", b);
-
@Devopia53 Ok, im so sorry because my question wasn't clear enough
I tried your method and it worked. However, when try adding b repeatedly, only the first one would stick to a. Others just go down one line
I tried this:selection->dynamicCall("EndKey(QVarient&)", 6); selection->dynamicCall("InsertFile(QString&)", b); selection->dynamicCall("EndKey(QVarient&)", 6); selection->dynamicCall("InsertFile(QString&)", b); selection->dynamicCall("EndKey(QVarient&)", 6); selection->dynamicCall("InsertFile(QString&)", b);
and this
selection->dynamicCall("EndKey(QVarient&)", 6); selection->dynamicCall("InsertFile(QString&)", b); // insert b.docx selection->dynamicCall("EndKey(QVarient&)", 6); selection->dynamicCall("EndKey(QVarient&)", 6);
It gives the same result:
AB
B
BWould you mind explaining to me what exactly does
dynamicCall("EndKey(QVarient&)", 6);
do and what happens if i replace "6" with other numbers ? -
@Dante-Pham said in How to use dynamicall to insert 2 documents right next to each other:
Would you mind explaining to me what exactly does dynamicCall("EndKey(QVarient&)", 6); do and what happens if i replace "6" with other numbers ?
https://msdn.microsoft.com/en-us/library/office/ff195593.aspx
6 is equal to wdStory -
are you sure the probelem is not just a typo? QVarient should be QVariant
-
Because, the result is that all documents contain newlines.
If all the documents consist of a single line, try this:// repeatedly next step 3 lines selection->dynamicCall("GoTo(QVariant&, QVariant&)", 3, 1); // WdGoToItem::wdGoToLine=3, WdGoToDirection::wdGoToFirst=1 selection->dynamicCall("EndKey(QVariant&)", 5); // WdUnits::wdLine=5 selection->dynamicCall("InsertFile(QString&)", b); selection->dynamicCall("GoTo(QVariant&, QVariant&)", 3, 1); // WdGoToItem::wdGoToLine=3, WdGoToDirection::wdGoToFirst=1 selection->dynamicCall("EndKey(QVariant&)", 5); // WdUnits::wdLine=5 selection->dynamicCall("InsertFile(QString&)", b); selection->dynamicCall("GoTo(QVariant&, QVariant&)", 3, 1); // WdGoToItem::wdGoToLine=3, WdGoToDirection::wdGoToFirst=1 selection->dynamicCall("EndKey(QVariant&)", 5); // WdUnits::wdLine=5 selection->dynamicCall("InsertFile(QString&)", b);
For more information, check out Microsoft's site.
-
Thanks so much guys. It worked ^^