Clearing Cell Ranges in Kendo Angular Spreadsheet
| Product | Progress® Kendo UI® for Angular Spreadsheet |
Description
When working with the Spreadsheet for Angular, you might need to clear data from specific cells or ranges. This knowledge base article also answers the following questions:
- How to reset the value of specific cell ranges in Kendo UI Spreadsheet for Angular?
- How to clear all data from the Kendo UI Spreadsheet for Angular?
- Is there a clear function available for cell ranges in the Kendo UI Spreadsheet for Angular?
Solution
Depending on the use case, you can clear a specific range of cells or reset the entire Spreadsheet data.
Clearing Specific Cell Ranges
To clear specific cell ranges in the Kendo UI Spreadsheet for Angular, access the SpreadsheetWidget instance. This instance allows you to get the active sheet and reset a specific range of cells using the clear method. Here is how you can do it:
public clearCells(): void {
this.spreadsheet.spreadsheetWidget.sheets().forEach(function (sheet) {
sheet.range("A1:A2").clear();
});
}
Clearing All Data from the Spreadsheet
To clear all data from the Spreadsheet, you can reset all data by setting the sheets to an empty array or a new configuration. This approach removes all existing data and configurations from the Spreadsheet:
public clearAll(): void {
const dataEmpty = [{
name: 'Sheet1',
rows: []
}];
this.spreadsheet.spreadsheetWidget.fromJSON({ sheets: dataEmpty });
}
Both methods provide ways to clear data, whether it's a specific range or all the data in the Spreadsheet.