Add quick part by Aspose

Hello,

I have a document with predefined custom Quick Parts (block of text created in Word template .dotx).
Is it possible to add the quick part to Word file to the concrete place of document with DocumentBuilder or during mail merge?

Best regards,
Evgeniy

@konfetov,

Unfortunately, your question isn’t clear enough therefore we request you to please elaborate your inquiry further by mentioning the complete details of your use-case. This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly. Please also ZIP and upload your sample Word document here for our reference. We will investigate the scenario on our end and provide you more information.

Hi Awais,

quick-parts.zip (89.6 KB)
Here is

  1. Word template Test-template.dotx which has a quick part in the gallery.
  2. Word file Test-document.docx which is the template file saved as DOCX and some content added.
  3. Png file “word screenshot.png” which shown where I need to insert the quick part “Test-username” from the Quick Part Gallery of this document.

Best regards, Evgeniy

@konfetov,

I believe, the following draft code will help you in achieving what you are looking for:

Document dot = new Document(MyDir + @"Test-template.dotx");
Document doc = new Document(MyDir + @Test-document.docx");

foreach (BuildingBlock bb in dot.GlossaryDocument.BuildingBlocks)
{
    if (bb.Name.Equals("Username: John"))
    {
        // You can insert content of this Section at any place as per your requirement
        Section section = (Section)doc.ImportNode(bb.FirstSection, true);
        doc.InsertBefore(section, doc.FirstSection);
    }
}

doc.Save(MyDir + @"17.11.docx");

Awais,
thanks a lot, this works.

Best regards,
Evgeniy