SamplePage
(Added extra details on page)
(added more information)
Line 36: Line 36:
[[Documentation:SysSingleton GetSystemUrl|Check here]] on how to have a dynamic url for when your deploy your application onto the Mdriven Server.
[[Documentation:SysSingleton GetSystemUrl|Check here]] on how to have a dynamic url for when your deploy your application onto the Mdriven Server.


Create a ViewModel with the Name OpenDocumentReportTemplate
Create a ViewModel with the Name OpenDocumentReportTemplate. This ViewModel will be used a template for the Model-Driven data to generate reports


Within the ViewModel context menu, click Add column > Add columns needed for Report or create columns TemplateUrl and ReportFileName within the viewmodel.
Within the ViewModel context menu, click Add column > Add columns needed for Report or create columns TemplateUrl and ReportFileName within the viewmodel.
Line 48: Line 48:
in the ReportFileName column expression enter a file name for the new OpenDocument that will be generated in the format '<FileName>.odt' where <FileName> is the name of your file.
in the ReportFileName column expression enter a file name for the new OpenDocument that will be generated in the format '<FileName>.odt' where <FileName> is the name of your file.


create a class action within the
create a class action within the ViewModel whose data your want to print out using the expression below;
self.opendocumentreportshow(<classname>.ViewModels.OpenDocumentReportTemplate)
where <classname> is the root class of the viewmodel.


Create a Word template:
within OpenDocumentReportTemplate add columns whose data you want to print out.


