How to save the WinForms GridControl with changed values to an excel sheet?
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 the spreadsheet.
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");
}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 SubSamples:
Reference Link: Exporting