Spreadsheet Helpers
This section provides more information about common and helpful methods when dealing with spreadsheets.
Documentation
Methods
Method | Description |
---|---|
getColumnName | Get the column letter based on a number.jspreadsheet.helpers.getColumnName(columnNumber: Number) => String |
getCellNameFromCoords | Get the spreadsheet-like cell name from the coordinates.jspreadsheet.helpers.getColumnName(x: Number, y: Number) => String |
getCoordsFromCellName | Get the coordinates from the spreadsheet-like cell name.jspreadsheet.helpers.getCoordsFromColumnName(cellName: String) => [Number, Number] |
shiftFormula | Update all variables from a formula based a shift of x, y positions.jspreadsheet.helpers.shiftFormula(formula: String, x: Number, y: Number) => String |
getTokensFromRange | Extract the tokens from a range.jspreadsheet.helpers.getTokensFromRange(range: String) => Array |
getRangeFromTokens | Get the range from an array of tokens. jspreadsheet.helpers.getRangeFromTokens(tokens: Array) => String |
getCoordsFromRange | Get the coordinates from a range string.jspreadsheet.helpers.getCoordsFromRange(range: string, adjust?: boolean) => [number,number,number,number] |
getRangeFromCoords | Get the range string such as A1:A9 from an array of numbersjspreadsheet.helpers.getRangeFromCoords(range: [number,number,number,number]) => String |
createFromTables | Extract the configuration to create a new spreadsheet from a static HTML element.jspreadsheet.helpers.createFromTable(element: HTMLElement, options: Object) => Object |
parseCSV | Transform a CSV string into an array.jspreadsheet.helpers.parseCSV(data: String, delimiter: String) => Array |
getTokensFromCoords | Get all token names from a range of coordinates.getTokensFromCoords: (x1: number, y1: number, x2: number, y2: number, wsName?: string) => [] |
Examples
Data Grid Helpers Example
<div id="spreadsheet"></div>
<script>
let worksheets = jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
minDimensions: [6,6]
}]
});
// Returns A1
jspreadsheet.helpers.getCellNameFromCoords(0,0);
// Returns (4) [1, 0, 2, 3]
jspreadsheet.helpers.getCoordsFromRange('B1:C4');
// Also works with the worksheet instance. Returns 1,1
let coords = worksheets[0].helpers.getCoordsFromCellName('B2');
</script>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
export default function App() {
// Spreadsheet array of worksheets
const spreadsheet = useRef();
// Returns A1
let cellName = jspreadsheet.helpers.getCellNameFromCoords(0,0);
// Returns (4) [1, 0, 2, 3]
let range = jspreadsheet.helpers.getCoordsFromRange('B1:C4');
// Also works with the worksheet instance. Returns 1,1
let coords = spreadsheet.current[0].helpers.getCoordsFromCellName('B2');
// Render data grid component
return (
<Spreadsheet ref={spreadsheet} license={license}>
<Worksheet />
</Spreadsheet>
);
}
<template>
<Spreadsheet ref="spreadsheet" :license="license">
<Worksheet />
</Spreadsheet>
</template>
<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
const license = 'ZjExZjgzZDY4YjZhMGJjM2UwNTI5ODI3YWU3OWE4ZDAwZmRiNGM5ZTlhM2M2YjBhMWQ4YzZiYTk5NTRhODdlNjJiNWIwYjM0MzhkYjc2ZmMwMWM5NDI4ODgwOGRmY2YxY2JhMTI5ZjE0YTNkY2I3NTM0YTI1NjhmZjgwOGUxNTksZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpJMk16WTJNVEUwTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==';
export default {
components: {
Spreadsheet,
Worksheet,
},
mounted() {
// Returns A1
let cellName = jspreadsheet.helpers.getCellNameFromCoords(0,0);
// Returns (4) [1, 0, 2, 3]
let range = jspreadsheet.helpers.getCoordsFromRange('B1:C4');
// Also works with the worksheet instance. Returns 1,1
let coords = this.$refs.spreadsheet.current[0].helpers.getCoordsFromCellName('B2');
},
data() {
return {
license
};
}
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import "jspreadsheet/dist/jspreadsheet.css"
import "jsuites/dist/jsuites.css"
@Component({
standalone: true,
selector: "app-root",
template: `<div #spreadsheet></div>`
})
export class AppComponent {
@ViewChild("spreadsheet") spreadsheet: ElementRef;
// Worksheets
worksheets: jspreadsheet.worksheetInstance[];
// Create a new data grid
ngAfterViewInit() {
// Create spreadsheet
this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
worksheets: [
{
minDimensions: [10,10]
}
]
});
// Returns A1
let cellName = jspreadsheet.helpers.getCellNameFromCoords(0,0);
// Returns (4) [1, 0, 2, 3]
let range = jspreadsheet.helpers.getCoordsFromRange('B1:C4');
// Also works with the worksheet instance. Returns 1,1
let coords = this.worksheets[0].helpers.getCoordsFromCellName('B2');
}
}