Expand description
GridCraft data kept in hidden workbook-scope defined names, so that it travels inside the xlsx file.
An item key is stored as names _gc_<key>_0, _gc_<key>_1, …, each a formula of string
literals joined with &: "…"&"…". Excel limits a string literal to 255 characters and a
formula to 8,192, so a long value is split over as many names as it needs and the file stays
one that Excel accepts. Older items (custom views, scripts, the watch list and scenarios) keep
one name each, _sc_<key>; reading accepts that form as well, so those items can move to this
format later, and a write of the same key replaces it.
XML can’t carry every character (controls other than tab, line feed and carriage return, and
U+FFFE and U+FFFF), and the xlsx writer drops those. In _gc_ items each of them, and the
marker itself, is written as ESCAPE followed by its code as four upper-case hex digits
(U+0001 becomes \u{FDD0}0001), and reading turns them back. The marker is a Unicode
noncharacter, which XML carries but real text does not use, so the escape costs nothing on
ordinary text. Legacy _sc_ items are read as they are.
Structs§
Constants§
- ESCAPE
- Starts an escaped character in a
_gc_item: U+FDD0, a noncharacter. - MAX_
ITEMS - The most items
itemsandkeysreturn: the first this many keys in sorted order. A file can carry any number of hidden names; the rest are not listed. - MAX_
ITEM_ CHARS - The longest item: 4,194,304 characters.
Functions§
- chunk_
formulas textas name formulas: string literals of at most 255 characters joined with&, each formula at most 8,192 characters, with the characters XML can’t carry escaped (seeESCAPE). Concatenatingstring_literalsof each and turning the escapes back givestextback.- get
- The item text stored under
key, orNonewhen there is none (or it is over the size limit). - get_
json - The item under
keyas JSON (Nonewhen missing or not JSON). - holds_
item - Whether the workbook holds an item under
name(compared without case): a hidden workbook-scope_gc_<key>_<k>name, or a workbook-scope legacy_sc_<key>name, which is read whether or not it is hidden. A visible_gc_name is the person’s own. - item_
key - The item a hidden name belongs to, lower-cased:
_gc_<key>_<k>and_sc_<key>give<key>. - items
- The items whose key starts with
prefix("macro_"), by lower-cased key, read in one pass over the names: the firstMAX_ITEMSitems that can be read, and the count of the readable ones past them. An item over the size limit is neither listed nor counted, so it takes no place another item could have. (keyslists keys without reading the items.) - keys
- The keys of the items stored in the workbook that start with
prefix("macro_"), sorted and lower-cased: the firstMAX_ITEMSof them. To read them all,itemstakes one pass where agetper key would take one each. - remove
- Removes the item stored under
key. - set
- Stores
textunderkey, replacing what was there (in either format). Empty text removes it. - set_
json - set_
many - Stores every
(key, text)ofitemsassetwould, with the checks done before anything changes and one pass over the names for all of them, so writing a thousand items into a workbook with many thousands of names stays near-linear. - string_
literals - Concatenates the string literals of a
"a"&"b""c"formula (anything outside them is ignored).