The OpenAF's XLS plugin offers one of the most handy features: the ability to write a simple javascript array of maps to an Excel spreadsheet. But first a warning: it can't be a complex sub maps/arrays, just plain strings/numbers array which usually is enough (although there is an alternative way that will mention on the end of the post).
The functionality is captured on the setTable function of the XLS plugin. Giving an example, let's say we get an array with all the files and corresponding info from a folder using io.listFiles:
var path = ".";
var outputFile = "test.xlsx";
var listOfFiles = io.listFiles(path).files;
plugin("XLS");
var xls = new XLS();
var sheet = xls.getSheet("my sheet");
xls.setTable(sheet, "B", "2", listOfFiles);
xls.writeFile(outputFile);
xls.close();
On the first lines of the code we defined the output file as "test.xlsx". After running this script:
openaf -f test.js
if there wasn't any errors you will find a test.xlsx on the same folder that will look similar to this:
The first instinct is: "can I format it?" The answer is yes. You can add an auto-filter easily:
ow.loadFormat();
ow.format.xls.autoFilter(sheet, "B2:K2")
"Can I change color, font, etc...?": Yes, check out ow.format.xls.getStyle.
"Can I just use a previous excel template and just fill it in?": Yes. The probably the easiest to do. Just change the new XLS line to this:
var xls = new XLS("myTemplate.xlsx");