Skip to content

Commit dda760e

Browse files
authored
Merge pull request #240 from SyncfusionExamples/988804-ModifyStreamsSamples
988804-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents 154a577 + 22db5a2 commit dda760e

File tree

50 files changed

+87
-341
lines changed
  • Editing Excel cells
    • Access Cell or Range/.NET/Access Cell or Range/Access Cell or Range
    • Access Discontinuous Range/.NET/Access Discontinuous Range/Access Discontinuous Range
    • Access Migrant Range/.NET/Access Migrant Range/Access Migrant Range
    • Access Relative Range/.NET/Access Relative Range/Access Relative Range
    • Accessing Filter/.NET/Accessing Filter/Accessing Filter
    • Advanced Filter/.NET/Advanced Filter/Advanced Filter
    • Cell Color Filter/.NET/Cell Color Filter/Cell Color Filter
    • Clear Content/.NET/Clear Content/Clear Content
    • Combination Filter/.NET/Combination Filter/Combination Filter
    • Custom Filter/.NET/Custom Filter/Custom Filter
    • Dynamic Filter/.NET/Dynamic Filter/Dynamic Filter
    • Filter/.NET/Filter/Filter
    • Find/.NET/Find/Find
    • Font Color Filter/.NET/Font Color Filter/Font Color Filter
    • Icon Filter/.NET/Icon Filter/Icon Filter
    • Precedent and Dependent Cells/.NET/Precedent and Dependent Cells/Precedent and Dependent Cells
    • Replace/.NET/Replace/Replace
    • Sort On Cell Color/.NET/Sort On Cell Color/Sort On Cell Color
    • Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values
    • Sort on Font Color/.NET/Sort on Font Color/Sort on Font Color
    • Sorting Data with Filters/.NET/Sorting Worksheet/Sorting Worksheet
  • Format rows and columns
    • Autofit Rows and Columns/.NET/Autofit Rows and Columns/Autofit Rows and Columns
    • Delete Rows and Columns/.NET/Delete Rows and Columns/Delete Rows and Columns
    • Expand or Collapse Groups/.NET/Expand or Collapse Groups/Expand or Collapse Groups
    • Group Rows and Columns/.NET/Group Rows and Columns/Group Rows and Columns
    • Hide Range/.NET/Hide Range/Hide Range
    • Hide Rows and Columns/.NET/Hide Rows and Columns/Hide Rows and Columns
    • Insert Rows and Columns/.NET/Insert Rows and Columns/Insert Rows and Columns
    • Move Rows and Columns/.NET/Move Rows and Columns/Move Rows and Columns
    • Resize Rows and Columns/.NET/Resize Rows and Columns/Resize Rows and Columns
    • Ungroup Rows and Columns/.NET/Ungroup Rows and Columns/Ungroup Rows and Columns
  • Import and Export Data
    • Array to Worksheet/.NET/Array to Worksheet/Array to Worksheet
    • CollectionObjects to Worksheet/.NET/CollectionObjects to Worksheet/CollectionObjects to Worksheet
    • DataColumn to Worksheet/.NET/DataColumn to Worksheet/DataColumn to Worksheet
    • DataTable to Worksheet/.NET/DataTable to Worksheet/DataTable to Worksheet
    • DataView to Worksheet/.NET/DataView to Worksheet/DataView to Worksheet
    • Grouping Options/.NET/Grouping Options/Grouping Options
    • HTML Table to Worksheet/.NET/HTML Table to Worksheet/HTML Table to Worksheet
    • Import Data Options/.NET/Import Data Options/Import Data Options
    • Layout Options/.NET/Layout Options/Layout Options
    • Worksheet to CollectionObjects/.NET/Worksheet to CollectionObjects/Worksheet to CollectionObjects
    • Worksheet to DataTable/.NET/Worksheet to DataTable/Worksheet to DataTable
    • Worksheet to Nested Class/.NET/Worksheet to Nested Class/Worksheet to Nested Class

Some content is hidden

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

50 files changed

+87
-341
lines changed

Editing Excel cells/Access Cell or Range/.NET/Access Cell or Range/Access Cell or Range/Program.cs

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

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

