@@ -90,12 +90,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
9090
9191 #region Save
9292 //Saving the workbook
93- FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
94- workbook.SaveAs(outputStream);
93+ workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
9594 #endregion
96-
97- //Dispose streams
98- outputStream.Dispose();
9995}
10096{% endhighlight %}
10197
@@ -163,12 +159,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
163159
164160 #region Save
165161 //Saving the workbook
166- FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
167- workbook.SaveAs(outputStream);
162+ workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
168163 #endregion
169-
170- //Dispose streams
171- outputStream.Dispose();
172164}
173165{% endhighlight %}
174166
@@ -261,12 +253,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
261253
262254 #region Save
263255 //Saving the workbook
264- FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
265- workbook.SaveAs(outputStream);
256+ workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
266257 #endregion
267-
268- //Dispose streams
269- outputStream.Dispose();
270258}
271259{% endhighlight %}
272260
@@ -344,12 +332,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
344332
345333 #region Save
346334 //Saving the workbook
347- FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
348- workbook.SaveAs(outputStream);
335+ workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
349336 #endregion
350-
351- //Dispose streams
352- outputStream.Dispose();
353337}
354338//Output
355339
@@ -469,12 +453,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
469453
470454 #region Save
471455 //Saving the workbook
472- FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
473- workbook.SaveAs(outputStream);
456+ workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
474457 #endregion
475-
476- //Dispose streams
477- outputStream.Dispose();
478458}
479459{% endhighlight %}
480460
@@ -537,12 +517,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
537517
538518 #region Save
539519 //Saving the workbook
540- FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
541- workbook.SaveAs(outputStream);
520+ workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
542521 #endregion
543-
544- //Dispose streams
545- outputStream.Dispose();
546522}
547523{% endhighlight %}
548524
@@ -615,12 +591,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
615591
616592 #region Save
617593 //Saving the workbook
618- FileStream outputStream = new FileStream(Path.GetFullPath("Output/IncrementalFormula.xlsx"), FileMode.Create, FileAccess.Write);
619- workbook.SaveAs(outputStream);
594+ workbook.SaveAs(Path.GetFullPath("Output/IncrementalFormula.xlsx"));
620595 #endregion
621-
622- //Dispose streams
623- outputStream.Dispose();
624596}
625597{% endhighlight %}
626598
@@ -686,12 +658,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
686658
687659 #region Save
688660 //Saving the workbook
689- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExternalFormula.xlsx"), FileMode.Create, FileAccess.Write);
690- workbook.SaveAs(outputStream);
661+ workbook.SaveAs(Path.GetFullPath("Output/ExternalFormula.xlsx"));
691662 #endregion
692-
693- //Dispose streams
694- outputStream.Dispose();
695663}
696664{% endhighlight %}
697665
@@ -768,12 +736,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
768736
769737 #region Save
770738 //Saving the workbook
771- FileStream outputStream = new FileStream(Path.GetFullPath("Output/CalculatedColumn.xlsx"), FileMode.Create, FileAccess.Write);
772- workbook.SaveAs(outputStream);
739+ workbook.SaveAs(Path.GetFullPath("Output/CalculatedColumn.xlsx"));
773740 #endregion
774-
775- //Dispose streams
776- outputStream.Dispose();
777741}
778742{% endhighlight %}
779743
@@ -2098,10 +2062,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
20982062 //Use the function. The expected result is 30
20992063 sheet.Range[ "A3"] .Formula = "AddInFunction(10,20)";
21002064
2101- //Saving the workbook as stream
2102- FileStream stream = new FileStream("AddIn.xlsx", FileMode.Create, FileAccess.ReadWrite);
2103- workbook.SaveAs(stream);
2104- stream.Dispose();
2065+ //Saving the workbook
2066+ workbook.SaveAs(Path.GetFullPath("Output/AddIn.xlsx"));
21052067}
21062068{% endhighlight %}
21072069
@@ -2251,12 +2213,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
22512213
22522214 #region Save
22532215 //Saving the workbook
2254- FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
2255- workbook.SaveAs(outputStream);
2216+ workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
22562217 #endregion
2257-
2258- //Dispose streams
2259- outputStream.Dispose();
22602218}
22612219{% endhighlight %}
22622220
@@ -2362,22 +2320,17 @@ Following code illustrates on how to ignore or set error indicators.
23622320using (ExcelEngine excelEngine = new ExcelEngine())
23632321{
23642322 IApplication application = excelEngine.Excel;
2365- application.DefaultVersion = ExcelVersion.Xlsx;
2366- FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
2367- IWorkbook workbook = application.Workbooks.Open(inputStream);
2323+ application.DefaultVersion = ExcelVersion.Xlsx;
2324+ IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
23682325 IWorksheet sheet = workbook.Worksheets[ 0] ;
23692326
23702327 //Sets warning if number is entered as text.
23712328 sheet.Range["A2:D2"].IgnoreErrorOptions = ExcelIgnoreError.NumberAsText;
23722329
23732330 #region Save
23742331 //Saving the workbook
2375- FileStream outputStream = new FileStream(Path.GetFullPath("Output/FormulaAuditing.xlsx"), FileMode.Create, FileAccess.Write);
2376- workbook.SaveAs(outputStream);
2332+ workbook.SaveAs(Path.GetFullPath("Output/FormulaAuditing.xlsx"));
23772333 #endregion
2378-
2379- //Dispose streams
2380- outputStream.Dispose();
23812334}
23822335{% endhighlight %}
23832336
@@ -2455,12 +2408,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
24552408
24562409 #region Save
24572410 //Saving the workbook
2458- FileStream outputStream = new FileStream(Path.GetFullPath("Output/CalculationMode.xlsx"), FileMode.Create, FileAccess.Write);
2459- workbook.SaveAs(outputStream);
2411+ workbook.SaveAs(Path.GetFullPath("Output/CalculationMode.xlsx"));
24602412 #endregion
2461-
2462- //Dispose streams
2463- outputStream.Dispose();
24642413}
24652414{% endhighlight %}
24662415
@@ -2551,12 +2500,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
25512500
25522501 #region Save
25532502 //Saving the workbook
2554- FileStream outputStream = new FileStream(Path.GetFullPath("Output/Iteration.xlsx"), FileMode.Create, FileAccess.Write);
2555- workbook.SaveAs(outputStream);
2503+ workbook.SaveAs(Path.GetFullPath("Output/Iteration.xlsx"));
25562504 #endregion
2557-
2558- //Dispose streams
2559- outputStream.Dispose();
25602505}
25612506{% endhighlight %}
25622507
0 commit comments