Xbasic
Office::ExcelDocumentToJson Method
Syntax
.ToJson as C ([ReturnAsObjects as L = .t.])
Arguments
- 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
Returns all the Sheets in a spreadsheet as json.
Example
dim doc as Office::ExcelDocument dim filename as c = "C:\files\ExcelDocument.xlsx" ? doc.Load(filename) = .T. ? doc.ToJson() = {"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" : [ ]} ? doc.ToJson(.f.) = {"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