I want to change the ColumnsCount property value at runtime, for example, based on the Excel files that the app is loading.
===
TELERIK EDIT:
A possible workaround is to recreate the Spreadsheet component. The downside will be a minor UI flicker. Alternatively, set ColumnsCount to a small value like 1. In this way the component will display only the existing columns in the opened file.
<TelerikNumericTextBox @bind-Value="@SpreadsheetColumnsCount"
Min="0" Max="999"
Width="80px" />
<TelerikButton OnClick="@OnButtonClick">Apply ColumnsCount</TelerikButton>
@if (SpreadsheetVisible)
{
<TelerikSpreadsheet Data="@SpreadsheetData"
ColumnsCount="@SpreadsheetColumnsCount">
</TelerikSpreadsheet>
}
@code {
private byte[]? SpreadsheetData { get; set; }
private int SpreadsheetColumnsCount { get; set; } = 10;
private bool SpreadsheetVisible { get; set; } = true;
private async Task OnButtonClick()
{
SpreadsheetVisible = false;
await Task.Delay(1);
SpreadsheetVisible = true;
}
}
On the Spreadsheet control please display a function list when the user types "=" or provide the user with some other reference about the available functions.
<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 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.