Zeilenzahl in Exceltabelle bestimmen



  • Hallo,
    ich lese in einem Programm Daten aus einer Excel-Tabelle aus (aus der MSDN):

    // OLE Variant for Optional.
    				COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
    
    				_Application objApp;
    				_Workbook objBook;
    				Workbooks objBooks;
    				Worksheets objSheets;
    				_Worksheet objSheet;
    				Range objRange;
    				VARIANT ret;
    
    				// Instantiate Excel and open an existing workbook.
    				objApp.CreateDispatch("Excel.Application");
    				objBooks = objApp.GetWorkbooks();
    				objBook = objBooks.Open(openFileName,
    					VOptional, VOptional, VOptional, VOptional,
    					VOptional, VOptional, VOptional, VOptional,
    					VOptional, VOptional, VOptional, VOptional);
    				objSheets = objBook.GetWorksheets();
    				objSheet = objSheets.GetItem(COleVariant((short)1));
    
    				//Get the range object for which you wish to retrieve the
    				//data and then retrieve the data (as a variant array, ret).
    				objRange = objSheet.GetRange(COleVariant("A2"), COleVariant("BP8"));
    				ret = objRange.GetValue();
    
    				//Create the SAFEARRAY from the VARIANT ret.
    				COleSafeArray sa(ret);
    
    				//Determine the array's dimensions.
    				long lNumRows;
    				long lNumCols;
    				sa.GetUBound(1, &lNumRows);
    				sa.GetUBound(2, &lNumCols);
    
    				//Display the elements in the SAFEARRAY.
    				long index[2];
    				VARIANT val;
    				int r, c;
    
    				for(r=1;r<=lNumRows;r++)
    				{
    ...
    }
    

    Das funktioniert soweit auch wunderbar, allerdings muß ich die Anzahl der Zeilen angeben. Diese möchte ich nun automatisch auslesen lassen. Wie kann ich das realisieren??



  • Weiß denn wirklich niemand eine Antwort?? Das wär echt super wichtig!

    THX im Vorraus!



  • Hi,

    du musst die Anzahl über die SpecialCells holen.

    int Anzahl=Columns(oder sowas).SpecialCells(11);
    //xlCellTypeLastCell==11 !
    


  • Also das mit den Zeilen hab ich jetzt gelöst, jetzt hab ich noch ein anderes Problem: obwohl ich Excel mit

    objApp.Quit();
    

    schließe, habe ich nach Beenden meines Programms noch immer einen "Excel" Prozess im Taskmanager. Mit jedem Programmstart wird es einer mehr! Wie kann ich das denn verhindern??


Anmelden zum Antworten