Skip to content

Commit c388db2

Browse files
authored
Merge pull request #1710 from syncfusion-content/990137-FAQStreamChangesUG
990137-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents d7378e4 + ef6fd77 commit c388db2

File tree

58 files changed

+118
-376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+118
-376
lines changed

Document-Processing/Excel/Excel-Library/NET/faqs/How-to-retain-cell-values-after-removing-formulas-in-Excel.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
1818
{
1919
IApplication application = excelEngine.Excel;
2020
application.DefaultVersion = ExcelVersion.Xlsx;
21-
FileStream inputStream = new FileStream("InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
22-
IWorkbook workbook = application.Workbooks.Open(inputStream);
21+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
2322
IWorksheet worksheet = workbook.Worksheets[0];
2423

2524
//Enable sheet calculation
@@ -41,10 +40,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
4140
}
4241
}
4342

44-
//Saving the workbook as stream
45-
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
46-
workbook.SaveAs(outputStream);
47-
outputStream.Dispose();
43+
//Saving the workbook
44+
workbook.SaveAs("Output.xlsx");
4845
}
4946
{% endhighlight %}
5047

Document-Processing/Excel/Excel-Library/NET/faqs/does-xlsio-support-the-multiline-header-footer-support.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
3434
pageSetup.RightFooter = "Right Footer Line 1\nRight Footer Line 2";
3535

3636
//Save the excel file
37-
FileStream outputStream = new FileStream("Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
38-
workbook.SaveAs(outputStream);
37+
workbook.SaveAs("Output.xlsx");
3938
workbook.Close();
4039
excelEngine.Dispose();
4140
}

Document-Processing/Excel/Excel-Library/NET/faqs/how-does-excel-file-with-uninstalled-fonts-is-converted-to-pdf-image.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ The following code snippet shows how to use font substitution in Excel to PDF co
1919
using (ExcelEngine excelEngine = new ExcelEngine())
2020
{
2121
IApplication application = excelEngine.Excel;
22-
FileStream fileStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
23-
IWorkbook workbook = application.Workbooks.Open(fileStream);
22+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
2423

2524
//Initializes the SubstituteFont event to perform font substitution during Excel to PDF conversion
2625
application.SubstituteFont += new SubstituteFontEventHandler(SubstituteFont);
2726

2827
XlsIORenderer renderer = new XlsIORenderer();
2928
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
3029

31-
FileStream stream = new FileStream("Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
32-
pdfDocument.Save(stream);
30+
pdfDocument.Save("Output.pdf");
3331
}
3432

3533
private static void SubstituteFont(object sender, SubstituteFontEventArgs args)

Document-Processing/Excel/Excel-Library/NET/faqs/how-to-access-a-table-in-Excel-document-using-the-table-name.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
1616
{
1717
IApplication application = excelEngine.Excel;
1818
application.DefaultVersion = ExcelVersion.Xlsx;
19-
FileStream inputStream = new FileStream("D:../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
20-
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
2120
IWorksheet worksheet = workbook.Worksheets[0];
2221

2322
//Initialize the table
@@ -38,9 +37,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
3837
}
3938
}
4039

41-
//Saving the workbook as stream
42-
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
43-
workbook.SaveAs(outputStream);
40+
//Saving the workbook
41+
workbook.SaveAs("Output.xlsx");
4442
}
4543
{% endhighlight %}
4644

Document-Processing/Excel/Excel-Library/NET/faqs/how-to-add-Barcode-in-Excel-document.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
2525
worksheet.Pictures.AddPicture(15, 10, barcode2);
2626

2727
// Save to file system
28-
FileStream stream = new FileStream("Output.xlsx",FileMode.OpenOrCreate, FileAccess.ReadWrite);
29-
workbook.SaveAs(stream);
28+
workbook.SaveAs("Output.xlsx");
3029
workbook.Close();
3130
excelEngine.Dispose();
3231
}

