Setting a merge code into a variable

Hi
We use Aspose.Words to merge data into variables such as Variable.Text1
We are now trying to set Aspose variables with the values of our variables. ie.,
Say Variable.Text1 == Comments
We then want to set the Aspose variable S to equal Comments by using this code
<<var [s = “Variable.Text1”]>>
s = <<[s]>>

The problem we are having is that our Variable.Text1 is not merging the value and hence we are getting;
s = Variable.Text1
instead of
s = Comments

Can anyone help with this ?

@stephenbp

We are working over your query and will get back to you soon.

@stephenbp

We suggest you please read the following article.
Using Variables

Please use the following template syntax. We have attached the input and output documents with this post for your kind reference. Docs.zip (20.1 KB)

<<var [s =sender.Name]>><<[s]>>

Please check the following code example that uses the above template syntax.

Document doc = new Document(MyDir + "input.docx");
ReportingEngine engine = new ReportingEngine();
                
Sender sender = new Sender { Name = "LINQ Reporting Engine", Message = "Hello World" };
engine.BuildReport(doc, sender, "sender"); 
                    
doc.Save(MyDir + "19.6.docx");

public class Sender
{
    public String Name { get; set; }
    public String Message { get; set; }
    public String Hyperlink { get; set; }
}

Thanks Tahir. That code is the code we first tried…ie., our variable = Variable.doc
And we have this code in our document
<<var [s=Variable.Text1]>>
s = <<[s]>>
But we get this output in our document
s == Variable.Text1

Based on this you can see that the Variable.Text1 is NOT merging in its own value

@stephenbp

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi Tahir, we have managed to get this working now ONLY when we set the variable as a number. If we set the variable as text we get errors. Can I ask a couple of more questions…

How can we use an <> statement to check if a variable is Null or not… I am trying

<<if [s != “”]>>
Correct
<>
Incorrect
<>

But we are getting an error on the !=

So how can we check if the variable is NULL or not.
Thanks

@stephenbp

The code example shared in my previous post works for text variable.

Please read the following article.
Using Lexical Tokens