From 0c052e08f3dc855597c6e813bc73371bd7cf5faf Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Mon, 27 Oct 2025 19:50:39 +0530 Subject: [PATCH] 988874-ModifyStreams-Working with Formulas --- .../NET/Working-with-Formulas.md | 89 ++++--------------- 1 file changed, 17 insertions(+), 72 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/Working-with-Formulas.md b/Document-Processing/Excel/Excel-Library/NET/Working-with-Formulas.md index 59cb65336..58e5472b1 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Working-with-Formulas.md +++ b/Document-Processing/Excel/Excel-Library/NET/Working-with-Formulas.md @@ -90,12 +90,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -163,12 +159,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -261,12 +253,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -344,12 +332,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } //Output @@ -469,12 +453,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -537,12 +517,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -615,12 +591,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/IncrementalFormula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/IncrementalFormula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -686,12 +658,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExternalFormula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ExternalFormula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -768,12 +736,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CalculatedColumn.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/CalculatedColumn.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -2098,10 +2062,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Use the function. The expected result is 30 sheet.Range["A3"].Formula = "AddInFunction(10,20)"; - //Saving the workbook as stream - FileStream stream = new FileStream("AddIn.xlsx", FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAs(stream); - stream.Dispose(); + //Saving the workbook + workbook.SaveAs(Path.GetFullPath("Output/AddIn.xlsx")); } {% endhighlight %} @@ -2251,12 +2213,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -2362,9 +2320,8 @@ Following code illustrates on how to ignore or set error indicators. using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; - application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet sheet = workbook.Worksheets[0]; //Sets warning if number is entered as text. @@ -2372,12 +2329,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/FormulaAuditing.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/FormulaAuditing.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -2455,12 +2408,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CalculationMode.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/CalculationMode.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -2551,12 +2500,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Iteration.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Iteration.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %}