Xbasic

excel_to_json Function

Syntax

c result = excel_to_json(c filename [, c filter [, c order [, c sheetname]]]])

Arguments

filenameCharacter

The file name of the Excel file.

filterCharacter

Default = "". An optional SQL WHERE clause. Ignored if data is read from multiple sheets.

orderCharacter

Default = "". An optional SQL ORDER clause. Ignored if data is read from multiple sheets.

sheetnameCharacter

Default = the first sheet. The name of the Excel sheet to read records from. If you do not specify a value, the first sheet in the file is assumed. You can specify a comma delimited list of sheets, or * (to get all sheets). If you specify * or more than one sheet, you cannot specify a filter or order and the result is a JSON array with data for each sheet.

Returns

resultCharacter

Returns the Excel file as JSON array where each record is an object in the JSON array.

Description

Takes an Excel file and returns a string of JSON data.

Example

dim fn as c = "C:\excelfiles\myExcelDoc.xlsx";
dim json as c

json = excel_to_json(fn, "", "", "products")

showvar(json)

See Also