Articles in this section
Category / Section

How to change font styles while importing an excel file to WinForms GridControl?

2 mins read

Importing excel to grid

By default, the font styles of the Excel Cells are imported from Excel to Grid, as it is. The font styles of the Excel Cells can be changed while importing them to Grid by handling the QueryImportExportCellInfo event. Using this event, the font style can be set, by using the Font.Facename property and other styles can also be changed when e.Action is set as GridConverterAction.Import.


private void importBtn_Click(object sender, EventArgs e)
   //Initializing the Excel engine.
   ExcelEngine engine = new ExcelEngine();
   //Opening the Excel file.
   IWorkbook book = engine.Excel.Workbooks.Open(@"..\..\Book1.xlsx");
   IWorksheet sheet = book.Worksheets[0];
   Syncfusion.GridExcelConverter.GridExcelConverterControl gecc = new Syncfusion.GridExcelConverter.GridExcelConverterControl();
   //Triggering the QueryImportExportCellInfo event.
   gecc.QueryImportExportCellInfo += new Syncfusion.GridExcelConverter.GridImportExportCellInfoEventHandler(gecc_QueryImportExportCellInfo);
   //Importing the grid.
   gecc.ExcelToGrid(sheet, this.gridControl1.Model);
//Handling the QueryImportExportCellInfo event.
void gecc_QueryImportExportCellInfo(object sender, Syncfusion.GridExcelConverter.GridImportExportCellInfoEventArgs e)
   //Changing the font style while Importing.
   if (e.Action == Syncfusion.GridExcelConverter.GridConverterAction.Import)
      //Changing Grid cell's font styles while importing.
      e.GridCell.Font.Facename = "Verdana";
      e.GridCell.CellValue = "Font Style in Verdana";
      e.GridCell.Font.Size = 7.0f;
      e.Handled = true;


Private Sub importBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles importBtn.Click
   'Initializing the Excel engine.
   Dim engine As New ExcelEngine()
   'Opening the Excel file.
   Dim book As IWorkbook = engine.Excel.Workbooks.Open("..\..\Book1.xlsx")
   Dim sheet As IWorksheet = book.Worksheets(0)
   Dim gecc As New Syncfusion.GridExcelConverter.GridExcelConverterControl()
   'Triggering the QueryImportExportCellInfo event.
   AddHandler gecc.QueryImportExportCellInfo, AddressOf gecc_QueryImportExportCellInfo
   'Importing the grid.
   gecc.ExcelToGrid(sheet, Me.gridControl1.Model)
End Sub
'Handling the QueryImportExportCellInfo event.
Private Sub gecc_QueryImportExportCellInfo(ByVal sender As Object, ByVal e As Syncfusion.GridExcelConverter.GridImportExportCellInfoEventArgs)
   ‘Changing the font style while Importing.
   If (e.Action = Syncfusion.GridExcelConverter.GridConverterAction.Import) Then
     'Changing Grid cell's font styles while importing.
     e.GridCell.Font.Facename = "Verdana"
     e.GridCell.CellValue = "Font Style in Verdana"
     e.GridCell.Font.Size = 7!
     e.Handled = True 
   End If
End Sub 


Font type in excel

Figure 1: Font type in Excel


Font type in grid after importing from excel sheet

Figure 2: Font type in Grid after importing the above Excel sheet


C#: Changing_Font_Style_while_importing_CS

VB: Changing_Font_Style_while_importing_VB

Reference link:

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment