How to make the hyperlink dynamically in Word, using LINQ Reporting Engine

for example,
If it is hard code url, it is working fine

Text to display: “Google Home Page”
Address: "https://www.google.com/"

However,
if I change the Address to
<<[GoogleUrl]>>
it will NOT work

@zhenyu.wang

Cause

When using the LINQ Reporting Engine in Aspose.Words, dynamic placeholders like <<[GoogleUrl]>> may not resolve correctly to create hyperlinks. This issue typically arises if the data source isn’t properly configured or if the syntax isn’t correctly interpreted by the engine.

Solution

To ensure that dynamic URLs work correctly, you need to verify that the data source is correctly set up and that the placeholder is properly formatted. Here’s how to do it:

  1. Data Source: Confirm that your data source contains the GoogleUrl field with the correct URL value.
  2. Hyperlink Syntax: Use the correct syntax for creating hyperlinks in your template. The format should be:
    { HYPERLINK <<[GoogleUrl]>> "Google Home Page" }
    

Code

Here’s a sample code snippet to demonstrate how to set up the data source and generate the document:

// Create a new document
Document doc = new Document("template.docx");

// Create a data source
var dataSource = new[]
{
    new { GoogleUrl = "https://www.google.com/" }
};

// Execute the reporting engine
var engine = new ReportingEngine();
engine.BuildReport(doc, dataSource, "dataSource");

// Save the document
doc.Save("output.docx");

Next Steps

  1. Verify that the GoogleUrl field is present in your data source.
  2. Ensure that the template document has the correct hyperlink syntax.
  3. Test the output document to confirm that the hyperlink is generated correctly.

If you follow these steps and ensure everything is set up properly, the hyperlink should work as expected. Please let me know if you need further assistance!

@zhenyu.wang Please see our documentation to learn how to insert hyperlinks dynamically:
https://docs.aspose.com/words/net/inserting-hyperlinks-dynamically/

You can use the following syntax:

<<link [uri_or_bookmark_expression] [display_text_expression]>>

After filling the template with data using the following code:

Document doc = new Document(@"C:\Temp\in.docx");

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, new string[] { "https://www.google.com/", "Link To Google" }, new string[] { "uri_or_bookmark_expression", "display_text_expression" });

doc.Save(@"C:\Temp\out.docx");

in.docx (13.8 KB)
The output will look like this: out.docx (11.2 KB)

1 Like

Thank you.
It is working

1 Like