Skip to content

Commit aaff81e

Browse files
authored
Merge pull request #1729 from syncfusion-content/990137-CsvToExcelUG
990137-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents 61aadad + 02cfafa commit aaff81e

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

Document-Processing/Excel/Conversions/CSV-to-Excel/NET/CSV-to-Excel-Conversion.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,13 @@ using (ExcelEngine excelEngine = new ExcelEngine())
2727
{
2828
IApplication application = excelEngine.Excel;
2929
application.DefaultVersion = ExcelVersion.Xlsx;
30-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.csv"), FileMode.Open, FileAccess.Read);
3130

3231
//Open the CSV file
33-
IWorkbook workbook = application.Workbooks.Open(inputStream, ",");
32+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.csv"), ",");
3433
IWorksheet worksheet = workbook.Worksheets[0];
3534

36-
//Saving the workbook as stream
37-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
38-
workbook.SaveAs(outputStream);
39-
40-
//Dispose streams
41-
outputStream.Dispose();
42-
inputStream.Dispose();
35+
//Saving the workbook
36+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
4337
}
4438
{% endhighlight %}
4539

@@ -85,16 +79,10 @@ using (ExcelEngine excelEngine = new ExcelEngine())
8579
application.DefaultVersion = ExcelVersion.Xlsx;
8680

8781
//Open the TSV file
88-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.tsv"), FileMode.Open, FileAccess.Read);
89-
IWorkbook workbook = application.Workbooks.Open(inputStream, "\t");
82+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.tsv"), "\t");
9083

9184
//Save the workbook
92-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.ReadWrite);
93-
workbook.SaveAs(outputStream);
94-
95-
//Dispose streams
96-
outputStream.Dispose();
97-
inputStream.Dispose();
85+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
9886
}
9987
{% endhighlight %}
10088

Document-Processing/Excel/Conversions/CSV-to-Excel/overview.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,13 @@ using (ExcelEngine excelEngine = new ExcelEngine())
2727
{
2828
IApplication application = excelEngine.Excel;
2929
application.DefaultVersion = ExcelVersion.Xlsx;
30-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.csv"), FileMode.Open, FileAccess.Read);
3130

3231
//Open the CSV file
33-
IWorkbook workbook = application.Workbooks.Open(inputStream, ",");
32+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.csv"), ",");
3433
IWorksheet worksheet = workbook.Worksheets[0];
3534

36-
//Saving the workbook as stream
37-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
38-
workbook.SaveAs(outputStream);
39-
40-
//Dispose streams
41-
outputStream.Dispose();
42-
inputStream.Dispose();
35+
//Saving the workbook
36+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
4337
}
4438
{% endhighlight %}
4539

@@ -85,16 +79,10 @@ using (ExcelEngine excelEngine = new ExcelEngine())
8579
application.DefaultVersion = ExcelVersion.Xlsx;
8680

8781
//Open the TSV file
88-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.tsv"), FileMode.Open, FileAccess.Read);
89-
IWorkbook workbook = application.Workbooks.Open(inputStream, "\t");
82+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.tsv"), "\t");
9083

9184
//Save the workbook
92-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.ReadWrite);
93-
workbook.SaveAs(outputStream);
94-
95-
//Dispose streams
96-
outputStream.Dispose();
97-
inputStream.Dispose();
85+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
9886
}
9987
{% endhighlight %}
10088

0 commit comments

Comments
 (0)