Skip to content

Commit 42bf509

Browse files
authored
Merge pull request #255 from SyncfusionExamples/990137-MacrosUGSample
990137-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents 51173d2 + 4c28847 commit 42bf509

File tree

6 files changed

+6
-18
lines changed
  • Create and Edit Macros
    • Clear All Macros/.NET/Clear All Macros/Clear All Macros
    • Create Macro as MSForm/.NET/Create Macro as MSForm/Create Macro as MSForm
    • Edit Macro/.NET/Edit Macro/Edit Macro
    • Remove Macro with Index/.NET/Remove Macro with Index/Remove Macro with Index
    • Remove Macro with Name/.NET/Remove Macro with Name/Remove Macro with Name
    • Skip Macro and Save/.NET/Skip Macro and Save/Skip Macro and Save

6 files changed

+6
-18
lines changed

Create and Edit Macros/Clear All Macros/.NET/Clear All Macros/Clear All Macros/Program.cs

Lines changed: 1 addition & 3 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.xls"), FileMode.Open, FileAccess.Read);
16-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xls"), ExcelOpenType.Automatic);
1716
IWorksheet sheet = workbook.Worksheets[0];
1817

1918
//Accessing Vba project
@@ -32,7 +31,6 @@ static void Main(string[] args)
3231
#endregion
3332

3433
//Dispose streams
35-
inputStream.Dispose();
3634
outputStream.Dispose();
3735
}
3836
}

Create and Edit Macros/Create Macro as MSForm/.NET/Create Macro as MSForm/Create Macro as MSForm/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ static void Main(string[] args)
2323
IVbaModules vbaModules = project.Modules;
2424

2525
//Opening form module existing workbook
26-
FileStream input = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xls"), FileMode.Open, FileAccess.ReadWrite);
27-
IWorkbook newBook = application.Workbooks.Open(input);
26+
IWorkbook newBook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xls"));
2827

2928
IVbaProject newProject = newBook.VbaProject;
3029

@@ -47,7 +46,6 @@ static void Main(string[] args)
4746
#endregion
4847

4948
//Dispose streams
50-
input.Dispose();
5149
outputStream.Dispose();
5250
}
5351
}

Create and Edit Macros/Edit Macro/.NET/Edit Macro/Edit Macro/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xls"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xls"), ExcelOpenType.Automatic);
1817
IWorksheet sheet = workbook.Worksheets[0];
1918

2019
//Accessing Vba project
@@ -38,7 +37,6 @@ static void Main(string[] args)
3837
#endregion
3938

4039
//Dispose streams
41-
inputStream.Dispose();
4240
outputStream.Dispose();
4341
}
4442
}

Create and Edit Macros/Remove Macro with Index/.NET/Remove Macro with Index/Remove Macro with Index/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xls"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xls"), ExcelOpenType.Automatic);
1817
IWorksheet sheet = workbook.Worksheets[0];
1918

2019
//Accessing Vba project
@@ -33,7 +32,6 @@ static void Main(string[] args)
3332
#endregion
3433

3534
//Dispose streams
36-
inputStream.Dispose();
3735
outputStream.Dispose();
3836
}
3937
}

Create and Edit Macros/Remove Macro with Name/.NET/Remove Macro with Name/Remove Macro with Name/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xls"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xls"), ExcelOpenType.Automatic);
1817
IWorksheet sheet = workbook.Worksheets[0];
1918

2019
//Accessing Vba project
@@ -33,7 +32,6 @@ static void Main(string[] args)
3332
#endregion
3433

3534
//Dispose streams
36-
inputStream.Dispose();
3735
outputStream.Dispose();
3836
}
3937
}

Create and Edit Macros/Skip Macro and Save/.NET/Skip Macro and Save/Skip Macro and Save/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ static void Main(string[] args)
1414
{
1515
IApplication application = excelEngine.Excel;
1616
application.DefaultVersion = ExcelVersion.Xlsx;
17-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xls"), FileMode.Open, FileAccess.Read);
18-
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
17+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xls"), ExcelOpenType.Automatic);
1918
IWorksheet sheet = workbook.Worksheets[0];
2019

2120
//Skip Macros while saving
@@ -28,7 +27,6 @@ static void Main(string[] args)
2827
#endregion
2928

3029
//Dispose streams
31-
inputStream.Dispose();
3230
outputStream.Dispose();
3331
}
3432
}

0 commit comments

Comments
 (0)