How to get the cell information in Javascript Spreadsheet?
Description
This knowledge base explains to get the cell information in Spreadsheet.
Solution
It can be achieved by “getCell” public method. It returns the applied properties of a particular cell. The different types of cell properties available in spreadsheet are described below.
Cell Model Properties | Description |
value | Defines the value of the cell which can be text or number. |
formula | Defines the formula or expression of the cell. |
index | Specifies the index of the cell. |
format | Specifies the number format code to display value in specified number format. |
hyperlink | Specifies the hyperlink of the cell. |
wrap | Wraps the cell text to the next line, if the text width exceeds the column width. |
isLocked | Specifies the cell is locked or not, for allow edit range in spreadsheet protect option. |
validation | Specifies the validation of the cell. |
colSpan | Specifies the column-wise cell merge count. |
rowSpan | Specifies the row-wise cell merge count. |
[HTML]
<div id="spreadsheet"></div>
[TS]
//Initialize Spreadsheet component let spreadsheet: Spreadsheet = new Spreadsheet({ sheets: [ { name: 'Car Sales Report', ranges: [{ dataSource: (dataSource as any).defaultData }], // you can refer this datasource in this link https://ej2.syncfusion.com/javascript/demos/spreadsheet/default/datasource.js rows: [ { index: 30, cells: [ { index: 4, value: 'Total Amount:', style: { fontWeight: 'bold', textAlign: 'right' } }, { formula: '=SUM(F2:F30)', style: { fontWeight: 'bold' } }, ] }], columns: [ { width: 180 }, { width: 130 }, { width: 130 }, { width: 180 }, { width: 130 }, { width: 120 } ] }], created: (): void => { spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:F1'); spreadsheet.numberFormat('$#,##0.00', 'F2:F31'); spreadsheet.updateCell({ formula: '=PERCENTAGE(F1,F2)' }, 'F12'); }, select: (args: SelectEventArgs) => { let range: number[] = getRangeIndexes(args.range); // to get the range of indexes let cell: CellModel = getCell(range[0], range[1], spreadsheet.getActiveSheet()); // to get the cell information in the selected cell console.log(cell); }
Demo Sample: https://stackblitz.com/edit/hbmtxq?file=index.ts
Conclusion
I hope you enjoyed learning about how to get the cell information in Javascript Spreadsheet?
For current customers, you can check out our Document processing libraries from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!