<TelerikSpreadsheet Height="500px" Width="100%">
<SpreadsheetSheets>
<SpreadsheetSheet Name="Sheet1">
<SpreadsheetSheetColumns>
<SpreadsheetSheetColumn Index="0" Width="100px"></SpreadsheetSheetColumn>
<SpreadsheetSheetColumn Index="1" Width="200px"></SpreadsheetSheetColumn>
</SpreadsheetSheetColumns>
<SpreadsheetSheetRows>
<SpreadsheetSheetRow Index="0">
<SpreadsheetSheetCell Value="Item"></SpreadsheetSheetCell>
<SpreadsheetSheetCell Value="Price"></SpreadsheetSheetCell>
</SpreadsheetSheetRow>
<SpreadsheetSheetRow Index="1">
<SpreadsheetSheetCell Value="Apples"></SpreadsheetSheetCell>
<SpreadsheetSheetCell Value="1.50"></SpreadsheetSheetCell>
</SpreadsheetSheetRow>
<SpreadsheetSheetRow Index="2">
<SpreadsheetSheetCell Value="Bananas"></SpreadsheetSheetCell>
<SpreadsheetSheetCell Value="2.00"></SpreadsheetSheetCell>
</SpreadsheetSheetRow>
</SpreadsheetSheetRows>
</SpreadsheetSheet>
</SpreadsheetSheets>
</TelerikSpreadsheet>
I'm attempting to create a custom spreadsheet tool that updates the values of the cells the user has selected. The problem is that I can't get the current cell selection from the TelerikSpreadsheet control.
I attempted to get it by exporting it from the control and importing it into an XlsxFormatProvider. I thought what I needed might be in the 'Worksheet.ViewState.SelectionState.ActiveCellIndex' object but it always seems to be set to Cell[0,0]. Is there somewhere else I can find the selection?
The following code works but always updates A1.
byte[] excelFileContent = await SpreadsheetRef.ExportToExcelAsync();
XlsxFormatProvider formatProvider = new();
Workbook workbook = formatProvider.Import(excelFileContent);
Worksheet worksheet = workbook.ActiveWorksheet;
CellIndex cellRange = worksheet.ViewState.SelectionState.ActiveCellIndex;
worksheet.Cells.GetCellSelection(cellRange).SetValue("Selected!!");
byte[] newExcelFileContent;
using (MemoryStream ms = new())
{
formatProvider.Export(workbook, ms);
newExcelFileContent = ms.ToArray();
}
FileData = newExcelFileContent;
await InvokeAsync(StateHasChanged);
I'm having the same issue that was fixed in the Telerik UI for WinForms RadSpreadsheet. When loading the workbook into a Blazor UI TelerikSpreadsheet control, the validation dropdown shows fine when exported to Excel but the Telerik control doesn't show the dropdown. However, it only allows you to type values in the supplied validation list as expected.
RadSpreadsheet: ListDataValidation not working, dropdown does not appear in control (telerik.com)
ListDataValidationRuleContext context = new(worksheet, ri, ci)
{
InputMessageTitle = "Restricted input",
InputMessageContent = "The input is restricted to the week days.",
ErrorStyle = ErrorStyle.Stop,
ErrorAlertTitle = "Wrong value",
ErrorAlertContent = "The entered value is not valid. Allowed values are the week days!",
InCellDropdown = true,
Argument1 = "Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"
};
cell.SetDataValidationRule(new ListDataValidationRule(context));
Please add support for protected worksheets and protected workbooks.