Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Apr 05, 2016 7:30 am

Hello everyone

Is it possible to insert AutoTexts with Spire.doc? I could not find any references in the documentation.

Thanks and best regards

BEKB
 
Posts: 11
Joined: Wed Dec 16, 2015 2:36 pm

Tue Apr 05, 2016 8:38 am

Hi,

Thanks for your posting.
Our Spire.Doc supports to add AutoTextField but we don't have the default library in MS Word(see the below picture). You need to create your library and give field.Code value you want to add (for example, Arrow1).
001.png

Code: Select all
 Paragraph paragraph = section.AddParagraph();
            Field field = paragraph.AppendField("Test1", FieldType.FieldAutoText);
           field.Code = " AUTOTEXT  \" Arrow1 \"  \\* MERGEFORMAT ";


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Apr 05, 2016 12:48 pm

Hey

Thanks, this works. I have one more issue in doing this.
If i load a document (.dotx) via LoadFromFile, insert a field as descriped above, save the document (.docx) via SaveToFile the field has no more reference to the AutoText and if refresh the field, there is an error.
Is there a way I can insert the field and convert it to "normal" content, i don't need any more functions from the field, i only need the content in the AutoText.

Thanks!

BEKB
 
Posts: 11
Joined: Wed Dec 16, 2015 2:36 pm

Wed Apr 06, 2016 2:43 am

Hi,

Thanks for your further posting.
Please first ensure your document's library includes the field you want to add.
For example, my library has a autotext field named Spike(see below).
002.png

003.PNG

When I use the following code to add Spike AutoText field, the content corresponds to the field is showed in output .dotx file.
Code: Select all
    Document document = new Document();
           Section section = document.AddSection();
           Paragraph paragraph = section.AddParagraph();
           Field field = paragraph.AppendField("Spike", FieldType.FieldAutoText);
          document.SaveToFile("1.dotx",FileFormat.Dotx2010);

Result:
result.PNG


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Apr 06, 2016 2:10 pm

Hi and thanks for your response.

I think I know where the problem in my case is.
The AutoText is not in my normal.dotx library. It is in the Library of the dotx Template i load. After i save the new created document to a docx the reference to the AutoText is lost.
The Method Document.LoadFromFile does not load the AutoTexts saved in the loaded dotx.

This is my code: (sorry, vb.net, but i think you can manage that ;) )
Code: Select all
Dim objDocument As New Document()
objDocument.LoadFromFile("AutoTextExtension\Dokumente\Can_Add_AutoTextField_To_Paragrapgh.dotx")

 Dim objAutoTextExtension As New AutoTextExtension()
 Dim paragraph As Paragraph = objDocument.Sections(0).AddParagraph()
 paragraph.AppendField("TEST", Spire.Doc.FieldType.FieldAutoText)

 objDocument.SaveToFile("AutoTextExtension\Dokumente\Can_Add_AutoTextField_To_Paragrapgh_Run.docx")

 Assert.AreEqual("TEST 123", paragraph.Text)


Is there any way to handle this issue?

BEKB
 
Posts: 11
Joined: Wed Dec 16, 2015 2:36 pm

Thu Apr 07, 2016 1:18 am

Hi,

Thanks for your feedback.
To help us investigate your issue, please share your template dotx file. Thank you.
You can also send it to amy.zhao@e-iceblue.com.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Apr 18, 2016 7:25 am

Hi,

I have received your document via e-mail. Thanks for your providing.
I have reproduced your issue and forwarded it to our dev team. We will inform you when it is resolved.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc