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
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
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:
GoogleUrl
field with the correct URL value.{ 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
GoogleUrl
field is present in your data source.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)
Thank you.
It is working