Example: Formatting values
Docentric Toolkit Help
In this report, we want to write out some data of one particular order e.g. shipping address, shipping fee, date of the order etc. Order date and shipping fee should be formatted as a short date and a currency, accordingly. Data model used for all examples is exposed here.
Initially, we are creating a report template. Follow the common preparation steps to start building the template from scratch:
- Open a new blank Word document and enable it for templating
- Turn on Data Sources and Elements Explorers
- Define default data source as the Order class
After that, you should be at the following point:
Add proper Docentric Field elements (about inserting Field elements you can read here) to the template that are bound among other things, to the Orders's properties OrderDate and ShippingFee:
Next, save the template and generate the report. Report generation takes place programmatically, from your application that is using (has a reference to) the Docentric Report Engine dll. This code looks like following:
// Getting specific order
Order orderDataSource = DataAccess.GetOrderById(7);
// Instancing report engine, by assigning the data source
DocumentGenerator dg = new DocumentGenerator(orderDataSource);
// Generating report by specifying the report template and the resulting report (as file paths)
It is also possible to invoke the method GenerateDocument with same parameters typed as System.IO.Stream.
Generated report looks like:
You can notice that the Order date and Shipping fee are not in desired format. In order to change this, set the property Format String of the Field elements bound to OrderDate and ShippingFee properties of the class Order to suitable values, like shown at the picture below:
You can click on the button next to the Format String control that pops up the assistant form with available format strings for chosen category of data types:
Or you can type in the Format String control directly valid .NET format string:
Notice (on the picture above) that in the Element Tree sub pane of the Elements Explorer, all formatted elements have letter "F" assigned.