PDA

View Full Version : ActiveQt + Excel



nile.one
18th September 2007, 07:08
I'm trying to convert Excel file to DBF. So i'm using ActiveQt FrameWork.
So i generated Excel namespace by using dumpcpp tool.
First of all i wanted to get list of the Worksheets.
The application is getting access violation in the row #10:
QString sheetname = sheet->Name();
I think the problem is that i incorrectly get the Excel::Worksheet object.

Does anybody know how to solve this problem?

The source code is shown below


Excel::Application* excel = new Excel::Application;
Excel::Workbooks* wbks = excel->Workbooks();
Excel::Workbook* wbk = wbks->Open(exchange->getFilename());
Excel::Sheets* sheets = wbk->Worksheets();
int count = sheets->Count();
QStringList sheetsList;
for (int i=1; i<=count; i++)
{
Excel::Worksheet* sheet = (Excel::Worksheet*) sheets->Item(i);
QString sheetname = sheet->Name();
sheetsList.append(sheetname);
}
wbk->Close();
excel->Quit();


Thanks.

nile.one
18th September 2007, 08:05
So, i've tried to use the QAxObject instead of dumpcpp's generated namespace.
And that works fine:



QAxObject* excel = new QAxObject( "Excel.Application", 0 );
// excel->dynamicCall("SetVisible(bool)",true);
QAxObject *workbooks = excel->querySubObject( "Workbooks" );
QAxObject *workbook = workbooks->querySubObject( "Open(const QString&)", exchange->getFilename() );
QAxObject *sheets = workbook->querySubObject( "Worksheets" );
int count = sheets->dynamicCall("Count()").toInt();
if (0 >= count)
{
excelState = Error;
return;
}
//else
QStringList sheetsList;
for (int i=1; i<=count; i++)
{
QAxObject* sheet = sheets->querySubObject( "Item( int )", i );
QString name = sheet->dynamicCall("Name()").toString();
sheetsList.append(name);
}
workbook->dynamicCall("Close()");
excel->dynamicCall( "Quit()");


It seems to me that the problem is in dumpcpp...

Of course, using the QAxObject is possible, but the Excel::Application namespace is much more pleasant to the eyes :o

nile.one
10th October 2007, 12:39
So i have another problem with ActiveQt and Excel =)

Does anybody know how to set Excel' cell values by array of data?
I mean not to call setValue on each cell, but set values of whole Range with only one call.
It will rapidly speed working with Excel data.

Well, here are my examples of code, which are unfortunately doesn't work

Example1, does nothing at all


QList<QVariant> lst;
for (int i=1; i<6; i++)
lst.append(i);
range = sheet->querySubObject( "Range(QString, QString)", "V1", "V5" );
QVariant v(lst);
range->dynamicCall("SetValue(QList<QVariant>)", lst);


Example 2, sets all values only to first value of list :(


QVariant v(lst);

range->dynamicCall("SetValue(QVariant)", v);


Thanks.

wysota
10th October 2007, 12:44
Your questions are a bit out of scope of this forum. You're asking for information about Excel API, which has nothing to do with Qt and I'm afraid we're simply not qualified to answer them.


BTW. Shouldn't you iterate starting from 0 instead of 1?

nile.one
15th October 2007, 05:00
ok, sorry for offtopic :o


BTW. Shouldn't you iterate starting from 0 instead of 1?
No, Micro$oft starts counting from 1 :D

bst
15th October 2007, 12:45
Hi,

you can only fill a horizontal range with an 1-dim Array, for a vertical range you need a 2-dim array.

And, also M$ often counts beginning with 1, here that shouldn't matter.

In VBA you could code it like this.

HTH, Bernd
--

Option Explicit

Sub x()
Dim i%, arHor(22 To 25), arVer(10 To 12, 99 To 99)

For i = 22 To 25
arHor(i) = i
Next
Range("A1:D1") = arHor

For i = 10 To 12
arVer(i, 99) = i
Next
Range("A2:A4") = arVer
End Sub

nile.one
16th October 2007, 07:10
Thanks, but unfortunately QAxObject doesn't support 2-dimensional arrays (i.e. QVariant doesn't support)

jpn
19th October 2007, 23:58
Actually you can make QVariant support basically anything.. :) See Q_DECLARE_METATYPE (http://doc.trolltech.com/latest/qmetatype.html#Q_DECLARE_METATYPE) for more details.