See also: tdf#137667.
CellFlags =1023 is specified to find all usedl cells where âusedâ should mean the same as in UsedArea. The above suggestion therefore only returns the expected result because the mentioned bug is active. The correct value is CellFlags=31 if cells with annotations (âcommentsâ) shall be included, CellFlags=23 otherwise (direct content of any kind - including formulas).
Please note that there isnât a single CellFlag for ânumberâ in the ordinary sense Calc uses the term. DateTime is treated differently based on the category of the NumberFormat. To get all the Number cells in the Calc sense, you need to use CellFlags=3 (=1+2)
Also:
The question assumes there is a definite âlast used cellâ in any sheet. The term is, however, ambiguous not only concerning the âusedâ: (1)Rightmost used cell of the bottom used row? (2)Bottommost used cell of the rightmost used column? (3)Bottom right cell of the âused rectangular rangeâ? The interpretation (§) was obviously assumed by the OQ. The answer Iâm commenting on silently assumed (2) if the actual working is interpreted. Afaik the order of CellRange objects returned by .queryContentCells() isnât specified at all.
Amendment;
I suppose the mentioned bug will not be fixed. The fix would break too many sheets using code relying on it. The âindispensable bugâ. An old phenomenon.