)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to modify the cell style while importing the worksheet?

Platform: WPF |
Control: SfSpreadsheet |
Published Date: October 31, 2019 |
Last Revised Date: October 31, 2019

In Spreadsheet control, you can modify the cell style of particular cell or entire sheet while importing the Excel workbook. CellStyle includes font settings, alignment settings, border settings and fill color settings, etc.

For example, you can modify the cell style for the entire worksheet while importing the workbook by modifying the required properties of CellStyle of the UsedRange in WorkBookLoaded event of Spreadsheet control as illustrated in the following code example.

 

C#

spreadSheetControl.WorkbookLoaded += SpreadSheetControl_WorkbookLoaded; ;
 
//To change the cellstyle while importing the sheet.
private void SpreadSheetControl_WorkbookLoaded(object sender, WorkbookLoadedEventArgs args)
{
    foreach (IWorksheet sheet in args.Workbook.Worksheets)
    {
        if (sheet.UsedRange.LastRow > 0 && sheet.UsedRange.LastColumn > 0)
        {
            var cellStyle = sheet.UsedRange.CellStyle;
            cellStyle.Font.FontName = "Arial Black";
            cellStyle.Font.Bold = true;
            cellStyle.Font.Color = ExcelKnownColors.Violet;
            cellStyle.Font.Size = 12;
            cellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft;
            cellStyle.Borders.LineStyle = ExcelLineStyle.Double;
        }
    }
}

 

Download CustomizeCellStyle demo from GitHub.

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon