OpenDocument
(Adding page to Category:TOC because it contains a TOC.)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==== Viewmodel additions ====
==== Background ====
You can create reports using Open Document documents as templates.
You can create reports using OpenDocument documents as templates. This functionality takes an OpenDocument document, processes it, adds data from a ViewModel, and outputs the resulting document file.


The templates is can be accessed in several different ways;
==== Ways to Retrieve the Template  ====
* From an URL
The templates can be accessed in several different ways:
* From the local filesystem
# From the database in BLOB attribute in a modeled class
* From the database in BLOB attribute in a modeled class
# From a URL (for example, a document server)
The viewmodel providing the report data also has attributes with specific names providing information to the report functionality.
# From the local filesystem
The ViewModel providing the report data also has attributes with specific names providing information to the reporting functionality.
{| class="wikitable"
{| class="wikitable"
|'''Attribute name'''
|'''Attribute name'''
Line 22: Line 23:
|TemplateIsHtml
|TemplateIsHtml
|True or False signaling how the template should be handled
|True or False signaling how the template should be handled
|Boolean, True or False
|Boolean, True, or False
|-
|-
|ReportFileName  
|ReportFileName  
Line 33: Line 34:
|}
|}


====OpenDocument Text - ODT====
==== Methods ====
Tips when editing "open document text" odt files in MS Word
Depending on your input format, you can use either of these two functions:
=====opendocumentreportasblob=====
Takes an array of bytes as input and output.
ResultAsBlob := self.opendocumentreportasblob(ReportRoot.ViewModels.ReportingViewmodel)
=====opendocumentreportshow=====
Does the same as ''opendocumentreportasblob'' above, but opens the resulting HTML in the browser.
self.opendocumentreportshow(ReportRoot.ViewModels.ReportingViewmodel)


Any font changes (even if not visible) will interfere MDrivens detection of what to replace in your document. If you encounter this, copy the text (including %) and paste as "plain text" replacing the previous text.
==== Document Formats  ====


Line break will will interfere MDrivens detection of what to replace in your document. Use Words text section settings and select "no line breaks" to avoid these problems.
=====OpenDocument Text - ODT=====
====OpenDocument sheets - ODS====
Tips when editing "open document text" odt files in MS Word:
OpenDocument excels - ODS document has issues to use data as numbers if we do not explicitly say that it is a number.
* Any font changes (even if invisible) will interfere with MDriven's detection of what to replace in your document. If you encounter this, copy the text (including %) and paste it as "plain text", replacing the previous text.
* Line breaks will interfere with MDriven's detection of what to replace in your document. Use Word's text section settings and select "no line breaks" to avoid these problems.


The problem is that our data-tags like %Something% that corresponds to ViewModelColumns are interpreted as text by excel - so our template will always believe that all cells fill with data is text.
=====OpenDocument sheets - ODS=====
OpenDocument Excels - ODS document has issues with using data as numbers if you do not explicitly say that it is a number.


To help you avoid this we have introduced this naming conversion :
The problem is that our data tags like <code>%Something%</code> that corresponds to ViewModelColumns are interpreted as text by Excel - so our template will always believe that every cell filled with data is text.
 
To help you avoid this, we have introduced this naming conversion:
{| class="wikitable"
{| class="wikitable"
!ViewModelColumn name ending with
!ViewModelColumn name ending with
Line 60: Line 71:
|end with a % and data before % must pass decimal.TryParse
|end with a % and data before % must pass decimal.TryParse
|
|
|}Use these naming suffixes in ViewModels that constitute reports for excel in order to get excel to understand that the value in an excel cell should be interpreted as a float or percentage - default will be interpreted as string.
|}Use these naming suffixes in ViewModels that constitute reports for Excel in order to get Excel to understand that the value in an Excel cell should be interpreted as a float or percentage - default will be interpreted as String.


==== '''Note!''' ====
===== HTML and XML Documents  =====
When creating OpenDocument documents, consider using the tag '''%meta%''' in your document to get the exact tag list for your document.
You can also use HTML templates. If the template used ends with .htm or .html, the logic expects a well-formed HTML document.


Copy the tag name including the percent signs from the generated meta tag information (preferable without style).  
See [[HtmlReport]] for more information.


If you type it or edit a part of the tag name, your editor can insert invisible control information that's interfere with the merging.
==== Information About Available Tags (Meta Data) ====
When creating OpenDocument documents, consider using the tag '''%meta%''' in your document to get the exact tag list for your document.


2020-04-06: Please also note that we have seen some issues with corrupt downloads when the ods template is created in OpenOffice 4.1.X. If the template is created in Excel is the document downloaded properly.
Copy the tag name including the percent signs from the generated meta tag information (preferably without style). The %meta% must be the first string in the element in order to be recognized - it is also case-sensitive.  


