[Qt-interest] excel QAxObject problem with optional params
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Mon Jan 4 02:32:42 CET 2010
Hi Enrique,
I'm not sure if Qt isNull variants mean anything in COM, but I suggest:
QAxObject * result = sheets->querySubObject("Add(QVariant,QVariant)",
QVariant(), lastSheet->asVariant());
Tony
> 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.inter
> op.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,XlSheet
> Type)",0,lastSheet->asVariant(),
> 1,"xlWorksheet"); // doesn't work
> QAxObject * result =
> sheets->querySubObject("Add(,QVariant,QVariant,XlSheetType)",l
> astSheet->asVariant(),
> 1,"xlWorksheet"); // doesn't work
> QAxObject * result =
> sheets->querySubObject("Add(QVariant,QVariant,QVariant,XlSheet
> Type)","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