How to set all cells to plain text format?

Currently, I can only use the code below to set the NumberFormat for a specified Range, but I want any newly added rows and columns to have this format, including automatically added rows and columns when moving to the bottom or end using arrow keys.




2 Replies

CR crosslife November 1, 2024 10:57 AM UTC

Code for test1 button in the video


private void ButtonBase_OnClick(object sender, RoutedEventArgs e)

        {

            var worksheet = spreadsheet.ActiveSheet;

            worksheet.UsedRange.NumberFormat = "@";

        }


Attachment: 20241101185636_WindowShot_6e7d31af.zip


SP Sreemon Premkumar Muthukrishnan Syncfusion Team November 4, 2024 01:37 PM UTC

Hi crosslife,


To apply the NumberFormat to all newly added cells, including automatically added rows and columns when navigating to the bottom or end using arrow keys, you can set the NumberFormat to text within the QueryRange event. Please see the code snippet below:

private void Spreadsheet_WorkbookLoaded(object sender, Syncfusion.UI.Xaml.Spreadsheet.Helpers.WorkbookLoadedEventArgs args)

{

    spreadsheet.ActiveGrid.QueryRange += ActiveGrid_QueryRange;

}

 private void ActiveGrid_QueryRange(object sender, Syncfusion.UI.Xaml.Spreadsheet.Helpers.SpreadsheetQueryRangeEventArgs e)

 {

     if(e.CellType != "Header" && e.ExcelRange.NumberFormat != "@")

         e.ExcelRange.NumberFormat = "@";

 }


We have prepared the sample based on your requirement, please find the sample with the video reference in the attachment.


Regards,
Sreemon Premkumar M.


Attachment: WPF_Spreadsheet_Demo_ce6a9410.zip

Loader.
Up arrow icon