Skip to content

Commit 5ae7923

Browse files
authored
Merge pull request #242 from SyncfusionExamples/988804-ModifyStreamsSamples
988804-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents dda760e + 9ef6e6a commit 5ae7923

File tree

14 files changed

+25
-99
lines changed
  • Conditional Formatting
    • Above and Below Average/.NET/Above and Below Average/Above and Below Average
    • Above and Below Standard Deviation/.NET/Above and Below Standard Deviation/Above and Below Standard Deviation
    • Color Scales/.NET/Color Scales/Color Scales
    • Conditional Format with R1C1/.NET/Conditional Format with R1C1/Conditional Format with R1C1
    • Create Conditional Format/.NET/Create Conditional Format/Create Conditional Format
    • Data Bars/.NET/Data Bars/Data Bars
    • Icon Sets/.NET/Icon Sets/Icon Sets
    • Read Conditional Format/.NET/Read Conditional Format/Read Conditional Format
    • Remove Conditional Format/.NET/Remove Conditional Format
    • Remove all Conditional Formats/.NET/Remove all Conditional Formats/Remove all Conditional Formats
    • Remove at Index/.NET/Remove at Index/Remove at Index
    • Top To Bottom Percent/.NET/Top To Bottom Percent/Top To Bottom Percent
    • Top to Bottom Rank/.NET/Top to Bottom Rank/Top to Bottom Rank
    • Unique and Duplicate/.NET/Unique and Duplicate/Unique and Duplicate

14 files changed

+25
-99
lines changed

Conditional Formatting/Above and Below Average/.NET/Above and Below Average/Above and Below Average/Program.cs

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

1817
//Applying conditional formatting to "M6:M35"
@@ -32,13 +31,8 @@ static void Main(string[] args)
3231

3332
#region Save
3433
//Saving the workbook
35-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/AboveAndBelowAverage.xlsx"), FileMode.Create, FileAccess.Write);
36-
workbook.SaveAs(outputStream);
34+
workbook.SaveAs(Path.GetFullPath("Output/AboveAndBelowAverage.xlsx"));
3735
#endregion
38-
39-
//Dispose streams
40-
outputStream.Dispose();
41-
inputStream.Dispose();
4236
}
4337
}
4438
}

Conditional Formatting/Above and Below Standard Deviation/.NET/Above and Below Standard Deviation/Above and Below Standard Deviation/Program.cs

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

1817
//Applying conditional formatting to "M6:M35"
@@ -35,13 +34,8 @@ static void Main(string[] args)
3534

3635
#region Save
3736
//Saving the workbook
38-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/AboveAndBelowStandardDeviation.xlsx"), FileMode.Create, FileAccess.Write);
39-
workbook.SaveAs(outputStream);
37+
workbook.SaveAs(Path.GetFullPath("Output/AboveAndBelowStandardDeviation.xlsx"));
4038
#endregion
41-
42-
//Dispose streams
43-
outputStream.Dispose();
44-
inputStream.Dispose();
4539
}
4640
}
4741
}

Conditional Formatting/Color Scales/.NET/Color Scales/Color Scales/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/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
16-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"), ExcelOpenType.Automatic);
1716
IWorksheet worksheet = workbook.Worksheets[0];
1817

1918
//Create color scales for the data in specified range
@@ -36,13 +35,8 @@ static void Main(string[] args)
3635

3736
#region Save
3837
//Saving the workbook
39-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
40-
workbook.SaveAs(outputStream);
38+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
4139
#endregion
42-
43-
//Dispose streams
44-
outputStream.Dispose();
45-
inputStream.Dispose();
4640
}
4741
}
4842
}

Conditional Formatting/Conditional Format with R1C1/.NET/Conditional Format with R1C1/Conditional Format with R1C1/Program.cs

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

2323
#region Save
2424
//Saving the workbook
25-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ConditionalFormat.xlsx"), FileMode.Create, FileAccess.Write);
26-
workbook.SaveAs(outputStream);
25+
workbook.SaveAs(Path.GetFullPath("Output/ConditionalFormat.xlsx"));
2726
#endregion
28-
29-
//Dispose streams
30-
outputStream.Dispose();
3127
}
3228
}
3329
}

