Shared strings
Spreadsheet can store repeated text in a shared string table and reference it from cell data.
Shared strings let you store repeated text in a central list and reference it by index from each cell. This reduces duplicated text in sheetData and keeps imports/exports consistent with Excel-style shared strings.
When shared strings are enabled, a cell can store an ss index and the actual text lives in sharedStrings. If ss is present, it takes precedence over any string or formatted value on the cell.
// Before shared strings
{
ue: { sv: "Hello" },
fv: "Hello",
}
// With shared strings
{
ss: 0
}
// sharedStrings[0] === "Hello"Usage
const App = () => {
const [sharedStrings, onChangeSharedStrings] = useState<string[]>([]);
const { getFormattedValue, getEffectiveExtendedValue, getUserEnteredExtendedValue } = useSpreadsheetState({
sharedStrings,
onChangeSharedStrings,
});
// For YJS support
useYSpreadsheetV2({
onChangeSharedStrings,
});
// For search, so it looks for shared strings index
useSearch({
getFormattedValue,
});
return <CanvasGrid getFormattedValue={getFormattedValue} getUserEnteredExtendedValue={getUserEnteredExtendedValue} getEffectiveExtendedValue={getEffectiveExtendedValue} />;
};Import and export
Excel/ODS/CSV imports honor
enabledSharedStrings.Exports use
sharedStringswhenssis present (shared strings take precedence over cell-level string/format values).
Notes
Shared string entries are not garbage-collected on delete, similar to Excel. Cells simply stop referencing their indices.
Last updated
Was this helpful?