How to use AUTOTEXT feature in aspose.words

Hi All,

I’m new to aspose and currently assigned to a project that need to use aspose to build newsalert in word template.

I’m not sure how to call or use the AUTOTEXT feature by using aspose.

Can anyone please help me?

Cheers,
Joanne

Hi

Thanks for your request. Please see the following link to learn about AutoText feature in Aspose.Words:
https://reference.aspose.com/words/net/aspose.words.buildingblocks/
Best regards,

Hi Andrey,

Thanks for ur reply.

Do u haf any sample?

Cheers,
Joanne

Hi again,

By reading the content in the link that you have given, I still having some doubts. That is, how do I get the glossary document from the template doc?

Because when I assign the template doc into the document, I actually get a null value from the Document.GlossaryDocument. I do understand when there is no GlossaryDocument in the Document, then it will returning a null value, however, I’m pretty sure there is a AutoText item in my template doc.

So… we’ll really appreciate if you can shred some light on this.

Thank you very much and hope to read from you soon.

Victor

Hi

Thanks for your inquiry. Here is simple code, which shows how you can use AutoText:

// Open template, which contains AutoText
Document doc = new Document(@"Test001\test.dotx");
// Get AutoText entry.
BuildingBlock block = doc.GlossaryDocument.BuildingBlocks[0];
// BuildingBlock has one or more sections, we can insert these section into our document.
// I just appended all section of AutoText entries.
// You can insert only content of these setions or part of content.
foreach(Section section in block.Sections)
    doc.AppendChild(doc.ImportNode(section, true));
// Save output document.
doc.Save(@"Test001\out.doc");

I also attached my template. The template contains only one AutoText entry named “MyAutoText”.
Hope this helps.
In addition, you can attach your template here for testing.
Best regards.

Hi Alexey,

Thanks for the sample code. However, I tried doc.GlossaryDocument yesterday, it just shows me null value. And sorry for not make things clear at the beginning, actually, we are using aspose.words.dll version 6.4. So… I believe dotx is not supported? Anyway, I’ve open your attached dotx file and compare with my template dot file in office 2007. To me, they all look the same.

So now, I got another doubt besides this AutoText. FYI, we already purchase the license for 6.4, is it applicable to the latest version of aspose.words dll? If yes, then I just download the latest version and try out.

Hi
Thank you for additional information. The latest version of Aspose.Words is 9.1.0. You can download this version here:
https://releases.aspose.com/words/net
Also note, that every Aspose license carries one-year subscription for free upgrades to new versions released during this time. So, you can check the expiration date of your license and upgrade to the newest version. To check an expiration date of your license open the license file using notepad. You will see the following tags:
20100218

It means that you can free upgrade to version of Aspose.Words published before 02/18/2010.
So could you please try using the latest version and let me know how it goes on your side:
Best regards,

Hi again,

Thank you for the assistance in showing me the code on how to inserting the auto text. However, I’m having another issue. i.e. Whenever I add in the auto text in the block, I find this inserted text is actually started in a new page. And what I’m trying to achieve is letting the text to be continued in the same page… Mind to shred some light on this?

Thanks,

Victor Wong

Hi Victor,
I believe your can use the SectionStart property of the Section.PageSetup object to control whether the section will appear continious or on a new page.
Thanks,

hi adam,

Actually i did tried with SectionStart property of the Section.PageSetup object to specity to appendchild at the continuous page but unfortunately this doesn’t help.

I suspect is this because I appendchild in a doc that I already save previously?

Hi

Thank you for additional information. Maybe in your case, you need to append only content of the Section’s body instead of appending whole section. In this case, there will not be section break.
Best regards,

Hi mate,

Thanks for the help, it works!!

hi, Alexey

i trying your code snippet for a test and use word2013’s default buildingblock template which is locate “%appdata%\Roaming\Microsoft\Document Building Blocks\2052\15\Built-In Building Blocks.dotx”

i has a question here:
after runing your code, the output docment has only a watermark, but the document file size bigger then 1MB, i don’t know the reason, than i opening file in zip and found a lot of pictures in “word\media” subfolder. these files didn’t render in anywhere, can you explain the reason?

i use 13.10

thanks.

hi, Alexey

another question here

i use below code to initialize a Document object

ADoc.Document docx = new ADoc.Document(someExistedDocumentFile);
docx.AttachedTemplate = template;

but after setting AttachedTemplate property, the document’s GlossaryDocument is null. unexpectedly, i can’t completely use your code snippet,your code make a empty document and than full fill to it, but i have thousands of file in system and should export file with high performance, can you have any idea for this?

thanks

Hi Pyntia,

Please accept my apologies for late response.

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.

  1. Please attach your input Word document.
  2. Please attach your template document.
  3. Please attach the output Word file that shows the undesired behavior.
  4. Please attach your target Word document showing the desired behavior. You can use Microsoft Word to create your target Word document. I will investigate as to how you are expecting your final document be generated like.

As soon as you get these pieces of information to us we’ll start our investigation into your issue.