toJSON(type: String);
type. Range type. By default this optional parameter is set to Cells.
The toJSON method converts a specified range to JSON object.
This method returns a JSON object with the following properties: left and top are indexes of column and row in the top left corner of the range respectively, width - width of this range, height - its height, type - type.
To execute the example, the HTML page must contain the TabSheet component named tabSheet (see Example of Creating the TabSheet Component). Get the range B1:B2, get coordinates of the top left corner, the text inside this range, and determine if this range includes fixed columns and rows:
// Set coordinates of the top left range corner var tlCoord = new PP.Ui.TabSheetCoord(1, 1); // Set coordinates of the bottom right range corner var brCoord = new PP.Ui.TabSheetCoord(2, 1); // Create the B1:B2 range var range = new PP.Ui.TabSheetRange(tlCoord, brCoord, tabSheet); // Transform this range into a JSON object var rangeObj = range.toJSON(); // Get coordinates of the top left range corner var coord = "(" + rangeObj.left + ", " + rangeObj.top + ")"; console.log("Coordinates of the top left corner: " + coord); // Get text inside this range var plainText = range.toPlainText(); console.log("Text inside the range:"); console.log(plainText); // Determine if fixed columns and rows are in the range var rangeInfo = range.getRangeInfo(); console.log("Fixed columns " + (rangeInfo.fixedColumns ? "" : "are not ") + "are in the range"); console.log("Fixed rows " + (rangeInfo.fixedRows ? "" : "are not ") + "are in the range");
After executing the example the browser console shows coordinates of top left corner of the range B1:B2, text inside this range and messages informing if this range includes fixed columns and rows:
Coordinates of the top left corner: (1, 1)
Text inside the range:
5315
6995
Fixed columns are not included in the range
Fixed rows are not included in the range
See also: