Skip to content

Commit c13e09f

Browse files
committed
Excel2CSPro: some changes to the functionality of the Excel -> CSPro dictionary operation + some bug fixes
1 parent f89d528 commit c13e09f

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

Excel2CSPro/CreateDictionaryControl.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private void buttonSelectExcelFile_Click(object sender,EventArgs e)
3434
{
3535
try
3636
{
37-
_workbookController.OpenWorksheet(ofd.FileName);
37+
_workbookController.OpenWorkbook(ofd.FileName);
3838

3939
List<string> worksheetNames = _workbookController.WorksheetNames;
4040

@@ -257,6 +257,9 @@ private void buttonCreateDictionary_Click(object sender,EventArgs e)
257257

258258
CreateDictionaryItemControl.ItemSelections selections = cdic.Selections;
259259

260+
if( !selections.IncludeItem )
261+
continue;
262+
260263
if( !CSPro.Names.IsValid(selections.Name) )
261264
throw new Exception(String.Format(Messages.InvalidName,selections.Name));
262265

Excel2CSPro/CreateDictionaryItemControl.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public CreateDictionaryItemControl(CreateDictionaryControl.ColumnAnalysis column
2121
checkBoxItemCreateValueSet.Text = String.Format(checkBoxItemCreateValueSet.Text,_columnAnalysis.Values.Count);
2222
}
2323

24-
checkBoxIncludeItem.Text = _columnAnalysis.ColumnAddress;
2524
textBoxItemName.Text = CSPro.Names.CreateFromLabel(_columnAnalysis.HeaderText);
2625
textBoxItemLength.Text = _columnAnalysis.MaximumLength.ToString();
2726

@@ -44,10 +43,10 @@ private void checkBoxItemNumeric_CheckedChanged(object sender,EventArgs e)
4443
{
4544
bool isNumeric = checkBoxItemNumeric.Checked;
4645

47-
textBoxItemLength.Visible = !isNumeric;
46+
textBoxItemLength.Enabled = !isNumeric;
4847

49-
textBoxItemBeforeDecLength.Visible = isNumeric;
50-
textBoxItemAfterDecLength.Visible = isNumeric;
48+
textBoxItemBeforeDecLength.Enabled = isNumeric;
49+
textBoxItemAfterDecLength.Enabled = isNumeric;
5150

5251
checkBoxItemCreateValueSet.Visible = isNumeric && _canCreateValueSet;
5352
}

Excel2CSPro/CreateDictionaryItemControl.resx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@
207207
<data name="textBoxItemAfterDecLength.TabIndex" type="System.Int32, mscorlib">
208208
<value>5</value>
209209
</data>
210-
<data name="textBoxItemAfterDecLength.Visible" type="System.Boolean, mscorlib">
211-
<value>False</value>
212-
</data>
213210
<data name="&gt;&gt;textBoxItemAfterDecLength.Name" xml:space="preserve">
214211
<value>textBoxItemAfterDecLength</value>
215212
</data>
@@ -231,9 +228,6 @@
231228
<data name="textBoxItemBeforeDecLength.TabIndex" type="System.Int32, mscorlib">
232229
<value>4</value>
233230
</data>
234-
<data name="textBoxItemBeforeDecLength.Visible" type="System.Boolean, mscorlib">
235-
<value>False</value>
236-
</data>
237231
<data name="&gt;&gt;textBoxItemBeforeDecLength.Name" xml:space="preserve">
238232
<value>textBoxItemBeforeDecLength</value>
239233
</data>

Excel2CSPro/WorkbookController.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,56 @@ namespace Excel2CSPro
77
class WorkbookController
88
{
99
private static Excel.Application _application = null;
10+
private static List<Excel.Workbook> _openWorkbooks = new List<Excel.Workbook>();
1011
private Excel.Workbook _workbook = null;
1112
private Excel.Worksheet _worksheet = null;
1213

1314
public static void Close()
1415
{
1516
if( _application != null )
16-
_application.Quit();
17+
{
18+
// ignore any errors closing the workbooks or Excel
19+
try
20+
{
21+
for( int i = _openWorkbooks.Count - 1; i >= 0; i-- )
22+
CloseWorkbook(_openWorkbooks[i]);
23+
}
24+
25+
catch( Exception )
26+
{
27+
}
28+
29+
try
30+
{
31+
_application.Quit();
32+
}
33+
34+
catch( Exception )
35+
{
36+
}
37+
}
1738
}
1839

19-
public void OpenWorksheet(string filename)
40+
public void OpenWorkbook(string filename)
2041
{
21-
CloseWorksheet();
42+
if( _workbook != null )
43+
{
44+
CloseWorkbook(_workbook);
45+
_workbook = null;
46+
}
2247

2348
if( _application == null )
2449
_application = new Excel.Application();
2550

2651
_workbook = _application.Workbooks.Open(filename,Type.Missing,true);
52+
_openWorkbooks.Add(_workbook);
2753
}
2854

29-
public void CloseWorksheet()
55+
public static void CloseWorkbook(Excel.Workbook workbook)
3056
{
31-
if( _workbook != null )
32-
{
33-
_workbook.Saved = true; // disable any prompts to save the data
34-
_workbook.Close();
35-
_workbook = null;
36-
}
57+
workbook.Saved = true; // disable any prompts to save the data
58+
workbook.Close();
59+
_openWorkbooks.Remove(workbook);
3760
}
3861

3962
public List<string> WorksheetNames

0 commit comments

Comments
 (0)