Query the ShapeSheet
Query the ShapeSheet
A ShapeSheet Query is a high-performance way of retrieving data from shapes.
You can retrieve:
Formulas
Results
Formulas and Results simultaneously
You can query
A single shape
Multiple shapes on a page
There are two kinds of queries:
A CellQuery - used for retrieving specifically identified cells
A SectionQuery - an optimized way of retrieving all the cells across multiple rows
Building a query
Queries are simple objects. Create one, identify which cells you want by adding a column for each cell. And then ask the query to get formulas, results, or both. The query will return a Table object with one or more rows.
Examples
Getting a formula from a single cell from a shape
formulas will be Table object - with one column and with one row
To get the retrieved value
Getting a formula from multiple cells from a shape
You can retrieve the values like this
Return results from a single shape
Now let's learn how to return results.
The first thing you should realize is that you can specify what datatype to return the results in. Your choices are double, bool, intm string. To specify the type you will use a generic parameter on the GetResults() method.
A Note about grouping
You'll notice that tables that come back from these queries always have groups. Their usage will not be clear until later, but the intention is that the groups identify which rows in the table belong to which shape.
When perfoming a CellQuery on a single shape, there is only ever one group that identifies exactly one row.
Querying a Section on a single Shape
Imagine you want to query all the cells in a specific section. For example maybe you want to find all the character formatting cells. A section query makes it easy to query cell. The because all the rows will be fetched we only need to know the section index and the cell indices.
The returned table contains more than one row. But it contains exactly one group - each group is mapped to a specific shape - that contains all the rows.
NOTE: A group could contain zero rows because some sections may not exist on the shape or that section may contain no rows
Retieving cells from multiple shapes You know how to get shapesheet data from a single shape. What about multiple shapes? The process is very similar: construct the same query but instead of asking the query to run against a specific shape, you identify the page that contains all the shapes and provide the shapeids for those shapes.
Now the formulas table that is returned will have exactly two rows and twoc olumns. It will also have two groups. Each group identifies one row.
What if we wanted the all character colors for each shape?
The formulas table will have multiple rows, but will have exactly two groups. Each group will contain 1 or more rows.
Last updated