- }
- if (!excelObject.PutProperty("ActiveCell.Value", "wxWindows automation test!"))
- {
- wxMessageBox("Could not set active cell value.");
- return;
- }
-#ifdef HAVE_BOOL
- if (!excelObject.PutProperty("ActiveCell.Font.Bold", wxVariant((bool) TRUE)) )
- {
- wxMessageBox("Could not put Bold property to active cell.");
- return;
- }
-#endif
+ }
+
+ // Ensure that Excel is visible
+ if (!excelObject.PutProperty(wxT("Visible"), true))
+ {
+ wxMessageBox(wxT("Could not make Excel object visible"));
+ }
+ const wxVariant workbooksCountVariant = excelObject.GetProperty(wxT("Workbooks.Count"));
+ if (workbooksCountVariant.IsNull())
+ {
+ wxMessageBox(wxT("Could not get workbooks count"));
+ return;
+ }
+ const long workbooksCount = workbooksCountVariant;
+ if (workbooksCount == 0)
+ {
+ const wxVariant workbook = excelObject.CallMethod(wxT("Workbooks.Add"));
+ if (workbook.IsNull())
+ {
+ wxMessageBox(wxT("Could not create new Workbook"));
+ return;
+ }
+ }
+
+ if (!excelObject.PutProperty(wxT("ActiveCell.Value"), wxT("wxWidgets automation test!")))
+ {
+ wxMessageBox(wxT("Could not set active cell value."));
+ return;
+ }
+ if (!excelObject.PutProperty(wxT("ActiveCell.Font.Bold"), wxVariant(true)) )
+ {
+ wxMessageBox(wxT("Could not put Bold property to active cell."));
+ return;
+ }