We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to retrieve parts true- false and result text from IF fields

Hi,

Can you give me some idea about how get this, even with nested IF fields?

The document has already been combined.

Thank you.

Hi

Thanks for your request. May I ask you, why do you need to get this data from IF field? Maybe in your case it is enough just call UpdateFields() to evaluate IF field.

Best regards,

It’s a bit complex. I try to explain as best I can:

We want to insert a previusly combined document into another, using the function InsertDocument which is in AsposeWords Help. But the text of some combined fields in the document to insert, have got double quotes, and they are inside IF fields.

In the original document Aspose.Words resolves correctly IF fields, but this not happens once the document has been inserted. The tests that I’ve done tells me that the problem is the double quotes.

We had thought to search the text of parts true, false and result from IF fields and replace the double quotes with a text mark. Once the document has been inserted, we will replace the text mark with double quotes.

What do you think about this? Any other ideas?

Thank you.

Hi

Thank you for additional information. Could you please attach your document here and provide me sample code, which will allow me to reproduce the problem on my side?

Best regards,

You can try the two documents, DoubleQuotes1.doc and DoubleQuotes2.doc.

The first one is a simple document, and the second one, our case, has got a table and throws a Unexpected node type expection.

The code (the function InsertDocument is the same as in Aspose.Words Help):

Dim doc As Document
doc = New Document("DoubleQuotes1.doc")
doc.MailMerge.Execute(New String() {"FIELD1", "FIELD2"}, New String() {"1", "AAAAAAA""HELLO""BBBBBBBB"})
doc.Save("DocToInsert.doc")
doc = New Document("Template.doc")
InsertDocument(doc.Range.Bookmarks("INSERTDOCUMENT").BookmarkStart.ParentNode, New Document("DocToInsert.doc"))
doc.Range.Bookmarks("INSERTDOCUMENT").Remove()
doc.MailMerge.Execute(New String() {"FIELD1"}, New String() {"2"})
doc.Save("FinalDocument.doc")

Thak you.

Hi

Thank you for additional information. True text and False text in IF fields cannot contain double quotes. Double quotes in if fields are using to mark start and end of expressions
http://office.microsoft.com/en-us/word/HP051876761033.aspx

If you, for example, have double quotes inside true text, text after the second double quote will be truncated. For example:

“AAAAA”BBBBB”CCCC”

In this case, you are expecting to see all the text, but you will see only text between the first and second double quote.

Since, you are inserting true and false text using mail merge approach, you can just replace double quotes in field values. For example you can try suing MergeField event handler to achieve this:

Document doc = new Document(@"Test001\DoubleQuotes1.doc");
doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField);
doc.MailMerge.Execute(new string[] {"FIELD1", "FIELD2"}, new string[] {"1", "AAAAAAA\"HELLO\"BBBBBBBB"});
doc.Save(@"Test001\DocToInsert.doc");

void MailMerge_MergeField(object sender, MergeFieldEventArgs e)
{
    if (e.FieldValue.ToString().Contains("\""))
        e.Text = e.FieldValue.ToString().Replace('"', '\'');
}

Hope this helps.

Best regards.