[Cpp]
// Configure //--------------------------------------------------------------------------------------------------
Void OExcelWnd: openExcel ()
{
Excel = new QAxObject ("Excel. Application ");
Excel-> setProperty ("UserControl", false );
Excel-> setProperty ("Visible", true );
Workbooks = excel-> querySubObject ("WorkBooks ");
Workbook = workbooks-> querySubObject ("Open (QString, QVariant)", curFile );
Worksheets = workbook-> querySubObject ("WorkSheets ");
Int sheetCount = worksheets-> property ("Count"). toInt ();
Worksheet = workbook-> querySubObject ("WorkSheets (int)", 1 );
// Sheet select box event: Todo: not changed, not triggered
Connect (worksheet, SIGNAL (SelectionChange (IDispatch *), this, SLOT (OnExcelSheetRangedClicked (IDispatch *)));
}
// Configure //--------------------------------------------------------------------------------------------------
Void OExcelWnd: OnExcelSheetRangedClicked (IDispatch * selectedRange)
{
QAxObject * userSelectedRange = new QAxObject (IUnknown *) selectedRange );
QAxObject * rows = userSelectedRange-> querySubObject ("Rows ");
QAxObject * columns = userSelectedRange-> querySubObject ("Columns ");
Int intRowCount = rows-> property ("Count"). toInt ();
Int intColCount = columns-> property ("Count"). toInt ();
If (intRowCount = 1 & intColCount = 1)
{
Int intRow = userSelectedRange-> property ("Row"). toInt ();
Int intCol = userSelectedRange-> property ("Column"). toInt ();
QAxObject * cellRange = worksheet-> querySubObject ("Cells (int, int)", intRow, intCol );
QString cellValue = cellRange-> dynamicCall ("Value2 ()"). toString ();
QDebug () <cellValue;
}
}
// Configure //--------------------------------------------------------------------------------------------------
Void OExcelWnd: readExcel1 ()
{
Excel = new QAxObject ("Excel. Application ");
Excel-> setProperty ("Visible", false );
Workbooks = excel-> querySubObject ("WorkBooks ");
Workbook = workbooks-> querySubObject ("Open (QString, QVariant)", curFile );
Worksheets = workbook-> querySubObject ("WorkSheets ");
Int sheetCount = worksheets-> property ("Count"). toInt ();
TabWidget-> clear ();
For (int I = 1; I <= sheetCount; I ++ ){
QAxObject * worksheet = workbook-> querySubObject ("WorkSheets (int)", I );
QString sheetName = worksheet-> property ("Name"). toString ();
QAxObject * usedrange = worksheet-> querySubObject ("UsedRange ");
QAxObject * rows = usedrange-> querySubObject ("Rows ");
QAxObject * columns = usedrange-> querySubObject ("Columns ");
Int intRows = rows-> property ("Count"). toInt ();
Int intCols = columns-> property ("Count"). toInt ();
Int intRowStart = usedrange-> property ("Row"). toInt ();
Int intColStart = usedrange-> property ("Column"). toInt ();
QTableWidget * onetable = new QTableWidget (intRows, intCols, this );
Connect (onetable, SIGNAL (itemClicked (QTableWidgetItem *), this, SLOT (OnTableWidgetItemClicked (QTableWidgetItem *)));
Onetable-> setObjectName (sheetName );
TabWidget-> addTab (onetable, sheetName );
For (int I = intRowStart; I <intRowStart + intRows; I ++)
{
For (int j = intColStart; j <intColStart + intCols; j ++)
{
QAxObject * range = worksheet-> querySubObject ("Cells (int, int)", I, j );
QString itemValue = range-> dynamicCall ("Value2 ()"). toString ();
QTableWidgetItem * newItem = new QTableWidgetItem (itemValue );
Onetable-> setItem (I, j, newItem );
} // End
} // End
}
}
[Cpp]
//// Test: Images and tables embedded in the shape table,
// QAxObject * shapes;
// Shapes = worksheet-> querySubObject ("Shapes ");
// Int shapecount = shapes-> property ("Count"). toInt ();
// QDebug () <shapecount;
// QAxObject * shape;
// Shape = worksheet-> querySubObject ("Shapes (int)", 1 );
// QString shapename = shapes-> property ("Name"). toString ();
// QDebug () <shapename;
// Shape-> querySubObject ("IncrementLeft (int)", 100 );