Editing Excel cells/Access Discontinuous Range/.NET/Access Discontinuous Range/Access Discontinuous Range/Program.cs

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

2929
#region Save
3030
//Saving the workbook
31-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/DiscontinuousRange.xlsx"), FileMode.Create, FileAccess.Write);
32-
workbook.SaveAs(outputStream);
31+
workbook.SaveAs(Path.GetFullPath("Output/DiscontinuousRange.xlsx"));
3332
#endregion
34-
35-
//Dispose streams
36-
outputStream.Dispose();
3733
}
3834
}
3935
}

Editing Excel cells/Access Migrant Range/.NET/Access Migrant Range/Access Migrant Range/Program.cs

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

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

Editing Excel cells/Access Relative Range/.NET/Access Relative Range/Access Relative Range/Program.cs

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

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

Editing Excel cells/Accessing Filter/.NET/Accessing Filter/Accessing Filter/Program.cs

Lines changed: 2 additions & 4 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);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1716
IWorksheet worksheet = workbook.Worksheets[0];
1817

1918
#region Accessing Filter
@@ -61,8 +60,7 @@ static void Main(string[] args)
6160
}
6261
#endregion
6362

64-
//Dispose streams
65-
inputStream.Dispose();
63+
workbook.SaveAs("Output.xlsx");
6664
}
6765
}
6866
}

Editing Excel cells/Advanced Filter/.NET/Advanced Filter/Advanced Filter/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
#region Advanced Filter
@@ -26,13 +25,8 @@ static void Main(string[] args)
2625

2726
#region Save
2827
//Saving the workbook
29-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/AdvancedFilter.xlsx"), FileMode.Create, FileAccess.Write);
30-
workbook.SaveAs(outputStream);
28+
workbook.SaveAs(Path.GetFullPath("Output/AdvancedFilter.xlsx"));
3129
#endregion
32-
33-
//Dispose streams
34-
outputStream.Dispose();
35-
inputStream.Dispose();
3630
}
3731
}
3832
}

Editing Excel cells/Cell Color Filter/.NET/Cell Color Filter/Cell Color Filter/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
#region Cell Color Filter
@@ -28,13 +27,8 @@ static void Main(string[] args)
2827

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

Editing Excel cells/Clear Content/.NET/Clear Content/Clear Content/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
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);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1716
IWorksheet worksheet = workbook.Worksheets[0];
1817

1918
#region Clear Content
@@ -23,13 +22,8 @@ static void Main(string[] args)
2322

2423
#region Save
2524
//Saving the workbook
26-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ClearContent.xlsx"), FileMode.Create, FileAccess.Write);
27-
workbook.SaveAs(outputStream);
25+
workbook.SaveAs(Path.GetFullPath("Output/ClearContent.xlsx"));
2826
#endregion
29-
30-
//Dispose streams
31-
outputStream.Dispose();
32-
inputStream.Dispose();
3327
}
3428
}
3529
}

Editing Excel cells/Combination Filter/.NET/Combination Filter/Combination Filter/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);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1716
IWorksheet worksheet = workbook.Worksheets[0];
1817

1918
#region Combination Filter
@@ -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/CombinationFilter.xlsx"), FileMode.Create, FileAccess.Write);
39-
workbook.SaveAs(outputStream);
37+
workbook.SaveAs(Path.GetFullPath("Output/CombinationFilter.xlsx"));
4038
#endregion
41-
42-
//Dispose streams
43-
outputStream.Dispose();
44-
inputStream.Dispose();
4539
}
4640
}
4741
}

Editing Excel cells/Custom Filter/.NET/Custom Filter/Custom Filter/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
#region Custom Filter
@@ -33,13 +32,8 @@ static void Main(string[] args)
3332

3433
#region Save
3534
//Saving the workbook
36-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CustomFilter.xlsx"), FileMode.Create, FileAccess.Write);
37-
workbook.SaveAs(outputStream);
35+
workbook.SaveAs(Path.GetFullPath("Output/CustomFilter.xlsx"));
3836
#endregion
39-
40-
//Dispose streams
41-
outputStream.Dispose();
42-
inputStream.Dispose();
4337
}
4438
}
4539
}

0 commit comments

Comments
 (0)