GlideExcelParser - Scoped, Global

You can parse .xlsx formatted Excel files.

The GlideExcelParser methods can be used in global and scoped scripts. The API name space identifier "sn_impex" must be used when creating a GlideExcelParser object.

GlideExcelParser - close()

Close the connection to the input stream and release the document.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
void

GlideExcelParser - getColumnHeaders()

Returns a list of column headers from the parsed document.

Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
Array An array of strings of column headers from the parsed document.

GlideExcelParser - getErrorMessage()

Returns the error message when the parse() method fails.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
String The error message.

GlideExcelParser - getRow()

Get the current row values and headers.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
Object The row headers are property names and the row values are property values.

GlideExcelParser - GlideExcelParser()

Creates an instance of GlideExcelParser.

The API name space identifier "sn_impex" must be used when creating a GlideExcelParser object.

Table 9. Parameters
Name Type Description
None
var parser = new sn_impex.GlideExcelParser(); 
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream(<attachment sys id>);

parser.parse(attachmentStream); 

//retrieve the column headers
var headers = parser.getColumnHeaders();  
var header1 = headers[0]; 
var header2 = headers[1]; 

//print headers
gs.print(header1 + " " + header2); 

while(parser.next()) { 
  var row = parser.getRow(); 
  //print row value for both columns   
  gs.print(row[header1] + ' ' + row[header2]) 
}

GlideExcelParser - next()

Moves to the next row.

Table 10. Parameters
Name Type Description
None
Table 11. Returns
Type Description
Boolean Returns true if there is a next row, otherwise, returns false.

GlideExcelParser - parse(GlideScriptableInputStream inputStream)

Parse an XLSX formatted Excel document.

Table 12. Parameters
Name Type Description
inputStream GlideScriptableInputStream The Excel document to be parsed.
Table 13. Returns
Type Description
Boolean Returns true if the parse was successful, otherwise, returns false.

Example from a scripted REST API script where the Excel file is sent in the request payload.

var parser = new sn_impex.GlideExcelParser();
parser.parse(request.body.dataStream); 

GlideExcelParser - setHeaderRowNumber(Number headerRowNumber)

Set the number of the header row to be retrieved.

Table 14. Parameters
Name Type Description
headerRowNumber Number The header row to be retrieved.
Table 15. Returns
Type Description
void

GlideExcelParser - setNullToEmpty(Boolean empty)

Return an empty value instead of null when an Excel cell is not present.

Table 16. Parameters
Name Type Description
empty Boolean When true, cells that are not present return an empty value. When false, cells that are not present return null.
Table 17. Returns
Type Description
void

GlideExcelParser - setSheetName(String sheetName)

Set the name of the sheet to be retrieved.

If both setSheetNumber() and setSheetName() are set, setSheetName() is used.

Table 18. Parameters
Name Type Description
sheetName String The name of the sheet to be retrieved.
Table 19. Returns
Type Description
void

GlideExcelParser - setSheetNumber(Number sheetNumber)

Set the number of the Excel sheet to be retrieved.

If both setSheetNumber() and setSheetName() are set, setSheetNumber() is ignored.

Table 20. Parameters
Name Type Description
sheetNumber Number The Excel sheet number to retrieve.
Table 21. Returns
Type Description
void