@@ -32,12 +32,8 @@ N> XlsIO supports importing of data from data table to worksheet in Windows Form
3232
3333 #region Save
3434 //Saving the workbook
35- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataTable.xlsx"), FileMode.Create, FileAccess.Write);
36- workbook.SaveAs(outputStream);
35+ workbook.SaveAs(Path.GetFullPath("Output/ImportDataTable.xlsx"));
3736 #endregion
38-
39- //Dispose streams
40- outputStream.Dispose();
4137}
4238{% endhighlight %}
4339
@@ -104,12 +100,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
104100
105101 #region Save
106102 //Saving the workbook
107- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataColumn.xlsx"), FileMode.Create, FileAccess.Write);
108- workbook.SaveAs(outputStream);
103+ workbook.SaveAs(Path.GetFullPath("Output/ImportDataColumn.xlsx"));
109104 #endregion
110-
111- //Dispose streams
112- outputStream.Dispose();
113105}
114106{% endhighlight %}
115107
@@ -176,12 +168,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
176168
177169 #region Save
178170 //Saving the workbook
179- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataView.xlsx"), FileMode.Create, FileAccess.Write);
180- workbook.SaveAs(outputStream);
171+ workbook.SaveAs(Path.GetFullPath("Output/ImportDataView.xlsx"));
181172 #endregion
182-
183- //Dispose streams
184- outputStream.Dispose();
185173}
186174{% endhighlight %}
187175
@@ -242,12 +230,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
242230
243231 #region Save
244232 //Saving the workbook
245- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportCollectionObjects.xlsx"), FileMode.Create, FileAccess.Write);
246- workbook.SaveAs(outputStream);
233+ workbook.SaveAs(Path.GetFullPath("Output/ImportCollectionObjects.xlsx"));
247234 #endregion
248-
249- //Dispose streams
250- outputStream.Dispose();
251235}
252236{% endhighlight %}
253237
@@ -444,12 +428,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
444428
445429 #region Save
446430 //Saving the workbook
447- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataOptions.xlsx"), FileMode.Create, FileAccess.Write);
448- workbook.SaveAs(outputStream);
431+ workbook.SaveAs(Path.GetFullPath("Output/ImportDataOptions.xlsx"));
449432 #endregion
450-
451- //Dispose streams
452- outputStream.Dispose();
453433}
454434{% endhighlight %}
455435
@@ -690,21 +670,16 @@ namespace Layout_Options
690670
691671 #region Save
692672 //Saving the workbook
693- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write);
694- workbook.SaveAs(outputStream);
673+ workbook.SaveAs(Path.GetFullPath("Output/ImportData.xlsx"));
695674 #endregion
696-
697- //Dispose streams
698- outputStream.Dispose();
699675 }
700676 //Helper method to load data from XML file and add them in collections.
701677 private static IList<Brand> GetVehicleDetails()
702678 {
703679 XmlSerializer deserializer = new XmlSerializer(typeof(BrandObjects));
704680
705681 //Read data from XML file.
706- FileStream stream = new FileStream(Path.GetFullPath(@"Data/ExportData.xml"), FileMode.Open, FileAccess.Read);
707- TextReader textReader = new StreamReader(stream);
682+ TextReader textReader = new StreamReader(Path.GetFullPath(@"Data/ExportData.xml"));
708683 BrandObjects brands = (BrandObjects)deserializer.Deserialize(textReader);
709684
710685 //Initialize parent collection to add data from XML file.
@@ -1370,21 +1345,16 @@ namespace Grouping_Options
13701345
13711346 #region Save
13721347 //Saving the workbook
1373- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write);
1374- workbook.SaveAs(outputStream);
1348+ workbook.SaveAs(Path.GetFullPath("Output/ImportData.xlsx"));
13751349 #endregion
1376-
1377- //Dispose streams
1378- outputStream.Dispose();
13791350 }
13801351 //Helper method to load data from XML file and add them in collections.
13811352 private static IList<Brand> GetVehicleDetails()
13821353 {
13831354 XmlSerializer deserializer = new XmlSerializer(typeof(BrandObjects));
13841355
1385- //Read data from XML file.
1386- FileStream stream = new FileStream(Path.GetFullPath(@"Data/ExportData.xml"), FileMode.Open, FileAccess.Read);
1387- TextReader textReader = new StreamReader(stream);
1356+ //Read data from XML file.
1357+ TextReader textReader = new StreamReader(Path.GetFullPath(@"Data/ExportData.xml"));
13881358 BrandObjects brands = (BrandObjects)deserializer.Deserialize(textReader);
13891359
13901360 //Initialize parent collection to add data from XML file.
@@ -1967,12 +1937,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
19671937
19681938 #region Save
19691939 //Saving the workbook
1970- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write);
1971- workbook.SaveAs(outputStream);
1940+ workbook.SaveAs(Path.GetFullPath("Output/ImportData.xlsx"));
19721941 #endregion
1973-
1974- //Dispose streams
1975- outputStream.Dispose();
19761942}
19771943{% endhighlight %}
19781944
@@ -2206,12 +2172,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
22062172
22072173 #region Save
22082174 //Saving the workbook
2209- FileStream outputStream = new FileStream(Path.GetFullPath("Output/ArrayToWorksheet.xlsx"), FileMode.Create, FileAccess.Write);
2210- workbook.SaveAs(outputStream);
2175+ workbook.SaveAs(Path.GetFullPath("Output/ArrayToWorksheet.xlsx"));
22112176 #endregion
2212-
2213- //Dispose streams
2214- outputStream.Dispose();
22152177}
22162178{% endhighlight %}
22172179
@@ -2440,18 +2402,12 @@ namespace ImportHtml
24402402 IWorksheet worksheet = workbook.Worksheets[ 0] ;
24412403
24422404 //Imports HTML table into the worksheet from first row and first column
2443- FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.html"), FileMode.Open, FileAccess.ReadWrite);
2444- worksheet.ImportHtmlTable(inputStream, 1, 1);
2405+ worksheet.ImportHtmlTable(Path.GetFullPath(@"Data/InputTemplate.html"), 1, 1);
24452406
24462407 #region Save
24472408 //Saving the workbook
2448- FileStream outputStream = new FileStream(Path.GetFullPath("Output/HTMLTabletoWorksheet.xlsx"), FileMode.Create, FileAccess.Write);
2449- workbook.SaveAs(outputStream);
2409+ workbook.SaveAs(Path.GetFullPath("Output/HTMLTabletoWorksheet.xlsx"));
24502410 #endregion
2451-
2452- //Dispose streams
2453- outputStream.Dispose();
2454- inputStream.Dispose();
24552411 }
24562412 }
24572413 }
@@ -2556,13 +2512,11 @@ using (ExcelEngine excelEngine = new ExcelEngine())
25562512 FileStream inputStream = new FileStream("../../../Data/XmlFile.xml", FileMode.Open, FileAccess.Read);
25572513 worksheet.ImportXml(inputStream, 1, 6);
25582514
2559- //Saving the workbook as stream
2560- FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
2561- workbook.SaveAs(outputStream);
2515+ //Saving the workbook
2516+ workbook.SaveAs("Output.xlsx");
25622517
25632518 //Dispose stream
25642519 inputStream.Dispose();
2565- outputStream.Dispose();
25662520}
25672521{% endhighlight %}
25682522
@@ -2617,13 +2571,11 @@ using (ExcelEngine excelEngine = new ExcelEngine())
26172571 FileStream inputStream = new FileStream("../../../Data/XmlFile.xml", FileMode.Open, FileAccess.Read);
26182572 workbook.XmlMaps.Add(inputStream);
26192573
2620- //Saving the workbook as stream
2621- FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
2622- workbook.SaveAs(outputStream);
2574+ //Saving the workbook
2575+ workbook.SaveAs("Output.xlsx");
26232576
26242577 //Dispose stream
26252578 inputStream.Dispose();
2626- outputStream.Dispose();
26272579}
26282580{% endhighlight %}
26292581
0 commit comments