Document-Processing/Excel/Excel-Library/NET/faqs/how-to-add-and-remove-page-breaks-in-Excel.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
3838
//Setting sheet view to see the page breaks
3939
worksheet.View = SheetView.PageBreakPreview;
4040

41-
//Saving the workbook as stream
42-
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
43-
workbook.SaveAs(outputStream);
44-
45-
//Dispose streams
46-
outputStream.Dispose();
41+
//Saving the workbook
42+
workbook.SaveAs("Output.xlsx");
4743
}
4844
{% endhighlight %}
4945

Document-Processing/Excel/Excel-Library/NET/faqs/how-to-add-oval-shape-to-Excel-chart.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: How to add Oval shape to Excel chart using XlsIO | Syncfusion
3-
description: Code example to add Oval shape to Excel chart using Syncfusion .NET Excel library (XlsIO).
3+
description: This page explains how to add Oval shape to Excel chart in C# (cross-platform and Windows-specific) and VB.NET using Syncfusion .NET Excel library (XlsIO).
44
platform: document-processing
55
control: XlsIO
66
documentation: UG
@@ -35,12 +35,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
3535

3636
#region Save
3737
//Saving the workbook
38-
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
39-
workbook.SaveAs(outputStream);
38+
workbook.SaveAs("Output.xlsx");
4039
#endregion
41-
42-
//Dispose streams
43-
outputStream.Dispose();
4440
}
4541
{% endhighlight %}
4642

Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-TimePeriod-conditional-formatting-in-Excel.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
1818
{
1919
IApplication application = excelEngine.Excel;
2020
application.DefaultVersion = ExcelVersion.Xlsx;
21-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.xlsx"), FileMode.Open, FileAccess.Read);
22-
IWorkbook workbook = application.Workbooks.Open(inputStream);
21+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
2322
IWorksheet worksheet = workbook.Worksheets[0];
2423

2524
//Apply conditional format for specific time period
@@ -34,12 +33,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
3433
conditionalFormat.BackColor = ExcelKnownColors.Sky_blue;
3534

3635
//Saving the workbook
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();
36+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
4337
}
4438
{% endhighlight %}
4539

Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-custom-filtering-to-string-data-types-using-XlsIO.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
1616
{
1717
IApplication application = excelEngine.Excel;
1818
application.DefaultVersion = ExcelVersion.Xlsx;
19-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.xlsx"), FileMode.Open, FileAccess.Read);
20-
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
2120
IWorksheet worksheet = workbook.Worksheets[0];
2221

2322
//Creating an AutoFilter
@@ -30,12 +29,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
3029
firstCondition.String = "1000.00";
3130

3231
//Saving the workbook
33-
FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
34-
workbook.SaveAs(outputStream);
35-
36-
//Dispose streams
37-
outputStream.Dispose();
38-
inputStream.Dispose();
32+
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
3933
}
4034
{% endhighlight %}
4135

Document-Processing/Excel/Excel-Library/NET/faqs/how-to-apply-formatting-to-pivottable-in-Excel-protected-view.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
1616
{
1717
IApplication application = excelEngine.Excel;
1818
application.DefaultVersion = ExcelVersion.Xlsx;
19-
FileStream fileStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
20-
IWorkbook workbook = application.Workbooks.Open(fileStream);
19+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
2120
IWorksheet worksheet = workbook.Worksheets[0];
2221
IWorksheet pivotSheet = workbook.Worksheets[1];
2322

@@ -40,10 +39,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
4039
pivotTable.BuiltInStyle = PivotBuiltInStyles.PivotStyleDark15;
4140
pivotTable.Layout();
4241

43-
//Saving the workbook as stream
44-
FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
45-
workbook.SaveAs(stream);
46-
stream.Dispose();
42+
//Saving the workbook
43+
workbook.SaveAs("Output.xlsx");
4744
}
4845

4946
{% endhighlight %}

0 commit comments

Comments
 (0)