==== HTML documents ====
If you type or edit a part of the tag name, your editor can insert invisible control information that doesn't interfere with the merging.
You can also use html templates. If the template used ends with .htm or .html the logic expects a well formed html document and will expand tags just as in OpenDocument formats - but the we will check for row-builders %%+ROWBUILDERTAG& in <nowiki><tr></nowiki> context (html tables)


See [[Microsoft office and OpenDocument as a Report generator]] for an example.
==== Notes ====
''2020-04-06:'' Please also note that we have seen some issues with corrupt downloads when the ods template is created in OpenOffice 4.1.X. If the template is created in Excel, check that the document is downloaded properly.


==== XML documents ====
==== Examples ====
XML is just the more generic case of html. They are treated by the same logic. You can from 20190919 use any xml-tag as row builder. Example
See [[Training:Microsoft office and OpenDocument as a Report generator|Microsoft Office and OpenDocument as a Report generator]] for an example.
<pre>
[[Category:Reports]]
<SomeXml attrib='%SomeVMColumnAsAttributeresult%'>
{{Edited|July|12|2024}}
    %SomeOtherVMColumnAsXMLTextresult%
  <Items>
    <Item>%%+TheVMNestingColumn%
      <ContentInItem someattrib='%VMColInNesting%'>
          %StuffFromViewModelNesting%
      </ContentInItem>
    </Item>
  </Items>
</SomeXml>


</pre>
[[Category:TOC]]

Latest revision as of 14:13, 26 March 2024

Background

You can create reports using OpenDocument documents as templates. This functionality takes an OpenDocument document, processes it, adds data from a ViewModel, and outputs the resulting document file.

Ways to Retrieve the Template

The templates can be accessed in several different ways:

  1. From the database in BLOB attribute in a modeled class
  2. From a URL (for example, a document server)
  3. From the local filesystem

The ViewModel providing the report data also has attributes with specific names providing information to the reporting functionality.

Attribute name Attribute should evaluate to Value type and content
TemplateUrl The URL or local filename String with for example http://www.mdriven.net/templates/report.odt or for prototyping c:\\temp\\mytemplate.odt
TemplateBlob A class attribute containing the template Blob with an uploaded document template, value is expected to be Base64Encoded
TemplateIsHtml True or False signaling how the template should be handled Boolean, True, or False
ReportFileName Filename to be used when opening the generated document
ReportDirectoryName Directoryname that will be used if the document is saved before opening it This is passed along with the IOpenDocumentService and can be used by implementors to structure documents in zip files or output directories

Methods

Depending on your input format, you can use either of these two functions:

opendocumentreportasblob

Takes an array of bytes as input and output.

ResultAsBlob := self.opendocumentreportasblob(ReportRoot.ViewModels.ReportingViewmodel)
opendocumentreportshow

Does the same as opendocumentreportasblob above, but opens the resulting HTML in the browser.

self.opendocumentreportshow(ReportRoot.ViewModels.ReportingViewmodel)

Document Formats

OpenDocument Text - ODT

Tips when editing "open document text" odt files in MS Word:

  • Any font changes (even if invisible) will interfere with MDriven's detection of what to replace in your document. If you encounter this, copy the text (including %) and paste it as "plain text", replacing the previous text.
  • Line breaks will interfere with MDriven's detection of what to replace in your document. Use Word's text section settings and select "no line breaks" to avoid these problems.
OpenDocument sheets - ODS

OpenDocument Excels - ODS document has issues with using data as numbers if you do not explicitly say that it is a number.

The problem is that our data tags like %Something% that corresponds to ViewModelColumns are interpreted as text by Excel - so our template will always believe that every cell filled with data is text.

To help you avoid this, we have introduced this naming conversion:

ViewModelColumn name ending with Interpreted by report logic as Data must
float excel value-type float pass decimal.TryParse
percentage excel value-type percentage and excel value = sent in value /100 end with a % and data before % must pass decimal.TryParse

Use these naming suffixes in ViewModels that constitute reports for Excel in order to get Excel to understand that the value in an Excel cell should be interpreted as a float or percentage - default will be interpreted as String.

HTML and XML Documents

You can also use HTML templates. If the template used ends with .htm or .html, the logic expects a well-formed HTML document.

See HtmlReport for more information.

Information About Available Tags (Meta Data)

When creating OpenDocument documents, consider using the tag %meta% in your document to get the exact tag list for your document.

Copy the tag name including the percent signs from the generated meta tag information (preferably without style). The %meta% must be the first string in the element in order to be recognized - it is also case-sensitive.

If you type or edit a part of the tag name, your editor can insert invisible control information that doesn't interfere with the merging.

Notes

2020-04-06: Please also note that we have seen some issues with corrupt downloads when the ods template is created in OpenOffice 4.1.X. If the template is created in Excel, check that the document is downloaded properly.

Examples

See Microsoft Office and OpenDocument as a Report generator for an example.

This page was edited 46 days ago on 03/26/2024. What links here