Generate Excel file (xls or xlsx) based on script

Gustavo Olivei1
Tera Contributor

Hello All,

 

I am looking for some help to generate an Excel file based on Script. I read a lot of content based on CSV file, but the request is to have a XLS or XLXS file. So, I have the script results working fine for csv, so I just want to "improve" the result.

 

The request is:

I want an Excel file to show in the header the name of the field (ex: Assignment Group) and the number of records assigned to them (ex: 5). There is more complexity to obtain the result (filtering and using Glideaggregate), but the final output into the file should be like this:

 

Assignment GroupQuantity
Group A5
Group B2

 

The current code that I am using you can find below:

var gr = new GlideRecord('table');
gr.get('sys_id of record');
var grAttachment = new GlideSysAttachment();
grAttachment.write(gr, filename, contenttype, excelData);
14 REPLIES 14

I've followed these step, but the resulting file is corrupt/invalid. I receive the following message when trying to open it:

peter0611_0-1733507543162.png

When I click 'Yes', it fails and I receive this message:

peter0611_1-1733507618515.png

Has anyone else been able to get this to work?

 

 

Same problem, any ideea how this can be solved? 
I tried different MIME types, adding different headers, but no success.

I had to daily provide xls files with data obtained by a script.
I used a quite complicated workaround :

The xls file is created by a scheduled report.

The input file for the report is an import set file filled in a scheduled import.

The scheduled import:
pre-script : empties the import set file, builds a csv file and attaches it to a datasource
post-script : triggers scheduled report.

ajays
Tera Contributor

Can you share your complete script here, will check it out 

Hi Ajay,

 

Can you please tell how to change background color of rows using tags. Like you used tag to make header bold, I want to make header bold and with different background color for the row