Skip to content

Commit 13b8d4e

Browse files
authored
Merge pull request #245 from SyncfusionExamples/988874-ModifyStreams
Modify file streams of C# [Cross-platform] in XlsIO UG - Working with Formulas
2 parents 52f73c7 + d85c8f4 commit 13b8d4e

File tree

14 files changed

+19
-78
lines changed
  • Create and Edit Formulas
    • Argument Separator/.NET/Argument Separator/Argument Separator
    • Calculated Column/.NET/Calculated Column/Calculated Column
    • Calculated Value/.NET/Calculated Value/Calculated Value
    • Calculation Modes/.NET/Calculation Modes/Calculation Modes
    • Cross Sheet Formula/.NET/Cross Sheet Formula/Cross Sheet Formula
    • Delete Named Range/.NET/Delete Named Range/Delete Named Range
    • External Formula/.NET/External Formula/External Formula
    • Formula Array/.NET/Formula Array/Formula Array
    • Ignore Error/.NET/Ignore Error/Ignore Error
    • Incremental Formula/.NET/Incremental Formula/Incremental Formula
    • Iteration/.NET/Iteration/Iteration
    • Named Range/.NET/Named Range/Named Range
    • Set Formula/.NET/Set Formula/Set Formula
    • Types of Calculated Value/.NET/Types of Calculated Value/Types of Calculated Value

14 files changed

+19
-78
lines changed

Create and Edit Formulas/Argument Separator/.NET/Argument Separator/Argument Separator/Program.cs

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

2121
#region Save
2222
//Saving the workbook
23-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
24-
workbook.SaveAs(outputStream);
23+
workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
2524
#endregion
26-
27-
//Dispose streams
28-
outputStream.Dispose();
2925
}
3026
}
3127
}

Create and Edit Formulas/Calculated Column/.NET/Calculated Column/Calculated Column/Program.cs

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

3737
#region Save
3838
//Saving the workbook
39-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CalculatedColumn.xlsx"), FileMode.Create, FileAccess.Write);
40-
workbook.SaveAs(outputStream);
39+
workbook.SaveAs(Path.GetFullPath("Output/CalculatedColumn.xlsx"));
4140
#endregion
42-
43-
//Dispose streams
44-
outputStream.Dispose();
4541
}
4642
}
4743
}

Create and Edit Formulas/Calculated Value/.NET/Calculated Value/Calculated Value/Program.cs

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

3434
#region Save
3535
//Saving the workbook
36-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
37-
workbook.SaveAs(outputStream);
36+
workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
3837
#endregion
39-
40-
//Dispose streams
41-
outputStream.Dispose();
4238
}
4339
}
4440
}

Create and Edit Formulas/Calculation Modes/.NET/Calculation Modes/Calculation Modes/Program.cs

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

2020
#region Save
2121
//Saving the workbook
22-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CalculationMode.xlsx"), FileMode.Create, FileAccess.Write);
23-
workbook.SaveAs(outputStream);
22+
workbook.SaveAs(Path.GetFullPath("Output/CalculationMode.xlsx"));
2423
#endregion
25-
26-
//Dispose streams
27-
outputStream.Dispose();
2824
}
2925
}
3026
}

Create and Edit Formulas/Cross Sheet Formula/.NET/Cross Sheet Formula/Cross Sheet Formula/Program.cs

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

2626
#region Save
2727
//Saving the workbook
28-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
29-
workbook.SaveAs(outputStream);
28+
workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
3029
#endregion
31-
32-
//Dispose streams
33-
outputStream.Dispose();
3430
}
3531
}
3632
}

Create and Edit Formulas/Delete Named Range/.NET/Delete Named Range/Delete Named Range/Program.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ static void Main(string[] args)
1010
using (ExcelEngine excelEngine = new ExcelEngine())
1111
{
1212
IApplication application = excelEngine.Excel;
13-
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);
13+
application.DefaultVersion = ExcelVersion.Xlsx;
14+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1615
IWorksheet sheet = workbook.Worksheets[0];
1716

1817
//Deleting named range object
@@ -26,12 +25,8 @@ static void Main(string[] args)
2625

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

Create and Edit Formulas/External Formula/.NET/External Formula/External Formula/Program.cs

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

2020
#region Save
2121
//Saving the workbook
22-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExternalFormula.xlsx"), FileMode.Create, FileAccess.Write);
23-
workbook.SaveAs(outputStream);
22+
workbook.SaveAs(Path.GetFullPath("Output/ExternalFormula.xlsx"));
2423
#endregion
25-
26-
//Dispose streams
27-
outputStream.Dispose();
2824
}
2925
}
3026
}

Create and Edit Formulas/Formula Array/.NET/Formula Array/Formula Array/Program.cs

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

2828
#region Save
2929
//Saving the workbook
30-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
31-
workbook.SaveAs(outputStream);
30+
workbook.SaveAs(Path.GetFullPath("Output/Formula.xlsx"));
3231
#endregion
33-
34-
//Dispose streams
35-
outputStream.Dispose();
3632
}
3733
}
3834
}

Create and Edit Formulas/Ignore Error/.NET/Ignore Error/Ignore Error/Program.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,17 @@ static void Main(string[] args)
1010
using (ExcelEngine excelEngine = new ExcelEngine())
1111
{
1212
IApplication application = excelEngine.Excel;
13-
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);
13+
application.DefaultVersion = ExcelVersion.Xlsx;
14+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1615
IWorksheet sheet = workbook.Worksheets[0];
1716

1817
//Sets warning if number is entered as text.
1918
sheet.Range["A2:D2"].IgnoreErrorOptions = ExcelIgnoreError.NumberAsText;
2019

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

Create and Edit Formulas/Incremental Formula/.NET/Incremental Formula/Incremental Formula/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/IncrementalFormula.xlsx"), FileMode.Create, FileAccess.Write);
27-
workbook.SaveAs(outputStream);
26+
workbook.SaveAs(Path.GetFullPath("Output/IncrementalFormula.xlsx"));
2827
#endregion
29-
30-
//Dispose streams
31-
outputStream.Dispose();
3228
}
3329
}
3430
}

0 commit comments

Comments
 (0)