exporting optimal properties to Excel

Started by Gerald Groot Roessink, November 11, 2022, 22:11:02 PM

Previous topic - Next topic

Gerald Groot Roessink

Hello,
I extended the example script Export to Excel to include propertyvalues organized in columns without hardcoding the propertynames and allowing them to be optional. Just for business-object I replaced lines in the original:


Headers (lines 35-41 in the example):
// Set up some headers including unique tags
const  alltags = ["Name","Documentation"] ;
$('business-object').each(function(o) {
 for (i = 0; i<o.prop().length;i++) {alltags.push(o.prop())};
});
const headers = [...new Set(alltags)]; //make tags unique

Lines (lines 56-66 in the example):
// Loop through all elements and set cells to object info
   var current_row = 1;
   $('business-object').each(function(o) {
   excel.set(0, 0, current_row, o.name);
   excel.set(0, 1, current_row, o.documentation);
   for (i = 0; i<headers.length;i++) {
       excel.set(0, i, current_row, o.prop(headers));
   }
   current_row++;
});


It works perfect except for optional properties. Then the resultating field in the Excel contains the word "undefined". A blank field would be a bet beter result but I don't seem to be able to change tot control this in jArchi.

Any suggestions?

With regards
Gerald


Phil Beauvoir

#1
Hi, welcome to the Archi forums!

I think this is a general JavaScript issue. You need to check the value returned by o.prop(headers) and if it is null set it to an empty string. For example:

value = o.prop('propertyName');
excel.set(0, i, current_row, value == null ? "" : value);
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.