Repository navigation
Expand file tree
/
Copy pathMainApp.cs
More file actions
190 lines (166 loc) · 6.14 KB
/
Copy pathMainApp.cs
File metadata and controls
190 lines (166 loc) · 6.14 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using ExcelExporter.Services;
using MaterialSkin;
using MaterialSkin.Controls;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace ExcelExporter
{
public partial class MainApp : MaterialForm
{
// =========================
// FREE EDITION STATE
// =========================
private string selectedExcelFile = null;
private string lastExportPath = null;
private ExcelExporterService exporter = new ExcelExporterService();
// =========================
// CONSTRUCTOR
// =========================
public MainApp()
{
InitializeComponent();
this.Text = "Excel VBA Exporter – Free Edition";
this.Icon = Properties.Resources.ExcelExporter;
MaterialSkinManager manager = MaterialSkinManager.Instance;
manager.AddFormToManage(this);
manager.Theme = MaterialSkinManager.Themes.LIGHT;
manager.ColorScheme = new ColorScheme(
Primary.Blue600,
Primary.Blue700,
Primary.Blue200,
Accent.LightBlue200,
TextShade.WHITE);
btnExport.Enabled = false;
btnOpenFolder.Enabled = false;
toolStripStatusLabel.Text =
"Free Edition – Upgrade to PRO for batch export & CLI automation";
}
// =========================
// SELECT FILE
// =========================
private void btnSelectFile_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Filter =
"Excel Files (*.xls;*.xlsx;*.xlsm;*.xlsb;*.xlt;*.xltx;*.xltm;*.xlam)|" +
"*.xls;*.xlsx;*.xlsm;*.xlsb;*.xlt;*.xltx;*.xltm;*.xlam";
ofd.Title = "Select an Excel file with VBA macros";
if (ofd.ShowDialog() == DialogResult.OK)
{
selectedExcelFile = ofd.FileName;
lblFile.Text = Path.GetFileName(selectedExcelFile);
btnExport.Enabled = true;
btnOpenFolder.Enabled = false;
toolStripStatusLabel.Text = "Ready to export";
}
}
}
// =========================
// PRO FEATURE (FOLDER)
// =========================
private void btnSelectFolder_Click(object sender, EventArgs e)
{
MessageBox.Show(
"Batch export from folders is available in the PRO edition.\n\n" +
"PRO features include:\n" +
"• Export VBA from entire folders\n" +
"• Command-line automation\n" +
"• CI / scripting integration",
"PRO Feature",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
// =========================
// EXPORT (FREE = SINGLE FILE)
// =========================
private void btnExport_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(selectedExcelFile))
{
MessageBox.Show(
"Please select an Excel file first.",
"No file selected",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
ExportOptions options = new ExportOptions
{
ExportModules = chkModules.Checked,
ExportClasses = chkClasses.Checked,
ExportForms = chkForms.Checked,
CreateZipArchive = chkZipExport.Checked
};
try
{
toolStripStatusLabel.Text = "Exporting...";
Refresh();
// ✅ CORRECT FREE-EDITION CALL
lastExportPath = exporter.ExportVbaFromExcel(
selectedExcelFile,
options);
btnOpenFolder.Enabled = true;
toolStripStatusLabel.Text = "Export completed";
MessageBox.Show(
"Export completed successfully.\n\nOutput:\n" + lastExportPath,
"Success",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception ex)
{
toolStripStatusLabel.Text = "Export failed";
MessageBox.Show(
ex.Message,
"Export failed",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
// =========================
// OPEN EXPORT FOLDER
// =========================
private void btnOpenFolder_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(lastExportPath))
{
MessageBox.Show(
"No export folder available.",
"Information",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
string folderToOpen =
File.Exists(lastExportPath)
? Path.GetDirectoryName(lastExportPath)
: lastExportPath;
if (Directory.Exists(folderToOpen))
{
Process.Start("explorer.exe", folderToOpen);
}
else
{
MessageBox.Show(
"Export folder no longer exists.",
"Not Found",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
}
// =========================
// THEME
// =========================
private void toggleThemeSwitch_CheckedChanged(object sender, EventArgs e)
{
MaterialSkinManager.Instance.Theme =
toggleThemeSwitch.Checked
? MaterialSkinManager.Themes.DARK
: MaterialSkinManager.Themes.LIGHT;
}
}
}