Skip to content

Commit 716abc7

Browse files
authored
Merge pull request #258 from SyncfusionExamples/990137-FAQStreamChangesSample
990137-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents 509b4c3 + 0cb8bf7 commit 716abc7

File tree

19 files changed

+33
-123
lines changed
  • FAQ
    • Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart
    • Barcode/.NET/Add Barcode/Barcode
    • Chart/.NET
      • Set background color for chart/Set background color for chart
      • Show leader line/Show leader line
      • Switch chart series orientation/Switch chart series orientation
    • Column width for pivot table range/.NET/Column width for pivot table range/Column width for pivot table range
    • Conditional Formatting/.NET
    • Conversions/.NET/JSON to CSV/JSON to CSV
    • Filtering/.NET/Custom Filter String Type/CustomFilterStringType
    • Override Excel Document/.NET/Override Excel Document/Override Excel Document
    • RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor
    • Timespan/.NET/Set and format time values/Set and format time values
    • Workbook default font and font size/.NET/Workbook default font and font size/Workbook default font and font size
    • Worksheet Names/.NET
      • All Worksheet Names/All Worksheet Names
      • Hidden Worksheet Names/Hidden Worksheet Names
      • Visible Worksheet Names/Visible Worksheet Names
    • Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand

19 files changed

+33
-123
lines changed

FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Program.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ static void Main(string[] args)
3232

3333
#region Save
3434
//Saving the workbook
35-
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
36-
workbook.SaveAs(outputStream);
35+
workbook.SaveAs("Output.xlsx");
3736
#endregion
38-
39-
//Dispose streams
40-
outputStream.Dispose();
4137
}
4238
}
4339
}
44-
}
40+
}

FAQ/Barcode/.NET/Add Barcode/Barcode/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ static void Main(string[] args)
2424
worksheet.Pictures.AddPicture(15, 10, barcode2);
2525

2626
// Save to file system
27-
FileStream stream = new FileStream("Output/Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
28-
workbook.SaveAs(stream);
27+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
2928
workbook.Close();
3029
excelEngine.Dispose();
3130
}
32-
3331
}
34-
3532
}
3633
}

FAQ/Chart/.NET/Set background color for chart/Set background color for chart/Program.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817
IWorksheet worksheet = workbook.Worksheets[0];
1918

2019
//Get the first chart in the worksheet
@@ -28,16 +27,9 @@ static void Main(string[] args)
2827

2928
#region Save
3029
//Saving the workbook
31-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
32-
workbook.SaveAs(outputStream);
30+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3331
#endregion
34-
35-
//Dispose streams
36-
outputStream.Dispose();
37-
inputStream.Dispose();
3832
}
39-
4033
}
41-
4234
}
43-
}
35+
}

FAQ/Chart/.NET/Show leader line/Show leader line/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ static void Main(string[] args)
4343

4444
#region Save
4545
//Saving the workbook
46-
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
47-
workbook.SaveAs(outputStream);
46+
workbook.SaveAs("Output.xlsx");
4847
#endregion
49-
50-
//Dispose streams
51-
outputStream.Dispose();
5248
}
5349
}
5450
}

FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ static void Main(string[] args)
5151

5252
#region Save
5353
//Saving the workbook
54-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
55-
workbook.SaveAs(outputStream);
54+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
5655
#endregion
57-
58-
//Dispose streams
59-
outputStream.Dispose();
6056
}
6157
}
6258
}

FAQ/Column width for pivot table range/.NET/Column width for pivot table range/Column width for pivot table range/Program.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817
IWorksheet worksheet = workbook.Worksheets[0];
1918
IWorksheet worksheet1 = workbook.Worksheets[1];
2019

@@ -39,14 +38,9 @@ static void Main(string[] args)
3938

4039
#region Save
4140
//Saving the workbook
42-
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
43-
workbook.SaveAs(outputStream);
41+
workbook.SaveAs("Output.xlsx");
4442
#endregion
45-
46-
//Dispose streams
47-
outputStream.Dispose();
48-
inputStream.Dispose();
4943
}
5044
}
5145
}
52-
}
46+
}

FAQ/Conditional Formatting/.NET/Time period/Time period/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ static void Main(string[] args)
1212
{
1313
IApplication application = excelEngine.Excel;
1414
application.DefaultVersion = ExcelVersion.Xlsx;
15-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.xlsx"), FileMode.Open, FileAccess.Read);
16-
IWorkbook workbook = application.Workbooks.Open(inputStream);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
1716
IWorksheet worksheet = workbook.Worksheets[0];
1817

1918
//Apply conditional format for specific time period
@@ -28,12 +27,7 @@ static void Main(string[] args)
2827
conditionalFormat.BackColor = ExcelKnownColors.Sky_blue;
2928

3029
//Saving the workbook
31-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
32-
workbook.SaveAs(outputStream);
33-
34-
//Dispose streams
35-
outputStream.Dispose();
36-
inputStream.Dispose();
30+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3731
}
3832
}
3933

FAQ/Conditional Formatting/.NET/Traffic lights icon/Traffic lights icon/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ static void Main(string[] args)
5454
iconSet.IconSet = ExcelIconSetType.ThreeTrafficLights1;
5555

5656
//Saving the workbook
57-
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write);
58-
workbook.SaveAs(outputStream);
59-
outputStream.Dispose();
57+
workbook.SaveAs("Output.xlsx");
6058
}
61-
6259
}
63-
6460
}
6561
}
6662

FAQ/Conversions/.NET/JSON to CSV/JSON to CSV/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ static void Main()
2525
sheet.ImportDataTable(dataTable, true, 1, 1);
2626

2727
//Saving the workbook as CSV
28-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.csv"), FileMode.Create, FileAccess.ReadWrite);
29-
workbook.SaveAs(outputStream, ",");
30-
31-
//Dispose streams
32-
outputStream.Dispose();
28+
workbook.SaveAs(Path.GetFullPath("Output/Sample.csv"), ",");
3329
}
3430
}
3531
}

FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ public static void Main(string[] args)
99
{
1010
IApplication application = excelEngine.Excel;
1111
application.DefaultVersion = ExcelVersion.Xlsx;
12-
FileStream inputStream = new FileStream(Path.GetFullPath(@"../../../Data/Input.xlsx"), FileMode.Open, FileAccess.Read);
13-
IWorkbook workbook = application.Workbooks.Open(inputStream);
12+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"../../../Data/Input.xlsx"));
1413
IWorksheet worksheet = workbook.Worksheets[0];
1514

1615
//Creating an AutoFilter
@@ -23,12 +22,7 @@ public static void Main(string[] args)
2322
firstCondition.String = "1000.00";
2423

2524
//Saving the workbook
26-
FileStream outputStream = new FileStream(Path.GetFullPath("../../../Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
27-
workbook.SaveAs(outputStream);
28-
29-
//Dispose streams
30-
outputStream.Dispose();
31-
inputStream.Dispose();
25+
workbook.SaveAs(Path.GetFullPath("../../../Output/Output.xlsx"));
3226
}
3327
}
3428
}

0 commit comments

Comments
 (0)