You are here

Export Apps

Export apps are used to export data in a custom format.

  • Define attribute @task as export.file
    // @task = export.file

  • Define the extension of the file to be exported.
    // @exportfiletype = xml

  • The text to be written to the export file is the return value of the exec function and must be a return.
    return "exported text".

  • When the script terminate and if the return text is not null and does not start with "@Cancel ", the user will be promped with a dialog to choose a file name where to export. 

Example

Export all the accounting with description and balance in a xml file.

// @id = ch.banana.apps.export
// @api = 1.0
// @pubdate = 2016-04-08
// @doctype = *.*
// @description = Export into a text file (.txt)
// @task = export.file
// @exportfiletype = txt
// @timeout = -1

function exec() {
var exportResult = '<accounts>';
    var tableAccounts = Banana.document.table('Accounts');
    if ( !tableAccounts) {
      return;
   }
   for (i=0;i<tableAccounts.rowCount;i++) {
        if (tableAccounts.row(i).value('Account')) {
            exportResult += '<account>';
            exportResult += '<accountnr>' + tableAccounts.row(i).value('Account') + '</accountnr>';
            exportResult += '<description>' + tableAccounts.row(i).value('Description') + '</description>';
            exportResult += '<balance>' + tableAccounts.row(i).value('Balance') + '</balance>';
            exportResult += '</account>';
        }
    }
    exportResult += '</accounts>';
    //return the string
    return exportResult;
}

 

Share this article: Twitter | Facebook | Email


Help us improve the documentation

We welcome feedback on how to improve this page.
Tell us what theme needs a better explanation or how to clarify a topic.