-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_vba_epplus.cs
More file actions
50 lines (44 loc) · 1.64 KB
/
read_vba_epplus.cs
File metadata and controls
50 lines (44 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env dotnet run
#:package EPPlus@8.5.0
#pragma warning disable
using OfficeOpenXml;
using System;
using System.IO;
ExcelPackage.License.SetNonCommercialOrganization("Test");
var file = args.Length > 0 ? args[0] : "output/22_vba_macros.xlsm";
try
{
using (var package = new ExcelPackage(new FileInfo(file)))
{
Console.WriteLine($"File: {file}");
Console.WriteLine($"Sheets: {package.Workbook.Worksheets.Count}");
foreach (var ws in package.Workbook.Worksheets)
Console.WriteLine($" Sheet: {ws.Name}");
if (package.Workbook.VbaProject != null)
{
Console.WriteLine($"VBA Project: YES");
Console.WriteLine($" Name: {package.Workbook.VbaProject.Name}");
Console.WriteLine($" Modules: {package.Workbook.VbaProject.Modules.Count}");
foreach (var mod in package.Workbook.VbaProject.Modules)
{
Console.WriteLine($" Module: {mod.Name} Type={mod.Type} Code={mod.Code?.Length ?? 0} chars");
if (mod.Code?.Length > 0)
Console.WriteLine($" Code: {mod.Code.Substring(0, Math.Min(100, mod.Code.Length))}");
}
}
else
{
Console.WriteLine("VBA Project: NO");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"ERROR: {ex.GetType().Name}: {ex.Message}");
Console.WriteLine($" StackTrace: {ex.StackTrace}");
if (ex.InnerException != null)
{
Console.WriteLine($" Inner: {ex.InnerException.GetType().Name}: {ex.InnerException.Message}");
Console.WriteLine($" Inner StackTrace: {ex.InnerException.StackTrace}");
}
}