Xbasic
Office::ExcelDocumentSheetsToJson Method
Syntax
.SheetsToJson as C (FileName as C [, ReturnAsObjects as L = .t.])
Arguments
- FileNameCharacter
The Excel file to read. File must end in .xlsx extension.
- ReturnAsObjectsLogical
Default = .t.. If .f., newlines and quotes will be escaped.
Returns
- resultCharacter
Returns the data in the Excel file as a JSON string.
Description
Gets all sheets and cell values as JSON.
Example
dim doc as Office::ExcelDocument
dim filename as c = "C:\Users\JaneDoe\Documents\excelDoc.xlsx"
json1 = doc.sheetsToJson(filename)
? json1
= {"Sheet1" : [
{"Firstname" : "John" , "Lastname" : "Smith" , "City" : "Boston" , "State" : "MA"} ,
{"Firstname" : "Henry" , "Lastname" : "Rhodes" , "City" : "New York" , "State" : "NY"} ,
{"Firstname" : "Allison" , "Lastname" : "Berman" , "City" : "Los Angeles" , "State" : "CA"} ,
{"Firstname" : "Amanda" , "Lastname" : "Higgins" , "City" : "Chicago" , "State" : "IL"} ,
{"Firstname" : "Nancy" , "Lastname" : "Clark" , "City" : "Boston" , "State" : "MA"} ,
{"Firstname" : "Cecelia" , "Lastname" : "Dawkins" , "City" : "Boulder" , "State" : "CO"} ,
{"Firstname" : "Kathy" , "Lastname" : "Morton" , "City" : "New York" , "State" : "NY"}] , "Sheet2" : [
] , "Sheet3" : [
]}
json2 = doc.SheetsToJson(filename,.f.)
? json2
= {"Sheet1" : "[\r\n{\"Firstname\" : \"John\" , \"Lastname\" : \"Smith\" , \"City\" : \"Boston\" , \"State\" : \"MA\"} , \r\n{\"Firstname\" : \"Henry\" , \"Lastname\" : \"Rhodes\" , \"City\" : \"New York\" , \"State\" : \"NY\"} , \r\n{\"Firstname\" : \"Allison\" , \"Lastname\" : \"Berman\" , \"City\" : \"Los Angeles\" , \"State\" : \"CA\"} , \r\n{\"Firstname\" : \"Amanda\" , \"Lastname\" : \"Higgins\" , \"City\" : \"Chicago\" , \"State\" : \"IL\"} , \r\n{\"Firstname\" : \"Nancy\" , \"Lastname\" : \"Clark\" , \"City\" : \"Boston\" , \"State\" : \"MA\"} , \r\n{\"Firstname\" : \"Cecelia\" , \"Lastname\" : \"Dawkins\" , \"City\" : \"Boulder\" , \"State\" : \"CO\"} , \r\n{\"Firstname\" : \"Kathy\" , \"Lastname\" : \"Morton\" , \"City\" : \"New York\" , \"State\" : \"NY\"}]" , "Sheet2" : "[\r\n]" , "Sheet3" : "[\r\n]"}See Also