Entering dates in the Blazor spreadsheet act weird if you enter a 2 digit year. It seems to subtract a day when you remove focus from the cell.
Start by entering a date like 2/2/25:
Then hit enter or otherwise remove focus from the cell and this is what it changes it to. Notice it subtracts a day:
Then put focus back on the cell:
Now look at the editor at the top:
I note that when you enter a two digit year in Excel it defaults the century to 20 when you enter a year less than 30. It defaults a century of 19 when you enter a year >= 30. It appears that with the Telerik Blazor spreadsheet it always defaults the century to 19. You can make arguments on either side of that but the real issue here is that it subtracts a day when you enter a two digit year. It doesn't do that when you enter a 4 digit year.
The related thing that becomes an issue is when you export the spreadsheet to a byte array and evaluate the cell RawValue. When you enter a 4 digit year, you get a raw value that is a positive number and you can use FormatHelper.ConvertDoubleToDateTime to get the date value. When you enter a 2 digit year and get the raw value, it is a negative number, and when you call FormatHelper.ConvertDoubleToDateTime it returns null.
Can you please comment on the rhyme or reason the spreadsheet behaves this way? Or is this a bug(s)?
Thanks.
When copy-pasting a cell from Excel to the Spreadsheet, our component then generates an invalid horizontal alignment value, which does not conform to the document format specification:
<alignment horizontal="start" vertical="bottom" />
The valid values for horizontal do not include start:
<simpleType name="ST_HorizontalAlignment">
<restriction base="xsd:string">
<enumeration value="general"/>
<enumeration value="left"/>
<enumeration value="center"/>
<enumeration value="right"/>
<enumeration value="fill"/>
<enumeration value="justify"/>
<enumeration value="centerContinuous"/>
<enumeration value="distributed"/>
</restriction>
</simpleType>
Here are the steps:
1. Copy some basic content from Excel (two text cells)
2. Paste the content to the Telerik Blazor Spreadsheet component and save the XLSX file
Reproduction: https://blazorrepl.telerik.com/QJEJlAvY33zlToJO18.
To reproduce:
step 1: observe that cells div.k-spreadsheet-fixed-container fills div.k-spreadsheet-view
step 2: Move the splitter handler to left
step 3: Observe that the div.k-spreadsheet-view width is adjusted to the new size of its parent, but div.k-spreadsheet-fixed-container is not.
Expected: Spreadsheet component handles updating the size its parts.
===
ADMIN EDIT
===
A possible workaround for the time being is to simulate the browser resize event - the Spreadsheet is properly resized in this case.
Here is how to achieve that: https://blazorrepl.telerik.com/wzOfQbEW38JtEjFD36.
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.
When the Spreadsheet generates the byte array with ExportToExcelAsync(), it doesn't include the information about the active cell and sheet. For example, this restricts the ability to set the number of frozen columns and rows, based on the active cell. One must provide explicit UI for this as a custom tool.
===
TELERIK EDIT: Expanded the request scope to also include the active sheet.
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;
}
}
<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.