mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-07-08 18:16:08 +00:00
The spreadsheet engine parsed typed input with the invariant culture while displaying values with the current culture, breaking the edit round-trip on non-en-US hosts and making comma-decimal entry (10,50) impossible. Workbook gains a Culture property (defaults to CurrentCulture) which the component stamps from its inherited Culture parameter. It drives: - Cell input parsing (CellData type inference), including day-month date handling for cultures where the group and date separators collide (de-DE) - Edit text and display rendering (GetValue, GetValueAsString, GetDisplayText) - Number format rendering - format codes stay canonical invariant tokens while separators, month names, and AM/PM designators follow the culture - Formula entry and display via the new FormulaLocalizer (Excel FormulaLocal semantics: ';' argument separators and ',' decimals in comma-decimal cultures, lenient comma acceptance where unambiguous, canonical invariant storage) - Dialog input (data validation, conditional format, filter) via shared conversion helpers on SpreadsheetDialogBase XLSX and CSV files read and write canonical invariant values regardless of the workbook culture, including autofit column widths. Malformed formulas now surface as error trees instead of an unhandled lexer exception. Number format parsing is cached (hard-bounded) since CellView reparsed per render. Includes localization demos for the Spreadsheet and Document Processing sections and culture test suites. Note: headless code on non-en-US hosts now parses string values with the host culture; set Workbook.Culture explicitly (or to InvariantCulture) for host-independent processing.
69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Radzen.Documents.Spreadsheet;
|
|
|
|
namespace Radzen.Blazor.Spreadsheet;
|
|
|
|
#nullable enable
|
|
|
|
/// <summary>
|
|
/// Provides context for custom cell renderers in a spreadsheet.
|
|
/// </summary>
|
|
public class SpreadsheetCellRenderContext
|
|
{
|
|
/// <summary>
|
|
/// Gets the formatted display value of the cell.
|
|
/// </summary>
|
|
public string? FormattedValue { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the cell.
|
|
/// </summary>
|
|
public Cell Cell { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the worksheet that contains the cell.
|
|
/// </summary>
|
|
public Worksheet Worksheet { get; }
|
|
|
|
internal SpreadsheetCellRenderContext(string? formattedValue, Cell cell, Worksheet worksheet)
|
|
{
|
|
FormattedValue = formattedValue;
|
|
Cell = cell;
|
|
Worksheet = worksheet;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Provides context for custom cell editors in a spreadsheet.
|
|
/// </summary>
|
|
public class SpreadsheetCellEditContext : SpreadsheetCellRenderContext
|
|
{
|
|
private readonly Editor editor;
|
|
private readonly ISpreadsheet spreadsheet;
|
|
|
|
internal SpreadsheetCellEditContext(string? formattedValue, Cell cell, Worksheet worksheet, Editor editor, ISpreadsheet spreadsheet)
|
|
: base(formattedValue, cell, worksheet)
|
|
{
|
|
this.editor = editor;
|
|
this.spreadsheet = spreadsheet;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Commits the edited value to the cell. The value is converted to a string with the workbook
|
|
/// culture (the same culture the commit re-parses with) and applied through the undo/redo system.
|
|
/// </summary>
|
|
public Task CommitAsync(object? value)
|
|
{
|
|
editor.Value = value is IFormattable formattable
|
|
? formattable.ToString(null, Worksheet.Culture)
|
|
: value?.ToString();
|
|
return spreadsheet.AcceptAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cancels the current edit operation.
|
|
/// </summary>
|
|
public void Cancel() => editor.Cancel();
|
|
}
|