diff --git a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Filtering.md b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Filtering.md index e1c020ed7..d4385423d 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Filtering.md +++ b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Filtering.md @@ -27,8 +27,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Filter @@ -48,13 +47,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Filter.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Filter.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -120,8 +114,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Custom Filter @@ -142,13 +135,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CustomFilter.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/CustomFilter.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -218,8 +206,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Combination Filter @@ -241,13 +228,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CombinationFilter.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/CombinationFilter.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -315,8 +297,7 @@ The following code example illustrates how to apply Dynamic filter. { 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Dynamic Filter @@ -332,13 +313,8 @@ The following code example illustrates how to apply Dynamic filter. #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/DynamicFilter.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/DynamicFilter.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -398,8 +374,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Cell Color Filter @@ -415,13 +390,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CellColorFilter.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/CellColorFilter.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -479,8 +449,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Font Color Filter @@ -496,13 +465,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/FontColorFilter.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/FontColorFilter.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -562,8 +526,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Icon Filter @@ -579,13 +542,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/IconFilter.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/IconFilter.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -655,8 +613,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Advanced Filter @@ -670,13 +627,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/AdvancedFilter.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/AdvancedFilter.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -732,8 +684,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Accessing Filter @@ -781,8 +732,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) } #endregion - //Dispose streams - inputStream.Dispose(); + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -903,8 +853,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Access sort fields from AutoFilters @@ -931,13 +880,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) sorter.Sort(); #region Save - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} diff --git a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Find-and-Replace.md b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Find-and-Replace.md index 18817be70..ae817ba2d 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Find-and-Replace.md +++ b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Find-and-Replace.md @@ -28,8 +28,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Searches for the given string within the text of worksheet @@ -86,10 +85,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) cell.CellStyle.Color = Syncfusion.Drawing.Color.FromArgb(255, 0, 128, 128); } - //Saving the workbook as stream - FileStream stream = new FileStream(Path.GetFullPath(@"Output/Find.xlsx"), FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAs(stream); - stream.Dispose(); + //Saving the workbook + workbook.SaveAs(Path.GetFullPath(@"Output/Find.xlsx")); } {% endhighlight %} @@ -177,8 +174,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Replaces the given string with another string @@ -196,11 +192,9 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Replaces the given string with Array worksheet.Replace("Central", new string[] { "Central", "East" }, true); - //Saving the workbook as stream - FileStream stream = new FileStream(Path.GetFullPath("Output/Replace.xlsx"), FileMode.Create, FileAccess.ReadWrite); + //Saving the workbook workbook.Version = ExcelVersion.Xlsx; - workbook.SaveAs(stream); - stream.Dispose(); + workbook.SaveAs(Path.GetFullPath("Output/Replace.xlsx")); } {% endhighlight %} diff --git a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Hyperlink.md b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Hyperlink.md index 3c805ca10..9f9000037 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Hyperlink.md +++ b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Hyperlink.md @@ -214,12 +214,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Hyperlinks.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/Hyperlinks.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -325,8 +321,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Modify Hyperlink @@ -337,13 +332,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ModifyHyperlink.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ModifyHyperlink.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -391,8 +381,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Remove Hyperlink @@ -402,13 +391,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveHyperlink.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/RemoveHyperlink.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -484,12 +468,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ShapeHyperlink.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ShapeHyperlink.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -563,8 +543,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Modify Shape Hyperlink @@ -579,13 +558,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ModifyShapeHyperlink.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ModifyShapeHyperlink.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -641,8 +615,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath("Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Removing hyperlink from sheet with Index @@ -650,13 +623,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveShapeHyperlink.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/RemoveShapeHyperlink.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} diff --git a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/List-of-APIs-under-IRange.md b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/List-of-APIs-under-IRange.md index be6671818..5644322aa 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/List-of-APIs-under-IRange.md +++ b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/List-of-APIs-under-IRange.md @@ -36,17 +36,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Local R1C1 Address string address_R1C1_Local = worksheet.Range[3, 4].AddressR1C1Local; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -125,17 +115,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) worksheet.Range["B4"].Boolean = false; bool b4 = worksheet.Range["B4"].Boolean; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -206,17 +186,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick; borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -291,17 +261,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Set built in style worksheet.Range["C2"].BuiltInStyle = BuiltInStyles.Accent3; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -372,17 +332,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Disable sheet calculations worksheet.DisableSheetCalculations(); - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -464,17 +414,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) cell.Text = cell.AddressLocal; } - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -544,17 +484,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Get the cell style name string cellStyleName = worksheet.Range["C2"].CellStyleName; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -622,17 +552,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Get first column in the range int firstColumn = worksheet.Range["E1:R3"].Column; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -688,17 +608,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) column.Text = column.AddressLocal; } - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -767,17 +677,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Number of cells int count = worksheet.Range["A1:E5"].Count; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -831,17 +731,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Last cell in the range IRange lastCell = worksheet.Range["A1:E5"].End; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -891,17 +781,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Last cell in the entire column IRange lastCell = worksheet.Range["A1"].EntireColumn.End; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -953,17 +833,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Last cell in the entire row IRange lastCell = worksheet.Range["A1"].EntireRow.End; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1023,17 +893,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Get the claculated value of formula string value = worksheet.Range["C1"].CalculatedValue; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1124,17 +984,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool value_C1 = worksheet.Range["C1"].FormulaBoolValue; bool value_E1 = worksheet.Range["E1"].FormulaBoolValue; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1225,17 +1075,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool hasBoolean_A2 = worksheet.Range["A2"].HasBoolean; bool hasBoolean_A3 = worksheet.Range["A3"].HasBoolean; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1308,17 +1148,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool validation_A1 = worksheet.Range["A1"].HasDataValidation; bool validation_A3 = worksheet.Range["A3"].HasDataValidation; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1397,17 +1227,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool dateTime_B3 = worksheet.Range["B3"].HasDateTime; bool dateTime_B4 = worksheet.Range["B4"].HasDateTime; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1493,17 +1313,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool extFormula_C1 = worksheet.Range["C1"].HasExternalFormula; bool extFormula_C2 = worksheet.Range["C2"].HasExternalFormula; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1576,17 +1386,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool formula_A2 = worksheet.Range["A2"].HasFormula; bool formula_C2 = worksheet.Range["C2"].HasFormula; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1658,17 +1458,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool formulaArray = worksheet.Range["A1"].HasFormulaArray; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1746,17 +1536,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Has formula boolean value bool hasValue_E1 = worksheet.Range["E1"].HasFormulaBoolValue; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1835,17 +1615,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool hasNumber_A1 = worksheet.Range["A1"].HasNumber; bool hasNumber_A2 = worksheet.Range["A2"].HasNumber; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} @@ -1925,17 +1695,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) bool hasRichText = worksheet.Range["A1"].HasRichText; bool hasNumber_A2 = worksheet.Range["A2"].HasNumber; - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - workbook.SaveAs(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel"); - fileStreamResult.FileDownloadName = "Output.xlsx"; - return fileStreamResult; + workbook.SaveAs("Output.xlsx"); } {% endhighlight %} diff --git a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Sorting.md b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Sorting.md index 2981d15f8..a9d7cf173 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Sorting.md +++ b/Document-Processing/Excel/Excel-Library/NET/Cells-Manipulation/Sorting.md @@ -26,8 +26,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Sort On Cell Values @@ -61,13 +60,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/SortOnValues.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/SortOnValues.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -161,8 +155,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath("Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Sort on Font Color @@ -199,13 +192,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/SortOnFontColor.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/SortOnFontColor.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -287,8 +275,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Sort on Cell Color @@ -325,13 +312,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/SortOnCellColor.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/SortOnCellColor.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} diff --git a/Document-Processing/Excel/Excel-Library/NET/Import-Export/Export-from-Excel.md b/Document-Processing/Excel/Excel-Library/NET/Import-Export/Export-from-Excel.md index 481b21aa6..9d0bfec88 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Import-Export/Export-from-Excel.md +++ b/Document-Processing/Excel/Excel-Library/NET/Import-Export/Export-from-Excel.md @@ -22,15 +22,11 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Read data from the worksheet and Export to the DataTable - DataTable customersTable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames | ExcelExportDataTableOptions.ComputedFormulaValues); - - //Dispose streams - inputStream.Dispose(); + DataTable customersTable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames | ExcelExportDataTableOptions.ComputedFormulaValues); } //XlsIO supports binding of exported data table to data grid in Windows Forms, WPF, ASP.NET and ASP.NET MVC platforms alone. @@ -96,8 +92,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2016; - FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); IWorksheet worksheet = workbook.Worksheets[0]; //Event to choose an action while exporting data from Excel to data table. @@ -106,10 +101,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Read data from the worksheet and Export to the DataTable DataTable customersTable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames); - //Saving the workbook as stream - FileStream stream = new FileStream("ExportToDT.xlsx", FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAs(stream); - stream.Dispose(); + //Saving the workbook + workbook.SaveAs("ExportToDT.xlsx"); } //XlsIO supports binding of exported data table to data grid in Windows Forms, WPF, ASP.NET and ASP.NET MVC platforms alone @@ -223,15 +216,11 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Export worksheet data into Collection Objects List collectionObjects = worksheet.ExportData(1, 1, 10, 3); - - //Dispose streams - inputStream.Dispose(); } {% endhighlight %} @@ -369,8 +358,7 @@ namespace Worksheet_to_Nested_Class { 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Map column headers in worksheet with class properties. @@ -383,9 +371,6 @@ namespace Worksheet_to_Nested_Class //Export worksheet data into nested class Objects. List nestedClassObjects = worksheet.ExportData(1, 1, 10, 5, mappingProperties); - - //Dispose streams - inputStream.Dispose(); } } } diff --git a/Document-Processing/Excel/Excel-Library/NET/Import-Export/Import-to-Excel.md b/Document-Processing/Excel/Excel-Library/NET/Import-Export/Import-to-Excel.md index 5df36bd0d..8348f801d 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Import-Export/Import-to-Excel.md +++ b/Document-Processing/Excel/Excel-Library/NET/Import-Export/Import-to-Excel.md @@ -32,12 +32,8 @@ N> XlsIO supports importing of data from data table to worksheet in Windows Form #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataTable.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ImportDataTable.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -104,12 +100,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataColumn.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ImportDataColumn.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -176,12 +168,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataView.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ImportDataView.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -242,12 +230,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportCollectionObjects.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ImportCollectionObjects.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -444,12 +428,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportDataOptions.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ImportDataOptions.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -690,12 +670,8 @@ namespace Layout_Options #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ImportData.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } //Helper method to load data from XML file and add them in collections. private static IList GetVehicleDetails() @@ -703,8 +679,7 @@ namespace Layout_Options XmlSerializer deserializer = new XmlSerializer(typeof(BrandObjects)); //Read data from XML file. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/ExportData.xml"), FileMode.Open, FileAccess.Read); - TextReader textReader = new StreamReader(stream); + TextReader textReader = new StreamReader(Path.GetFullPath(@"Data/ExportData.xml")); BrandObjects brands = (BrandObjects)deserializer.Deserialize(textReader); //Initialize parent collection to add data from XML file. @@ -1370,21 +1345,16 @@ namespace Grouping_Options #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ImportData.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } //Helper method to load data from XML file and add them in collections. private static IList GetVehicleDetails() { XmlSerializer deserializer = new XmlSerializer(typeof(BrandObjects)); - //Read data from XML file. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/ExportData.xml"), FileMode.Open, FileAccess.Read); - TextReader textReader = new StreamReader(stream); + //Read data from XML file. + TextReader textReader = new StreamReader(Path.GetFullPath(@"Data/ExportData.xml")); BrandObjects brands = (BrandObjects)deserializer.Deserialize(textReader); //Initialize parent collection to add data from XML file. @@ -1967,12 +1937,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImportData.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ImportData.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -2206,12 +2172,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ArrayToWorksheet.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ArrayToWorksheet.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -2440,18 +2402,12 @@ namespace ImportHtml IWorksheet worksheet = workbook.Worksheets[0]; //Imports HTML table into the worksheet from first row and first column - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.html"), FileMode.Open, FileAccess.ReadWrite); - worksheet.ImportHtmlTable(inputStream, 1, 1); + worksheet.ImportHtmlTable(Path.GetFullPath(@"Data/InputTemplate.html"), 1, 1); #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/HTMLTabletoWorksheet.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/HTMLTabletoWorksheet.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } } } @@ -2556,13 +2512,11 @@ using (ExcelEngine excelEngine = new ExcelEngine()) FileStream inputStream = new FileStream("../../../Data/XmlFile.xml", FileMode.Open, FileAccess.Read); worksheet.ImportXml(inputStream, 1, 6); - //Saving the workbook as stream - FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAs(outputStream); + //Saving the workbook + workbook.SaveAs("Output.xlsx"); //Dispose stream inputStream.Dispose(); - outputStream.Dispose(); } {% endhighlight %} @@ -2617,13 +2571,11 @@ using (ExcelEngine excelEngine = new ExcelEngine()) FileStream inputStream = new FileStream("../../../Data/XmlFile.xml", FileMode.Open, FileAccess.Read); workbook.XmlMaps.Add(inputStream); - //Saving the workbook as stream - FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAs(outputStream); + //Saving the workbook + workbook.SaveAs("Output.xlsx"); //Dispose stream inputStream.Dispose(); - outputStream.Dispose(); } {% endhighlight %} diff --git a/Document-Processing/Excel/Excel-Library/NET/Worksheet-Cells-Manipulation.md b/Document-Processing/Excel/Excel-Library/NET/Worksheet-Cells-Manipulation.md index ab4acea38..adeb28de7 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Worksheet-Cells-Manipulation.md +++ b/Document-Processing/Excel/Excel-Library/NET/Worksheet-Cells-Manipulation.md @@ -49,12 +49,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/AccessCellorRange.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/AccessCellorRange.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -160,12 +156,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/AccessRelativeRange.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/AccessRelativeRange.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -256,12 +248,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/DiscontinuousRange.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/DiscontinuousRange.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -342,12 +330,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/MigrantRange.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/MigrantRange.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -418,8 +402,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Precedents in Worksheet @@ -517,9 +500,6 @@ using (ExcelEngine excelEngine = new ExcelEngine()) } Console.WriteLine(); #endregion - - //Dispose streams - inputStream.Dispose(); } {% endhighlight %} @@ -569,8 +549,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Precedents in Worksheet @@ -668,9 +647,6 @@ using (ExcelEngine excelEngine = new ExcelEngine()) } Console.WriteLine(); #endregion - - //Dispose streams - inputStream.Dispose(); } {% endhighlight %} @@ -724,8 +700,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Precedents in Worksheet @@ -823,9 +798,6 @@ using (ExcelEngine excelEngine = new ExcelEngine()) } Console.WriteLine(); #endregion - - //Dispose streams - inputStream.Dispose(); } {% endhighlight %} @@ -875,8 +847,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Precedents in Worksheet @@ -974,9 +945,6 @@ using (ExcelEngine excelEngine = new ExcelEngine()) } Console.WriteLine(); #endregion - - //Dispose streams - inputStream.Dispose(); } {% endhighlight %} @@ -1055,8 +1023,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Clear Content @@ -1066,13 +1033,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ClearContent.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ClearContent.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} diff --git a/Document-Processing/Excel/Excel-Library/NET/Worksheet-Rows-and-Columns-Manipulation.md b/Document-Processing/Excel/Excel-Library/NET/Worksheet-Rows-and-Columns-Manipulation.md index d02a0f2f6..38c4de310 100644 --- a/Document-Processing/Excel/Excel-Library/NET/Worksheet-Rows-and-Columns-Manipulation.md +++ b/Document-Processing/Excel/Excel-Library/NET/Worksheet-Rows-and-Columns-Manipulation.md @@ -20,8 +20,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Insert Rows @@ -42,13 +41,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/InsertRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/InsertRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -102,8 +96,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Delete Rows @@ -124,13 +117,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/DeleteRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/DeleteRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -196,8 +184,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Move Rows @@ -212,13 +199,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/MoveRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/MoveRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -271,8 +253,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Hide Row and Column @@ -283,13 +264,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/HideRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -360,12 +336,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/HideRange.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/HideRange.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -441,8 +413,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Resize rows @@ -463,13 +434,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ResizeRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ResizeRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -517,8 +483,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Resize rows @@ -539,13 +504,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ResizeRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ResizeRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -602,8 +562,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Autofit Rows @@ -624,13 +583,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/AutofitRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/AutofitRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -718,8 +672,7 @@ 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); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Autofit Rows @@ -740,13 +693,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/AutofitRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/AutofitRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -814,8 +762,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate - ToGroup.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate - ToGroup.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Group Rows @@ -832,13 +779,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/GroupRowsandColumns.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/GroupRowsandColumns.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -922,8 +864,7 @@ namespace Expand_or_Collapse_Groups { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate - To Expand.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate - To Expand.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Expand Groups @@ -938,13 +879,8 @@ namespace Expand_or_Collapse_Groups #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExpandGroups.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/ExpandGroups.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } } public void CollapseGroups() @@ -953,8 +889,7 @@ namespace Expand_or_Collapse_Groups { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate - To Collapse.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate - To Collapse.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region Collapse Groups @@ -969,13 +904,8 @@ namespace Expand_or_Collapse_Groups #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CollapseGroups.xlsx"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream); + workbook.SaveAs(Path.GetFullPath("Output/CollapseGroups.xlsx")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } } } @@ -1034,8 +964,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream fileStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); IWorksheet worksheet = workbook.Worksheets[0]; //Set the range for subtotaling @@ -1044,10 +973,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Perform subtotals for the range with every change in first column and subtotals to be included for specified list of columns range.SubTotal(0, ConsolidationFunction.Sum, new int[] { 2, 3, 4 }); - //Saving the workbook as stream - FileStream stream = new FileStream("Book1.xlsx", FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAs(stream); - stream.Dispose(); + //Saving the workbook + workbook.SaveAs("Book1.xlsx"); } {% endhighlight %}