In this article
The class Banana.Report.ReportElement represents the report itself and every element in the report, like sections, paragraphs, tables, texts and the report itself.
Once you create a new report through the method Banana.Report.newReport() you can start adding sections, paragraphs, texts, tables and so on.
When you add an element with one of the add methods, you get as return value an object of type
Elements as a container of other elements.
Banana.Report.ReportElement that represents the added element.
To this object you can add further elements and by this way construct the structure of the report.
Report
+ Paragraph
+ Table
+ Row
+ Cell
+ Cell
+ Row
+ Cell
+ Cell
...
Even if this interface enable you to add tables to text elements or columns to paragraphs, the result will be undefined.
Formatting like text size, text color, margins, and so on are set separately through a Banana.Report.ReportStyleSheet object.
Methods
addClass(classes)
Add classes to the node. A class binds the element to the corresponding class style definend in Banana.Report.ReportStyleSheet as used in CSS Stylesheets.
var report = Banana.Report.newReport("Report title"); report.addParagraph("1250.00").addClass("balanceStyle");
addSection([classes])
Add a section and return the created section as a Banana.Report.ReportElement object.
You can add sections only to sections, cells, captions, headers or footers.
var report = Banana.Report.newReport("Report title"); //Add a section with a style var section = report.addSection("sectionStyle"); section.addParagraph("First paragraph"); section.addParagraph("Second paragraph");
addParagraph([text, classes])
Add a paragraph and return the created paragraph as a Banana.Report.ReportElement object.
You can add paragraphs only to sections, cells, captions, headers or footers.
var report = Banana.Report.newReport("Report title"); //Add an empty paragraph report.addParagraph(" "); //Add a paragraph with a text report.addParagraph("Hello World !!!"); //Add a paragraph with a text and a style report.addParagraph("Hello World !!!", "styleHelloWorld");
addText(text [, classes])
Add a text node and return the create text as a Banana.Report.ReportElement object.
You can add texts only to sections, paragraphs, cells, captions, headers or footers.
var report = Banana.Report.newReport("Report title"); //Add a text report.addText("Hello world !!!"); //Add a text with a style report.addText("Hello world !!!", "styleHelloWorld");
addTable([classes])
Add a table and return the created table as a Banana.Report.ReportElement object.
You can add tables only to the report or sections.
var report = Banana.Report.newReport("Report title"); var myTable = report.addTable("myTable");
addColumn([classes])
Add a column and return the created column as a Banana.Report.ReportElement object.
You can add columns only to tables.
var column1 = myTable.addColumn("column1"); var column2 = myTable.addColumn("column2"); var column3 = myTable.addColumn("column3");
addRow([classes])
Add a row and return the created row as a Banana.Report.ReportElement object.
You can add rows only to tables, table headers or table footers.
var tableRow = myTable.addRow(); ...
addCell([span])
Add an empty cell and return the created cell as a Banana.Report.ReportElement object.
You can add cells only to rows. You can span cells over columns but not over rows.
tableRow.addCell(); //span empty cell over 1 column (default value) tableRow.addCell("", 3); //span empty cell over 3 columns ...
addCell(text [,classes, span])
Add a cell to the node and return the created cell as a Banana.Report.ReportElement object.
You can add cells only to rows.You can span cells over columns but not over rows.
tableRow.addCell("Bank", "firstCellStyle", 3); //span cell over 3 columns tableRow.addCell("1200.65", "secondCellStyle, 1); //span cell over 1 column ...
addLineBreak()
Add a line break and return the created line break as a Banana.Report.ReportElement object.
You can add line breaks only to paragraphs or cells.
// Add a line break to a paragraph var p = report.addParagraph(" "); p.addLineBreak(); // Add a line break to a cell var c = tableRow.addCell(); c.addLineBreak();
addPageBreak()
Add a page break node and return the created page beak as a Banana.Report.ReportElement object.
You can add page breaks only to the report or sections.
var report = Banana.Report.newReport("Report title"); ... report.addPageBreak(); ...
addImage(path [,classes])
Add an image and return the created image as a Banana.Report.ReportElement object. Supported formats are png and jpg.
The path can be relative to the script's folder, the document's folder, the name of a document attacched to the file or a data uri scheme (for images imbedded in the document).
- file:script/<relative_path_to_script_folder>/<image_name>
- file:document/<relative_path_to_file_folder>/<image_name>
- documents:<document_name>
- data:[<media type>][;charset=<character set>][;base64],<data>
You can add images only to sections, paragraphs, cells, captions, headers or footers.
The parameter path can be absolute or relative to the script path.
Since: Banana Accounting 8.0.5
var report = Banana.Report.newReport("Report title"); // Add an image located in the script folder report.addImage("file:script/logo_abc.jpg"); // Add an image located in the dcoument folder report.addImage("file:document/logo_mnp.jpg"); // Add an image saved in the table documents report.addImage("documents:logo_xyz.jpg"); // Add an image (a red dot) included in the document report.addImage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==");
addImage(path, widht, height [,classes])
Overloaded method to add an image and return the created image as a Banana.Report.ReportElement object.
The parameters widht and height have the same syntax as css lenhgt values. They can be absolute (ex.: "30px", "3cm", ... ) or relative (ex.: "50%", "3em", ...).
Since: Banana Accounting 8.0.5
var report = Banana.Report.newReport("Report title"); report.addImage("documents:image_logo", "3cm", "5cm");
addFieldPageNr([classes])
Add a field with containg the page number and return the created field as a Banana.Report.ReportElement object.
You can add this field only to sections, paragraphs, cells, captions, headers or footers.
var report = Banana.Report.newReport("Report title"); ... // Add the page number to the paragraph report.addParagraph("Page ").addFieldPageNr(); // Add a page number to the footer var footer = report.getFooter(); footer.addText("Page "); footer.addFieldPageNr();
getWatermark()
Return the watermak element.
Only the report has a watermak element.
var watermark = report.getWatermark(); watermark.addParagraph("Watermark text");
getHeader()
Return the header of the element.
Only tables and the report have an header element.
var report = Banana.Report.newReport("Report title"); //Report var reportHeader = report.getHeader(); reportHeader.addClass("header"); reportHeader.addText("Header text"); //Table var table = report.addTable("myTable"); var tableHeader = table.getHeader(); tableRow = tableHeader.addRow(); tableRow.addCell("Description"); tableRow.addCell("Amount");
getFooter()
Return the footer of the element.
Only tables and the report have a footer element.
//Report var footer = report.getFooter(); footer.addText("Footer text");
getCaption()
Return the caption of the element.
Only tables have a caption element.
var table = report.addTable("MyTable"); var caption = table.getCaption(); caption.addText("Table caption text", "captionStyle");
getTag()
Return the tag of the element, like 'body', 'p', 'table', 'td' and so on.
var report = Banana.Report.newReport("Report title"); ... report.getTag(); // returns 'body' footer.getTag(); // returns 'pfoot' ...
getTitle()
Return the title of the element.
Only a document element have a title.
var report = Banana.Report.newReport("My Report Title"); var title = report.getTitle(); // return 'My Report Title'
Since: Banana Accounting 8.0.5
setOutline(level)
Set the outline level, this is used to create the index when exporting to pdf.
report.addParagraph("1. Text").setOutline(1);
setBookmark(bookmark)
Set a bookmark (or anchor), this is used in conjunction with setLink().
report.addParagraph("Bookmark on page 2").setBookmark("bookmarkpage2");
setLink(bookmark)
Set a link to a bookmark. See setBookmark().
report.addParagraph("-> link to bookmark on page 2").setLink("bookmarkpage2");
setPageBreakBefore()
Set to insert a page break before the element.
// Insert a page break before a paragraph report.addParagraph("Hello world!!!").setPageBreakBefore(); // Insert a page break before a table /* first create a table then... */ myTable.setPageBreakBefore();
setSize(width, height)
Set the size of the element.
The parameters widht and height have the same syntax as css lenhgt values. They can be absolute (ex.: "30px", "3cm", ... ) or relative (ex.: "50%", "3em", ...).
You can only set the size of an image element.
Since: Banana Accounting 8.0.5
var image = report.addImage("C:/Documents/Images/img.jpg"); image.setSize("3cm", "6cm");
setStyleAttribute(attr_name, attr_value)
Set a style attribute to the element. Attributes ids and values follow the CSS specification. This attibute correspont to the inline styles in Css.
paragraph.setAttribute("font-size", "24pt");
setStyleAttributes(attributes)
Set style attributes to the element. Attributes ids and values follow the CSS specification. Those attributes correspond to the inline styles in Css.
paragraph.setAttribute("font-size:24pt;font-weight:bold;");
setTitle(title)
Set the title of the element.
Title can be only set to a document element.
Since: Banana Accounting 8.0.5
document.setTitle("Annual report");
setUrlLink(link)
Set a link to an external file (file://...) or a web page (http://....).
To the element the class "link" is automatically added.
report.addParagraph("Link to Banana.ch web page").setUrlLink("http://www.banana.ch");