Skip to content

Commit 61aadad

Browse files
authored
Merge pull request #1727 from syncfusion-content/990137-ExcelToCsvUG
990137-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents f334d33 + ee4e810 commit 61aadad

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@ 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.xlsx"), FileMode.Open, FileAccess.Read);
31-
IWorkbook workbook = application.Workbooks.Open(inputStream);
30+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
3231

33-
//Saving the workbook as streams
34-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.csv"), FileMode.Create, FileAccess.ReadWrite);
35-
workbook.SaveAs(outputStream, ",");
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
32+
//Saving the workbook
33+
workbook.SaveAs(Path.GetFullPath("Output/Sample.csv"), ",");
4034
}
4135
{% endhighlight %}
4236

@@ -83,16 +77,14 @@ using (ExcelEngine excelEngine = new ExcelEngine())
8377
application.MaximumRowsForCsv = 3000000;
8478
application.MaximumColumnsForCsv = 20000;
8579

86-
FileStream inputStream = new FileStream("Sample.csv", FileMode.Open, FileAccess.Read);
87-
IWorkbook workbook = application.Workbooks.Open(inputStream);
80+
IWorkbook workbook = application.Workbooks.Open("Sample.csv");
8881
IWorksheet sheet = workbook.Worksheets[0];
8982

9083
sheet.Range[2000000, 1].Text = "Syncfusion";
9184
sheet.Range[20, 18000].Text = "Syncfusion";
9285

93-
//Saving the workbook as stream
94-
FileStream outputStream = new FileStream("Output.csv", FileMode.Create, FileAccess.ReadWrite);
95-
workbook.SaveAs(outputStream,",");
86+
//Saving the workbook
87+
workbook.SaveAs("Output.csv",",");
9688
}
9789
{% endhighlight %}
9890

@@ -149,12 +141,10 @@ using (ExcelEngine excelEngine = new ExcelEngine())
149141
IApplication application = excelEngine.Excel;
150142
application.DefaultVersion = ExcelVersion.Xlsx;
151143

152-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
153-
IWorkbook workbook = application.Workbooks.Open(inputStream);
144+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
154145

155146
//Save the workbook in CSV format with tab(\t) as delimiter
156-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.tsv"), FileMode.Create, FileAccess.ReadWrite);
157-
workbook.SaveAs(outputStream, "\t");
147+
workbook.SaveAs(Path.GetFullPath("Output/Output.tsv"), "\t");
158148
}
159149
{% endhighlight %}
160150

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@ 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.xlsx"), FileMode.Open, FileAccess.Read);
31-
IWorkbook workbook = application.Workbooks.Open(inputStream);
30+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
3231

33-
//Saving the workbook as streams
34-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.csv"), FileMode.Create, FileAccess.ReadWrite);
35-
workbook.SaveAs(outputStream, ",");
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
32+
//Saving the workbook
33+
workbook.SaveAs(Path.GetFullPath("Output/Sample.csv"), ",");
4034
}
4135
{% endhighlight %}
4236

@@ -83,16 +77,14 @@ using (ExcelEngine excelEngine = new ExcelEngine())
8377
application.MaximumRowsForCsv = 3000000;
8478
application.MaximumColumnsForCsv = 20000;
8579

86-
FileStream inputStream = new FileStream("Sample.csv", FileMode.Open, FileAccess.Read);
87-
IWorkbook workbook = application.Workbooks.Open(inputStream);
80+
IWorkbook workbook = application.Workbooks.Open("Sample.csv");
8881
IWorksheet sheet = workbook.Worksheets[0];
8982

9083
sheet.Range[2000000, 1].Text = "Syncfusion";
9184
sheet.Range[20, 18000].Text = "Syncfusion";
9285

93-
//Saving the workbook as stream
94-
FileStream outputStream = new FileStream("Output.csv", FileMode.Create, FileAccess.ReadWrite);
95-
workbook.SaveAs(outputStream,",");
86+
//Saving the workbook
87+
workbook.SaveAs("Output.csv",",");
9688
}
9789
{% endhighlight %}
9890

@@ -149,12 +141,10 @@ using (ExcelEngine excelEngine = new ExcelEngine())
149141
IApplication application = excelEngine.Excel;
150142
application.DefaultVersion = ExcelVersion.Xlsx;
151143

152-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
153-
IWorkbook workbook = application.Workbooks.Open(inputStream);
144+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
154145

155146
//Save the workbook in CSV format with tab(\t) as delimiter
156-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.tsv"), FileMode.Create, FileAccess.ReadWrite);
157-
workbook.SaveAs(outputStream, "\t");
147+
workbook.SaveAs(Path.GetFullPath("Output/Output.tsv"), "\t");
158148
}
159149
{% endhighlight %}
160150

0 commit comments

Comments
 (0)