Rows n’ Columns Docs
Visit HomepagePricing
  • Introduction
  • License
  • Demos
  • Getting started
    • Installation
    • Spreadsheet state
    • Headless UI
    • Imperative Spreadsheet API
    • Examples
  • ⚙️Configuration
    • Features
      • Data validation
      • Formula evaluation
      • Real-time data
      • Cell editors
      • Cell renderer
      • Structured Cell Renderer
      • Theming
      • Styling
      • Context menu
      • Localisation
      • Undo/Redo
      • Conditional formatting
      • Named ranges
      • Structured references
        • Schema based tables and columns
        • Calculated columns
      • Basic filter or Excel AutoFilter
      • Charts
      • Embedded content
      • Calculate on-demand
      • Drag and Drop
      • Pivoting and Grouping (Coming soon)
      • Tokenizer
      • Lazy loading/Infinite scrolling
      • OpenAI/Chat GPT Integration
      • Search
      • Formula protection
      • Autofill
      • Export canvas as image
    • Components
      • Canvas Grid
      • Toolbar
      • Sheet Tabs
      • Sheet Switcher
      • Sheet Status
      • Range Selector
      • Formula Input
      • Selection Input
      • SheetSearch
      • NamedRangeEditor
      • DeleteSheetConfirmation
      • TableEditor
      • Cell Format Editor
      • Conditional Format Editor
      • Data Validation Editor
      • Insert Link Editor
      • Insert Image Editor
      • Floating Cell Editor
    • API
      • Cell Data
      • Sheets
      • SpreadsheetProvider
      • useSpreadsheet
      • Modules
      • SheetCell
    • Using Spreadsheet with NextJS
    • Keyboard shortcuts
  • Collaboration
    • Real time collaboration
    • Yjs Collaboration
    • Supabase realtime Collaboration
  • Charts
    • Charts
    • Custom charts
  • Excel and Google sheets
    • CSV
    • Excel
    • Google sheets (Coming soon)
  • Functions
    • Named functions
    • Array formulas
  • Data persistence
    • Server side data persistence
    • React Query integration
  • Specifications
    • Browser support
    • Third party licenses
  • Support
    • Contact support
    • Report bugs
    • Feature requests
Powered by GitBook
On this page
  • How to use
  • Batch updating Spreadsheet values
  • Spreadsheet
  • Sheet
  • CellRange

Was this helpful?

  1. Getting started

Imperative Spreadsheet API

As an escape hatch, we bundle an imperative API for the Spreadsheet to control spreadsheet states

Imperative API is helpful when you want to trigger state changes without having to modify spreadsheet state manually. These APIs can do multiple actions in one function call

How to use

  1. Wrap your Spreadsheet in SpreadsheetProvider

  2. Make sure you have handlers for callbacks such as onChange

import React from 'react'
// Add css
import "@rowsncolumns/spreadsheet/dist/spreadsheet.min.css";
import { SpreadsheetProvider, CanvasGrid, useSpreadsheetApi } from "@rowsncolumns/spreadsheet"

const MySpreadsheet = () => {
  const api = useSpreadsheetApi()
  const [sheetData, setSheetData] =
      useState<SheetData<CellData>>({});
      
  const onChange = (sheetId, cell, value) => {
    setSheetData(prev => {
      
    })
  }
  return (
    <>
      <button
        onClick={() => {
          api.setActiveSheet(2)
          api.getSheet(2)
            .getRange({ rowIndex: 2, columnIndex: 2 })
            .setValue("hello world")
        }}
      >Switch to next sheet and Update a cell</button>
      <CanvasGrid onChange={onChange} />
    </>
  )
}

const App = () => {
  return (
    <SpreadsheetProvider>
      <MySpreadsheet />
    </SpreadsheetProvider>
  )
}

Batch updating Spreadsheet values

For batch update of values, we recommend using setValues API, so only 1 undo/redo history will be added

const api = useSpreadsheetApi()

api.getSheet(2).getRange({
  startRowIndex: 1;
  endRowIndex: 2;
  startColumnIndex: 2;
  endColumnIndex: 3;
}).setValues([
  ['foo', 'bar']
  ['hello', 'world']
])

Spreadsheet

getSheet(sheetId: number)

setActiveSheet(sheetId: number)

getActiveSheet()

insertSheet()

Sheet

setActiveCell(cell: CellInterface)

setSelections(selections: GridRange)

setRowHeight(rowIndex: number, dimension: number)

setColumnWidth(columnIndex: number, dimension: number)

getActiveCell()

getSelections()

getSheetId()

getRange(range: GridRange | CellInterface)

hideRow(rowIndexes: number[])

hideColumn(columnIndexes: number[])

showRow(rowIndexes: number[])

showColumn(columnIndexes: number[])

deleteRow(rowIndexes: number[])

deleteColumn(columnIndexes: number[])

insertRow(rowIndex: number, numRows = 1)

insertColumn(columnIndex: number, numColumns = 1)

moveRows(rowIndexes: number[], destinationRow: number)

moveColumns(columnIndexes: number[], destinationColumn: number)

onRequestSearch()

sortRange( selections: SelectionArea[], sortOrder: SortOrder )

sortColumn(columnIndex: number, sortOrder: SortOrder)

CellRange

setValue(text: string)

setValues(values: string[][])

clearFormatting()

setFormat(type: T, value: FormattingValue)

delete()

PreviousHeadless UINextExamples

Last updated 1 year ago

Was this helpful?