Skip to content

Commit 1e2805d

Browse files
authored
Merge pull request #233 from SyncfusionExamples/985509-ModifyStreamsSamples
985509-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents defc582 + 526ef3f commit 1e2805d

File tree

40 files changed

+67
-260
lines changed
  • Worksheet Features
    • Access Worksheet/.NET/Access Worksheet/Access Worksheet
    • Activate Worksheet/.NET/Activate Worksheet/Activate Worksheet
    • Auto Fill/.NET/AutoFillUsingFillSeries/AutoFillUsingFillSeries
    • Copy Cell Range/.NET/Copy Cell Range/Copy Cell Range
    • Copy Column/.NET/Copy Column/Copy Column
    • Copy Row/.NET/Copy Row/Copy Row
    • Copy Workbook/.NET/Copy Workbook/Copy Workbook
    • Copy Worksheet/.NET/Copy Worksheet/Copy Worksheet
    • Create Worksheet/.NET/Create Worksheet/Create Worksheet
    • Fill Series/.NET
      • DateTimeFillSeries/DateTimeFillSeries
      • FillSeriesByEnablingTrend/FillSeriesByEnablingTrend
      • NumberFillSeries/NumberFillSeries
    • FitToPagesTall/.NET/FitToPagesTall/FitToPagesTall
    • FitToPagesWide/.NET/FitToPagesWide/FitToPagesWide
    • Freeze Columns/.NET/Freeze Columns/Freeze Columns
    • Freeze Rows/.NET/Freeze Rows/Freeze Rows
    • Hide Gridlines/.NET/Hide Gridlines/Hide Gridlines
    • Hide Row and Column Headers/.NET/Hide Row and Column Headers/Hide Row and Column Headers
    • Hide Row and Column/.NET/Hide Row and Column/Hide Row and Column
    • Hide Worksheet Tabs/.NET/Hide Worksheet Tabs/Hide Worksheet Tabs
    • Hide Worksheet/.NET/Hide Worksheet/Hide Worksheet
    • Highlight Worksheet Tab/.NET/Highlight Worksheet Tab/Highlight Worksheet Tab
    • IsFitToPage/.NET/IsFitToPage/IsFitToPage
    • IsSummaryColumnRight/.NET/IsSummaryColumnRight/IsSummaryColumnRight
    • IsSummaryRowBelow/.NET/IsSummaryRowBelow/IsSummaryRowBelow
    • Move Cell Range/.NET/Move Cell Range/Move Cell Range
    • Move Column/.NET/Move Column/Move Column
    • Move Row/.NET/Move Row/Move Row
    • Move Worksheet/.NET/Move Worksheet/Move Worksheet
    • PrintArea/.NET/PrintArea/PrintArea
    • PrintGridlines/.NET/PrintGridlines/PrintGridlines
    • PrintHeadings/.NET/PrintHeadings/PrintHeadings
    • PrintTitleColumns/.NET/PrintTitleColumns/PrintTitleColumns
    • PrintTitleRows/.NET/PrintTitleRows/PrintTitleRows
    • Remove Worksheet/.NET/Remove Worksheet/Remove Worksheet
    • Set Zoom Level/.NET/Set Zoom Level/Set Zoom Level
    • Show Row and Column/.NET/Show Row and Column/Show Row and Column
    • Split Panes/.NET/Split Panes/Split Panes
    • UnFreeze Panes/.NET/UnFreeze Panes/UnFreeze Panes

40 files changed

+67
-260
lines changed

Worksheet Features/Access Worksheet/.NET/Access Worksheet/Access Worksheet/Program.cs

Lines changed: 1 addition & 5 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

1716
#region Access
1817
//Accessing via index
@@ -21,9 +20,6 @@ static void Main(string[] args)
2120
//Accessing via sheet name
2221
IWorksheet NamedSheet = workbook.Worksheets["Sample"];
2322
#endregion
24-
25-
//Dispose streams
26-
inputStream.Dispose();
2723
}
2824
}
2925
}

Worksheet Features/Activate Worksheet/.NET/Activate Worksheet/Activate Worksheet/Program.cs

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

2424
#region Save
2525
//Saving the workbook
26-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ActivateWorksheet.xlsx"), FileMode.Create, FileAccess.Write);
27-
workbook.SaveAs(outputStream);
26+
workbook.SaveAs(Path.GetFullPath("Output/ActivateWorksheet.xlsx"));
2827
#endregion
29-
30-
//Dispose streams
31-
outputStream.Dispose();
3228
}
3329
}
3430
}

Worksheet Features/Auto Fill/.NET/AutoFillUsingFillSeries/AutoFillUsingFillSeries/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ public static void Main(string[] args)
2929
source.AutoFill(destinationRange, ExcelAutoFillType.FillSeries);
3030

3131
//Saving the workbook
32-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
33-
workbook.SaveAs(outputStream);
34-
35-
//Dispose streams
36-
outputStream.Dispose();
32+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3733
}
3834
}
3935
}

