How to save the edited changes in the same Excel document?
4 Nov 20252 minutes to read
The Save method is only supported on the framework platform.
The following code example illustrates how to save the edited changes in the same Excel document.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
//File path
string filepath = @"../../../Data/InputTemplate.xlsx";
//Load an Excel document
IWorkbook workbook = application.Workbooks.Open(filepath);
IWorksheet worksheet = workbook.Worksheets[0];
//Set text in the cell
worksheet["B1"].Text = "Text";
//Save the workbook to the same file
workbook.SaveAs(filepath);
}using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
//File path
string filepath = @"../../Data/InputTemplate.xlsx";
//Load an Excel document
IWorkbook workbook = application.Workbooks.Open(filepath);
IWorksheet worksheet = workbook.Worksheets[0];
//Set text in the cell
worksheet["B1"].Text = "Text";
//Save the workbook to the same file
workbook.Save();
}Using excelEngine As New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
'File path
Dim filepath As String = "../../Data/InputTemplate.xlsx"
'Load an Excel document
Dim workbook As IWorkbook = application.Workbooks.Open(filepath)
Dim worksheet As IWorksheet = workbook.Worksheets(0)
'Set text in the cell
worksheet("B1").Text = "Text"
'Save the workbook to the same file
workbook.Save()
End Using