From be3ba9db571edf0d061b26d5500b615181c80b00 Mon Sep 17 00:00:00 2001 From: anmcgrath Date: Sat, 22 Jun 2024 18:32:33 +1000 Subject: [PATCH 1/2] Format date/time with number format string --- src/BlazorDatasheet.Core/Data/Sheet.cs | 2 +- src/BlazorDatasheet.Core/Data/SheetCell.cs | 2 +- src/BlazorDatasheet.SharedPages/Pages/Index.razor | 6 +++++- src/BlazorDatasheet/Render/VisualCell.cs | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/BlazorDatasheet.Core/Data/Sheet.cs b/src/BlazorDatasheet.Core/Data/Sheet.cs index 4ad14c55..c7a4851d 100644 --- a/src/BlazorDatasheet.Core/Data/Sheet.cs +++ b/src/BlazorDatasheet.Core/Data/Sheet.cs @@ -420,7 +420,7 @@ public void EndBatchUpdates() /// /// /// - public CellFormat? GetFormat(int row, int col) + public CellFormat GetFormat(int row, int col) { var defaultFormat = new CellFormat(); var cellFormat = Cells.GetFormat(row, col).Clone(); diff --git a/src/BlazorDatasheet.Core/Data/SheetCell.cs b/src/BlazorDatasheet.Core/Data/SheetCell.cs index 40abec9c..4ec08d24 100644 --- a/src/BlazorDatasheet.Core/Data/SheetCell.cs +++ b/src/BlazorDatasheet.Core/Data/SheetCell.cs @@ -73,7 +73,7 @@ public T GetValue() /// Gets the merged format at the cell's position. Setting the format will /// merge the format with existing formats in the sheet. /// - public CellFormat? Format + public CellFormat Format { get => _sheet.GetFormat(Row, Col); set => _sheet.Cells.MergeFormatImpl(new Region(Row, Col), value); diff --git a/src/BlazorDatasheet.SharedPages/Pages/Index.razor b/src/BlazorDatasheet.SharedPages/Pages/Index.razor index 5a5a462e..c3c652e3 100644 --- a/src/BlazorDatasheet.SharedPages/Pages/Index.razor +++ b/src/BlazorDatasheet.SharedPages/Pages/Index.razor @@ -45,7 +45,7 @@ - +
@@ -161,6 +161,10 @@ Sheet.Cells[3, 3].Value = "Date/Time:"; Sheet.Cells[3, 4].Type = "datetime"; Sheet.Cells[3, 4].Value = DateTime.Now; + Sheet.Cells[3, 4].Format = new CellFormat() + { + NumberFormat = "yyyy-MM-dd" + }; Sheet.Cells[4, 3].Value = "Select:"; Sheet.Cells[4, 4].Type = "select"; diff --git a/src/BlazorDatasheet/Render/VisualCell.cs b/src/BlazorDatasheet/Render/VisualCell.cs index 46f77d81..09565d0e 100644 --- a/src/BlazorDatasheet/Render/VisualCell.cs +++ b/src/BlazorDatasheet/Render/VisualCell.cs @@ -30,8 +30,11 @@ public VisualCell(int row, int col, Sheet sheet) var cellValue = sheet.Cells.GetCellValue(row, col); Value = cellValue.Data; + if (cellValue.ValueType == CellValueType.Number && format.NumberFormat != null) FormattedString = (cellValue.GetValue()).ToString(format.NumberFormat); + else if (cellValue.ValueType == CellValueType.Date && format.NumberFormat != null) + FormattedString = (cellValue.GetValue()).ToString(format.NumberFormat); else FormattedString = Value?.ToString() ?? string.Empty; From fd455adcc0ad34886e103afcefb500f7b7005fa9 Mon Sep 17 00:00:00 2001 From: anmcgrath Date: Sat, 22 Jun 2024 18:44:53 +1000 Subject: [PATCH 2/2] Fix date time editor --- .../DateTimeEditorComponent.razor | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/BlazorDatasheet/Edit/DefaultComponents/DateTimeEditorComponent.razor b/src/BlazorDatasheet/Edit/DefaultComponents/DateTimeEditorComponent.razor index 7791c220..6b2ad381 100644 --- a/src/BlazorDatasheet/Edit/DefaultComponents/DateTimeEditorComponent.razor +++ b/src/BlazorDatasheet/Edit/DefaultComponents/DateTimeEditorComponent.razor @@ -2,6 +2,7 @@ @using BlazorDatasheet.Core.Interfaces @using BlazorDatasheet.Core.Data @using BlazorDatasheet.Core.Edit +@using BlazorDatasheet.Formula.Core @inherits BaseEditor