Worksheet Features/Copy Cell Range/.NET/Copy Cell Range/Copy Cell Range/Program.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ static void Main(string[] args)
1010
{
1111
IApplication application = excelEngine.Excel;
1212
application.DefaultVersion = ExcelVersion.Xlsx;
13-
14-
FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
15-
IWorkbook workbook = application.Workbooks.Open(sourceStream);
13+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1614

1715
IWorksheet sourceWorksheet = workbook.Worksheets[0];
1816
IWorksheet destinationWorksheet = workbook.Worksheets[1];
@@ -23,13 +21,8 @@ static void Main(string[] args)
2321
//Copy the cell range to the next sheet
2422
source.CopyTo(destination);
2523

26-
//Saving the workbook as stream
27-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
28-
workbook.SaveAs(outputStream);
29-
30-
//Dispose streams
31-
outputStream.Dispose();
32-
sourceStream.Dispose();
24+
//Saving the workbook
25+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3326
}
3427
}
3528
}

Worksheet Features/Copy Column/.NET/Copy Column/Copy Column/Program.cs

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

2018
IWorksheet sourceWorksheet = workbook.Worksheets[0];
2119
IWorksheet destinationWorksheet = workbook.Worksheets[1];
@@ -26,13 +24,8 @@ public static void Main(string[] args)
2624
//Copy the entire column to the next sheet
2725
sourceColumn.EntireColumn.CopyTo(destinationColumn);
2826

29-
//Saving the workbook as stream
30-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
31-
workbook.SaveAs(outputStream);
32-
33-
//Dispose streams
34-
outputStream.Dispose();
35-
inputStream.Dispose();
27+
//Saving the workbook
28+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3629
}
3730
}
3831
}

Worksheet Features/Copy Row/.NET/Copy Row/Copy Row/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public static void Main(string[] args)
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
1616

17-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
18-
IWorkbook workbook = application.Workbooks.Open(inputStream);
17+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1918

2019
IWorksheet sourceWorksheet = workbook.Worksheets[0];
2120
IWorksheet destinationWorksheet = workbook.Worksheets[1];
@@ -27,12 +26,7 @@ public static void Main(string[] args)
2726
sourceRow.EntireRow.CopyTo(destinationRow);
2827

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

Worksheet Features/Copy Workbook/.NET/Copy Workbook/Copy Workbook/Program.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,14 @@ public static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/SourceWorkbookTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook sourceWorkbook = application.Workbooks.Open(sourceStream);
18-
FileStream destinationStream = new FileStream(Path.GetFullPath(@"Data/DestinationWorkbookTemplate.xlsx"), FileMode.Open, FileAccess.Read);
19-
IWorkbook destinationWorkbook = application.Workbooks.Open(destinationStream);
16+
IWorkbook sourceWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/SourceWorkbookTemplate.xlsx"));
17+
IWorkbook destinationWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/DestinationWorkbookTemplate.xlsx"));
2018

2119
//Clone the workbook
2220
destinationWorkbook = sourceWorkbook.Clone();
2321

24-
//Saving the workbook as stream
25-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
26-
destinationWorkbook.SaveAs(outputStream);
27-
28-
//Dispose streams
29-
outputStream.Dispose();
30-
destinationStream.Dispose();
31-
sourceStream.Dispose();
22+
//Saving the workbook
23+
destinationWorkbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3224
}
3325
}
3426
}

Worksheet Features/Copy Worksheet/.NET/Copy Worksheet/Copy Worksheet/Program.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ static void Main(string[] args)
1111
{
1212
IApplication application = excelEngine.Excel;
1313
application.DefaultVersion = ExcelVersion.Xlsx;
14-
15-
FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/SourceTemplate.xlsx"), FileMode.Open, FileAccess.Read);
16-
IWorkbook sourceWorkbook = application.Workbooks.Open(sourceStream);
17-
18-
FileStream destinationStream = new FileStream(Path.GetFullPath(@"Data/DestinationTemplate.xlsx"), FileMode.Open, FileAccess.Read);
19-
IWorkbook destinationWorkbook = application.Workbooks.Open(destinationStream);
14+
IWorkbook sourceWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/SourceTemplate.xlsx"));
15+
IWorkbook destinationWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/DestinationTemplate.xlsx"));
2016

2117
#region Copy Worksheet
2218
//Copy first worksheet from the source workbook to the destination workbook
@@ -26,14 +22,8 @@ static void Main(string[] args)
2622

2723
#region Save
2824
//Saving the workbook
29-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CopyWorksheet.xlsx"), FileMode.Create, FileAccess.Write);
30-
destinationWorkbook.SaveAs(outputStream);
25+
destinationWorkbook.SaveAs(Path.GetFullPath("Output/CopyWorksheet.xlsx"));
3126
#endregion
32-
33-
//Dispose streams
34-
outputStream.Dispose();
35-
destinationStream.Dispose();
36-
sourceStream.Dispose();
3727
}
3828
}
3929
}

Worksheet Features/Create Worksheet/.NET/Create Worksheet/Create Worksheet/Program.cs

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

2424
#region Save
2525
//Saving the workbook
26-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CreateWorksheet.xlsx"), FileMode.Create, FileAccess.Write);
27-
workbook.SaveAs(outputStream);
26+
workbook.SaveAs(Path.GetFullPath("Output/CreateWorksheet.xlsx"));
2827
#endregion
29-
30-
//Dispose streams
31-
outputStream.Dispose();
3228
}
3329
}
3430
}

Worksheet Features/Fill Series/.NET/DateTimeFillSeries/DateTimeFillSeries/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ public static void Main(string[] args)
2323
range.FillSeries(ExcelSeriesBy.Columns, ExcelFillSeries.Years, 2, new DateTime(2100, 1, 1));
2424

2525
//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();
26+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
3127
}
3228
}
3329
}

0 commit comments

Comments
 (0)