How to add Two Tabs under Excel sheet using Scripting

Tejashri2
Tera Contributor

Hello Guy's

 

I have requirement to create Excel with two tabs, Earlier we have used below code to create one tab but now stuck on two tab creation.

 

var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id', '13acdb45870e06d065dda9773cbb3561');
gr.query();
if (gr.next()){

var Headers = ["Request Item", "New Device Name", "Slot Number"]; //add headers that you want to show in XLS file
var xlsData = ''; //The variable xlsData will contain a string which is used to build the xls file contents
var xlsData1 = '';

for (var i = 0; i < Headers.length; i++) { //Build the Headers
xlsData = xlsData + '"' + Headers[i] + '"' + ',';
}
xlsData = xlsData + "\r\n";

 


//Glide SCTASK to take details of the task
var fileName = "Tejashri.csv";
xlsData = xlsData + '"' + gr.request_item.getDisplayValue() + '",' + '"' + "newDevice" + '",' + '"' + "slotNum" + '"';
xlsData = xlsData + "\r\n";

 

var grAttachmentt = new GlideSysAttachment();
grAttachmentt.write(gr, fileName, 'application/csv', xlsData, xlsData);

}

 

 

 

Thank You!

2 REPLIES 2

Mark Manders
Mega Patron

CSV doesn't support multiple tabs and that's what ServiceNow supports. I would just create multiple ones and combine them afterwards if it needs to be one file.

Otherwise I'm afraid you need to rely an third-party libraries 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Thank you!