Hello World Example
Assume, that you have the Sender
class defined in your application as follows:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
public class Sender { | |
private String Name; | |
public final String getName() { | |
return Name; | |
} | |
public final void setName(String value) { | |
Name = value; | |
} | |
private String Message; | |
public final String getMessage() { | |
return Message; | |
} | |
public final void setMessage(String value) { | |
Message = value; | |
} | |
} |
To produce a report containing a message of a concrete sender on its behalf, you can use a template document with the following content.
<<[s.getName()]>> says: "<<[s.getMessage()]>>."
To build a report from the template, you can use the following source code.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(HelloWorld.class); | |
String fileName = "HelloWorld.doc"; | |
// Load the template document. | |
Document doc = new Document(dataDir + fileName); | |
// Create an instance of sender class to set it's properties. | |
Sender sender = new Sender(); | |
sender.setName("LINQ Reporting Engine"); | |
sender.setMessage("Hello World"); | |
// Create a Reporting Engine. | |
ReportingEngine engine = new ReportingEngine(); | |
// Execute the build report. | |
engine.buildReport(doc, sender, "sender"); | |
dataDir = dataDir + Utils.GetOutputFilePath(fileName); | |
// Save the finished document to disk. | |
doc.save(dataDir); |
After the source code is ran, the template document is populated with the data about the sender, and the document becomes a ready report with the following content.
LINQ Reporting Engine says: "Hello, World."
After the report document is built, you can save it or perform any other tasks on it using Aspose.Words API in your code.