How can I create an Excel file from a script in Servicenow?

mpsteve137
Tera Expert

I just need a really simple example of how I can create a .xlsx file not .csv. What is the syntax for this when writing with GlideSysAttachment().write?

I've tried:

var gsa = new GlideSysAttachment();

gsa.write(fixGr, 'test.xlsx', 'text/xlsx', data); 

but when I go to open the created attachment in Excel, Excel says its may be corrupted or the wrong file type. 
Can anyone please provide a simple example of what the data would look like and how to write it properly?

pls help

13 REPLIES 13

Adam Stout
ServiceNow Employee
ServiceNow Employee

What is the use case?  Any list or report can natively be exported to Excel without any code.

Hey Adam,

In our case, we're distributing a report to external users. However, the report has gotten too large to send via email, and the client doesn't want to have users login and export themselves.

We're considering using a script to create the csv/xlsx file and sending with an integration.

Yes - that seems to be almost exactly what we need. Unfortunately, they won't for us due to clustered MID servers 😕

Export sets are not supported on MID Servers in a cluster

Chananain
Kilo Contributor

It is elementary. When you save the file, choose to save it as an excel file. The only thing I don't like is that it can't be saved in Google Sheets. This platform is way better to work with because it is easier to share the field and has more possibilities to work with the data from tables. But this is not a big problem because Coupler.io will link google sheets to excel. So I can quickly transfer Microsoft Office data to Google Sheets. But it would be great if they added the feature for the files to be saved in Google Sheets.