Articles in this section
Category / Section

How to save the WinForms GridControl with changed values to an excel sheet?

1 min read

Save the grid

In order to save the grid control with changed values, we have to save the Workbook after exporting the grid to excel. IWorkBook.Save() method can be used to save the changed values in spread sheet.

C#

private void btnExport_Click(object sender, EventArgs e)
{
   ExcelEngine engine = new ExcelEngine();
   IApplication app = engine.Excel.Application;
   app.DefaultVersion = ExcelVersion.Excel2010;
   IWorkbook workBook = app.Workbooks.Create();
   workBook = engine.Excel.Workbooks.Open(@"..\..\Book1.xlsx");
   IWorksheet sheet = workBook.Worksheets[0];
   control.GridToExcel(this.gridControl1, sheet, ConverterOptions.Default);
   //Save the workbook.
   workBook.Save();
   Process.Start(@"..\..\Book1.xlsx");
}

 

VB

Private Sub btnExport_Click(ByVal sender As Object, ByVal e As EventArgs)
   Dim engine As New ExcelEngine()
   Dim app As IApplication = engine.Excel.Application
   app.DefaultVersion = ExcelVersion.Excel2010
   Dim workBook As IWorkbook = app.Workbooks.Create()
   workBook = engine.Excel.Workbooks.Open("..\..\Book1.xlsx")
   Dim sheet As IWorksheet = workBook.Worksheets(0)
   control.GridToExcel(Me.gridControl1, sheet, ConverterOptions.Default)
   'Save the workbook.
   workBook.Save()
   Process.Start("..\..\Book1.xlsx")
End Sub

 

Samples:

C#: SaveChangesToExcel_CS

VB: SaveChangesToExcel_VB

Reference link: https://help.syncfusion.com/windowsforms/grid-control/exporting#excel-export

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