[[File:Reporting.png|frameless|408x408px|link=https://learn.mdriven.net/File:Reporting.png]]
Trigger print out using the created class action and first print out will return all tags available for printing out data. Use these tags to format structure your report document.


You can have grids in grids to create structure:
If you dont want to use the %meta% tag to print out the available tags first. You may use the column names directly with the same expression. %<ColumnName>%.


[[File:Reporting 1.png|frameless|424x424px|link=https://learn.mdriven.net/File:Reporting_1.png]]


Save this as an open document file (odt). Save it to a place where you can access it from a URL (maybe you use SharePoint, or just stick it on some website).
To print out nested columns in a table format.


Now you need data. Declare a ViewModel in Modlr:
Create table add the expression
{| class="wikitable"
|+
|%%+<Nested ViewModel Column Name>%%<First Column Name>%
|%<Column Name>%
|%<Column Name>%
|}
[[File:OpenDocumentTemplateViewModel.png|alt=ViewModel Template for Printing out Model-Driven data to OpenDocument reports|none|thumb|752x752px|ViewModel Template]]
[[File:OpenDocumentTemplateForWord.png|alt=Office Text Document for Printing out model-driven data using OpenDocument format|none|thumb|739x739px|Text Template File]]


[[File:Reporting 2.png|frameless|411x411px|link=https://learn.mdriven.net/File:Reporting_2.png]]


(By now, you know that a ViewModel transforms your model for a specific need – in this case, the OpenDocument Report.)
The table format is for both text documents and spreadsheet documents.


[[File:Reporting 3.png|frameless|384x384px|link=https://learn.mdriven.net/File:Reporting_3.png]]
When using Microsoft Office Word, [https://support.microsoft.com/en-us/office/differences-between-the-opendocument-text-odt-format-and-the-word-docx-format-d9d51a92-56d1-4794-8b68-5efb57aebfdc Check here] for format styling that is supported in OpenDocument format.
 
Create a Word template:
Create two extra ViewModelColumns in your ViewModel - <code>TemplateUrl</code> and <code>ReportFileName</code>:
 
[[File:Reporting 4.png|frameless|444x444px|link=https://learn.mdriven.net/File:Reporting_4.png]]
 
Make the TemplateUrl column return the URL to where your template from above can be found – maybe in some SharePoint instances, as in this example.
 
Make the ReportFileName column return what the file should be called when produced.
 
And you are done.
 
Execute the report by using the new EAL operator:
 
<code>vSomePumpRev.opendocumentreportshow(‘PumpRevDeepReport’)</code> – this will call the OnOpenDocument event on the new IOpenDocumentService. This happens when each UI platform has its own way of showing things to a user.
namespace Eco.Services
  {
  // Summary:
  //    OpenDocumentService , ViewModel needs root level column describing url to
  //    template. Column must be namned "TemplateUrl" and be a valid url to a open
  //    document template
  public interface IOpenDocumentService
  {
    event EventHandler<OpenDocumentArgs> OnOpenDocument;
    byte[] AsByteArray(IObject vmroot, string viewModelName, out string reportname);
    void ExecuteOnOpenDocument(IObject vmroot, string viewModelName, byte[] openDocumentData, string reportname);
  }
  }
In WECPOF for WPF, we do this:
      File.WriteAllBytes(suggestedfilename, openDocumentData);
        System.Diagnostics.ProcessStartInfo sInfo = new System.Diagnostics.ProcessStartInfo(suggestedfilename);
        System.Diagnostics.Process.Start(sInfo);
In ASP.NET, you would do something else.
 
If you do not want to open the file – generate the data within – then use the new EAL operator <code>vSomePumpRev.opendocumentreportasblob(‘PumpRevDeepReport’)</code>
===A Brief Recap (A Bit Hasty and Vague)===
So you might think I just skimmed over stuff – like: '''how do you''' '''get a hold of the placeholder tags that are replaced with data?'''


Do this by entering the tag <code>%meta%</code> in your template. We will always look for this tag – and when found, we will add all valid tags in their places.
How do you '''create a hierarchical structure in the report?''' Find it like this in the data:
[[File:Reporting 5.png|frameless|387x387px|link=https://learn.mdriven.net/File:Reporting_5.png]]
And like this in the template:
[[File:Reporting 6.png|frameless|378x378px|link=https://learn.mdriven.net/File:Reporting_6.png]]
The tag <code>%%+Name%</code> acts as a row builder. The following tag <code>%OtherName%</code> is the data in the child. In the Example: <code>%%+ComponentSpecificationRevs%</code> – I stick this as the first thing in a table row and the row will be duplicated for each child. Then the <code>%RevisionNumber%</code> is filled in in the cell.
The reporting mechanism also works for Excel. An example of an Excel result report:
[[File:Reporting 7.png|frameless|339x339px|link=https://learn.mdriven.net/File:Reporting_7.png]]
===Update 2014-03-06. Qualifications===
When working with reports, we sometimes do not know in design time what needs the report will have at runtime. To handle this situation, the template tagging has been extended to allow for qualifications. Let me explain. The smallest possible report sample:
[[File:Reporting 8.png|frameless|254x254px|link=https://learn.mdriven.net/File:Reporting_8.png]]
[[File:Reporting 9.png|frameless|264x264px|link=https://learn.mdriven.net/File:Reporting_9.png]]
[[File:Reporting 10.png|frameless|376x376px|link=https://learn.mdriven.net/File:Reporting_10.png]]
We want to allow for picking the correct Class2 in runtime time while working on the template.
If we have this Excel template:
[[File:Reporting 11.png|frameless|279x279px|link=https://learn.mdriven.net/File:Reporting_11.png]]
We get this data out:
[[File:Reporting 12.png|frameless|268x268px|link=https://learn.mdriven.net/File:Reporting_12.png]]
The qualification extension is that we can now have Template tags like this:
  %Class2[Name=Hello1]Name%
  %Class2[Name=Hello1]Name%
What this means is that we are navigating to ViewModel column Class2 – but this is a list – and filter the result on the ViewModel column Name of ViewModelClass Class2. Taking the one with value “Hello1” – for that Class2 we use the Name column… Example:
What this means is that we are navigating to ViewModel column Class2 – but this is a list – and filter the result on the ViewModel column Name of ViewModelClass Class2. Taking the one with value “Hello1” – for that Class2 we use the Name column… Example:


[[File:Reporting 13.png|frameless|410x410px|link=https://learn.mdriven.net/File:Reporting_13.png]]
will give you:
[[File:Reporting 14.png|frameless|410x410px|link=https://learn.mdriven.net/File:Reporting_14.png]]
(Notice that we have different external ids in the two last columns – the first from a Class2 with <code>Name==Hello1</code>, the other from one with <code>Name==Hello2</code>)
This is useful when you have data in name-value pair patterns.
===Update 2014-04-04 -- Images in Word reports===
This is how you can do it.
Add some placeholder images in the template:
[[File:Reporting 15.png|frameless|375x375px|link=https://learn.mdriven.net/File:Reporting_15.png]]
On the Image “Format Picture” – Alt Text property – enter the Tag that holds the image blob in your ViewModel:
[[File:Reporting 16.png|frameless|404x404px|link=https://learn.mdriven.net/File:Reporting_16.png]]
Later, in Office(Word), it will look like this:[[File:2022-05-27 17h19 23.png|none|thumb|424x424px|link=https://learn.mdriven.net/File:2022-05-27_17h19_23.png]]Now, the image will be replaced with your data. Also, new today is the fact that the Aspect ratio of your data is kept in the final Word (odt) report:


[[File:Reporting 17.png|frameless|420x420px|link=https://learn.mdriven.net/File:Reporting_17.png]]
[[File:Reporting 17.png|frameless|420x420px]]


The MDriven Book - See: [[/learn.mdriven.net/Training:Prototyping|Prototyping]]
The MDriven Book - See: [[/learn.mdriven.net/Training:Prototyping|Prototyping]]

Revision as of 14:05, 3 June 2024

Generate Reports Using OpenDocument and Microsoft Office

OpenDocument format is an open file format standard for office applications compatible with Microsoft office and open source applications like LibreOffice and OpenOffice.

Common filename extensions used of OpenDocument documents are:

  • .odt for text documents
  • .ods for spreadsheet documents

Mdriven applications allow generating reports from model-driven data using OpenDocument format.

Text Document

Start by creating an OpenDocument text document using any office application that supports OpenDocument format.

Add %meta% tag within the document as this will be used to print out all the available tags within our ViewModel for printing out Model data.

Note: Make sure to write tags without spaces between the word(meta) and the percentage(%) signs.

Saving Strategies

Temporary Location

create a folder named temp in your C:/ directory and save your file in the directory as mytemplate.odt.

Your url path will now be 'c:\\temp\\mytemplate.odt'

Permanent Location (AssetsTK Strategy)

This strategy allows your template document to be uploaded with your model onto the server running your Turnkey application during deployment.

Go to the location where your .modlr file is saved

Create a folder with the name in the format of <YouModelFileName>_AssetsTK where <YouModelFileName> is the name of your .modlr file name.

Within the folder create another folder named content where your save your template document.

Your url path will now be 'http://localhost:8182/content/mytemplate.odt'

Check here on how to have a dynamic url for when your deploy your application onto the Mdriven Server.

Create a ViewModel with the Name OpenDocumentReportTemplate. This ViewModel will be used a template for the Model-Driven data to generate reports

Within the ViewModel context menu, click Add column > Add columns needed for Report or create columns TemplateUrl and ReportFileName within the viewmodel.

Select the view model to view the settings on the right.

Uncheck Use placing hints section at the top.

In the TemplateUrl column expression, enter the url path created earlier using any of the saving strategies above.

in the ReportFileName column expression enter a file name for the new OpenDocument that will be generated in the format '<FileName>.odt' where <FileName> is the name of your file.

create a class action within the ViewModel whose data your want to print out using the expression below;

self.opendocumentreportshow(<classname>.ViewModels.OpenDocumentReportTemplate)

where <classname> is the root class of the viewmodel.

within OpenDocumentReportTemplate add columns whose data you want to print out.

Trigger print out using the created class action and first print out will return all tags available for printing out data. Use these tags to format structure your report document.

If you dont want to use the %meta% tag to print out the available tags first. You may use the column names directly with the same expression. %<ColumnName>%.


To print out nested columns in a table format.

Create table add the expression

%%+<Nested ViewModel Column Name>%%<First Column Name>% %<Column Name>% %<Column Name>%
ViewModel Template for Printing out Model-Driven data to OpenDocument reports
ViewModel Template
Office Text Document for Printing out model-driven data using OpenDocument format
Text Template File


The table format is for both text documents and spreadsheet documents.
When using Microsoft Office Word, Check here for format styling that is supported in OpenDocument format.

Create a Word template:

%Class2[Name=Hello1]Name%

What this means is that we are navigating to ViewModel column Class2 – but this is a list – and filter the result on the ViewModel column Name of ViewModelClass Class2. Taking the one with value “Hello1” – for that Class2 we use the Name column… Example:


Reporting 17.png

The MDriven Book - See: Prototyping

This page was edited 81 days ago on 07/01/2024. What links here