[Qt-interest] QAxObject ActiveX excel problem with optional params in method

Enrique Cuesta enriquecues at gmail.com
Tue Jan 5 08:05:02 CET 2010


sorry for repeat this...
I need help !

Hi !

I'm trying to understand how to control Excel via Qt with QAxObject....
These days I had learned a lot...
but I have a problem !
This is an silly example to show you my problem:

// Create a Excel.Application
   QAxObject * excel = new QAxObject( "Excel.Application", 0 );
// set Visible On
   excel->setProperty("Visible", visible);
// Retrieve excel workbooks
   QAxObject * workbooks = excel->querySubObject( "Workbooks" );
// Add 3 worksheets to a new workbook
   QAxObject * activeWorkbook= workbooks->querySubObject("Add()");
// get worksheets collection
   QAxObject * sheets =  activeWorkbook->querySubObject("Sheets");
// count worksheets -> 3
   int sheetsCount = sheets->property("Count").toInt();
// get the last worksheet in the workbook
QAxObject * lastSheet =  sheets->querySubObject("Item(QVariant)",sheetsCount );

/*
 NOW my problem...
 I want to add a new sheet AFTER the last sheet in the workbook...
 This is the method Add for adding sheets:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.sheets.add.aspx
object Add(
       [In, Optional] object Before,  <--- sheet object
       [In, Optional] object After,   <--- sheet object
       [In, Optional] object Count,
       [In, Optional] object Type
 );
You only should inform Before or After... but not both.
In VBA you can do this in this way:
Sheets.Add Null, Sheets(Sheets.Count), 1, XlSheetType.xlWorksheet
 In C# with ActiveX you can do it in this way:
Add(Type.Missing, lastSheet , 1, XlSheetType.xlWorksheet);
Type.Missing !! When you don't want to inform an optional param you
use Type.Missing in c#... or Null in VBA... but... in a qt's
QAxObject???
I had tried a lot of things... but with no luck...

QAxObject * result =
sheets->querySubObject("Add(QVariant,QVariant,QVariant,XlSheetType)",0,lastSheet->asVariant(),
1,"xlWorksheet"); // doesn't work
QAxObject * result =
sheets->querySubObject("Add(,QVariant,QVariant,XlSheetType)",lastSheet->asVariant(),
1,"xlWorksheet"); // doesn't work
QAxObject * result =
sheets->querySubObject("Add(QVariant,QVariant,QVariant,XlSheetType)","Null",
lastSheet->asVariant(), 1,"xlWorksheet"); // doesn't work

QAxObject * result =
sheets->querySubObject("Add(QVariant)",lastSheet->asVariant()"); //
this is Ok for Before.. but I want after
*/

any idea?
THANK YOU VERY MUCH


sorry for my poor english !




More information about the Qt-interest-old mailing list