Skip to content

Commit c86dfe1

Browse files
authored
Merge pull request #248 from SyncfusionExamples/988804-ModifyStreamsSamples
988804-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents 5d50064 + 986f931 commit c86dfe1

File tree

7 files changed

+13
-53
lines changed
  • Create and Edit Table
    • Add Total Row/.NET/Add Total Row/Add Total Row
    • Apply Custom Style/.NET/Apply Custom Style/Apply Custom Style
    • Create Table/.NET/Create Table/Create Table
    • Format Table/.NET/Format Table/Format Table
    • Insert Column/.NET/Insert Column/Insert Column
    • Read Table/.NET/Read Table/Read Table
    • Remove Column/.NET/Remove Column/Remove Column

7 files changed

+13
-53
lines changed

Create and Edit Table/Add Total Row/.NET/Add Total Row/Add Total Row/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
//Creating a table
@@ -27,13 +26,8 @@ static void Main(string[] args)
2726

2827
#region Save
2928
//Saving the workbook
30-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/AddTotalRow.xlsx"), FileMode.Create, FileAccess.Write);
31-
workbook.SaveAs(outputStream);
29+
workbook.SaveAs(Path.GetFullPath("Output/AddTotalRow.xlsx"));
3230
#endregion
33-
34-
//Dispose streams
35-
inputStream.Dispose();
36-
outputStream.Dispose();
3731
}
3832
}
3933
}

Create and Edit Table/Apply Custom Style/.NET/Apply Custom Style/Apply Custom Style/Program.cs

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

101101
#region Save
102102
//Saving the workbook
103-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CustomTableStyle.xlsx"), FileMode.Create, FileAccess.Write);
104-
workbook.SaveAs(outputStream);
103+
workbook.SaveAs(Path.GetFullPath("Output/CustomTableStyle.xlsx"));
105104
#endregion
106-
107-
//Dispose streams
108-
outputStream.Dispose();
109105
}
110106
}
111107
}

Create and Edit Table/Create Table/.NET/Create Table/Create Table/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
{
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
//Create for the given data
2019
IListObject table = worksheet.ListObjects.Create("Table1", worksheet["A1:C5"]);
2120

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

Create and Edit Table/Format Table/.NET/Format Table/Format Table/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
//Creating a table
@@ -24,13 +23,8 @@ static void Main(string[] args)
2423

2524
#region Save
2625
//Saving the workbook
27-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/FormatTable.xlsx"), FileMode.Create, FileAccess.Write);
28-
workbook.SaveAs(outputStream);
26+
workbook.SaveAs(Path.GetFullPath("Output/FormatTable.xlsx"));
2927
#endregion
30-
31-
//Dispose streams
32-
inputStream.Dispose();
33-
outputStream.Dispose();
3428
}
3529
}
3630
}

Create and Edit Table/Insert Column/.NET/Insert Column/Insert Column/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
//Creating a table
@@ -24,13 +23,8 @@ static void Main(string[] args)
2423

2524
#region Save
2625
//Saving the workbook
27-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/InsertTableColumn.xlsx"), FileMode.Create, FileAccess.Write);
28-
workbook.SaveAs(outputStream);
26+
workbook.SaveAs(Path.GetFullPath("Output/InsertTableColumn.xlsx"));
2927
#endregion
30-
31-
//Dispose streams
32-
inputStream.Dispose();
33-
outputStream.Dispose();
3428
}
3529
}
3630
}

Create and Edit Table/Read Table/.NET/Read Table/Read Table/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
//Accessing first table in the sheet
@@ -24,13 +23,8 @@ static void Main(string[] args)
2423

2524
#region Save
2625
//Saving the workbook
27-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ReadTable.xlsx"), FileMode.Create, FileAccess.Write);
28-
workbook.SaveAs(outputStream);
26+
workbook.SaveAs(Path.GetFullPath("Output/ReadTable.xlsx"));
2927
#endregion
30-
31-
//Dispose streams
32-
inputStream.Dispose();
33-
outputStream.Dispose();
3428
}
3529
}
3630
}

Create and Edit Table/Remove Column/.NET/Remove Column/Remove Column/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
//Creating a table
@@ -24,13 +23,8 @@ static void Main(string[] args)
2423

2524
#region Save
2625
//Saving the workbook
27-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/RemoveTableColumn.xlsx"), FileMode.Create, FileAccess.Write);
28-
workbook.SaveAs(outputStream);
26+
workbook.SaveAs(Path.GetFullPath("Output/RemoveTableColumn.xlsx"));
2927
#endregion
30-
31-
//Dispose streams
32-
inputStream.Dispose();
33-
outputStream.Dispose();
3428
}
3529
}
3630
}

0 commit comments

Comments
 (0)