-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_vba_epplus.cs
More file actions
25 lines (18 loc) · 731 Bytes
/
create_vba_epplus.cs
File metadata and controls
25 lines (18 loc) · 731 Bytes
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
#!/usr/bin/env dotnet run
#:package EPPlus@8.5.0
#pragma warning disable
using OfficeOpenXml;
using System;
using System.IO;
ExcelPackage.License.SetNonCommercialOrganization("Test");
using (var package = new ExcelPackage())
{
var worksheet = package.Workbook.Worksheets.Add("Sheet1");
worksheet.Cells["A1"].Value = "Hello";
worksheet.Cells["A2"].Value = "Click the button to run the macro!";
package.Workbook.CreateVBAProject();
var module = package.Workbook.VbaProject.Modules.AddModule("Module1");
module.Code = "Sub HelloWorld()\r\n MsgBox \"Hello from EPPlus VBA!\"\r\nEnd Sub";
package.SaveAs(new FileInfo("output/epplus_vba.xlsm"));
Console.WriteLine("EPPlus VBA file created.");
}