Conditional Formatting/Create Conditional Format/.NET/Create Conditional Format/Create Conditional Format/Program.cs

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

6363
#region Save
6464
//Saving the workbook
65-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ConditionalFormat.xlsx"), FileMode.Create, FileAccess.Write);
66-
workbook.SaveAs(outputStream);
65+
workbook.SaveAs(Path.GetFullPath("Output/ConditionalFormat.xlsx"));
6766
#endregion
68-
69-
//Dispose streams
70-
outputStream.Dispose();
7167
}
7268
}
7369
}

Conditional Formatting/Data Bars/.NET/Data Bars/Data Bars/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/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
16-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"), ExcelOpenType.Automatic);
1716
IWorksheet worksheet = workbook.Worksheets[0];
1817

1918
//Create data bars for the data in specified range
@@ -30,13 +29,8 @@ static void Main(string[] args)
3029

3130
#region Save
3231
//Saving the workbook
33-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
34-
workbook.SaveAs(outputStream);
32+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3533
#endregion
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
4034
}
4135
}
4236
}

Conditional Formatting/Icon Sets/.NET/Icon Sets/Icon Sets/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/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
16-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"), ExcelOpenType.Automatic);
1716
IWorksheet worksheet = workbook.Worksheets[0];
1817

1918
//Create icon sets for the data in specified range
@@ -32,13 +31,8 @@ static void Main(string[] args)
3231

3332
#region Save
3433
//Saving the workbook
35-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
36-
workbook.SaveAs(outputStream);
34+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3735
#endregion
38-
39-
//Dispose streams
40-
outputStream.Dispose();
41-
inputStream.Dispose();
4236
}
4337
}
4438
}

Conditional Formatting/Read Conditional Format/.NET/Read Conditional Format/Read Conditional Format/Program.cs

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

1817
//Read conditional formatting settings
1918
string formatType = worksheet.Range["A1"].ConditionalFormats[0].FormatType.ToString();
2019
string cfOperator = worksheet.Range["A1"].ConditionalFormats[0].Operator.ToString();
2120

22-
//Dispose streams
23-
inputStream.Dispose();
21+
workbook.SaveAs("Output.xlsx");
2422
}
2523
}
2624
}

Conditional Formatting/Remove Conditional Format/.NET/Remove Conditional Format/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,16 @@ static void Main(string[] args)
1212
IApplication application = excelEngine.Excel;
1313
application.DefaultVersion = ExcelVersion.Xlsx;
1414

15-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
16-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"), ExcelOpenType.Automatic);
1716
IWorksheet worksheet = workbook.Worksheets[0];
1817

1918
//Removing conditional format for a specified range
2019
worksheet.Range["E5"].ConditionalFormats.Remove();
2120

2221
#region Save
2322
//Saving the workbook
24-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveConditionalFormat.xlsx"), FileMode.Create, FileAccess.Write);
25-
workbook.SaveAs(outputStream);
23+
workbook.SaveAs(Path.GetFullPath("Output/RemoveConditionalFormat.xlsx"));
2624
#endregion
27-
28-
//Dispose streams
29-
outputStream.Dispose();
30-
inputStream.Dispose();
3125
}
3226
}
3327
}

Conditional Formatting/Remove all Conditional Formats/.NET/Remove all Conditional Formats/Remove all Conditional Formats/Program.cs

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

1817
//Removing Conditional Formatting Settings From Entire Sheet
1918
worksheet.UsedRange.Clear(ExcelClearOptions.ClearConditionalFormats);
2019

2120
#region Save
2221
//Saving the workbook
23-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveAll.xlsx"), FileMode.Create, FileAccess.Write);
24-
workbook.SaveAs(outputStream);
22+
workbook.SaveAs(Path.GetFullPath("Output/RemoveAll.xlsx"));
2523
#endregion
26-
27-
//Dispose streams
28-
outputStream.Dispose();
29-
inputStream.Dispose();
3024
}
3125
}
3226
}

0 commit comments

Comments
 (0)