Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Also, ich versuche auf Excel zugreifen durch die Automatisierungsschnittstelle.

Die Automatisierungsschnittstelle habe ich mit dem Klassenassistenten hinzugefügt

( XL5EN32.OLB )

In meine cpp Datei include ich

#include "xl5en32.h"

#include "excel.h"

Wenn ich jetzt dass nur schreibe

_Application app;

Kriege folgenden Fehler:

error C2065: '_Application' : nichtdeklarierter Bezeichner

Weis jemand warum ?????

Da noch den ganzen Code


#include "stdafx.h"
#include "Excel.h"

#include "xl5en32.h"
#include "excel.h"




#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Das einzige Anwendungsobjekt

CWinApp theApp;

using namespace std;
//using namespace Excel;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// MFC initialisieren, Ausgabe und Fehlermeldung bei Fehlern
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
nRetCode = 1;

_Application app; // Hier kriegei ich den Fehler

/* if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox(
"Couldn't start Excel and get an application 0bject");
return;
}
*/


return nRetCode;
}
[/PHP]

  • Autor

also ich habe auch mit

using namespace Excel;

aber sobald ich es schreibe kriege ich Fehler

error C2871: 'Excel' : Existiert nicht oder ist kein Namespace

Das kommische daran ist, wenn ich es so versuche zu schreiben

Excel::ApplicationPtr p;

dann bei doppelklick wurde ApplicationPtr soger aufgelistet, leider Fehler ist gleich ;(

  • Autor

mein Problem liegt glaube ich wo anders, denn ich kann mal nich die

#include "excel.h" öffnen.

Kann es sein das bei mir SP fehlt oder die instalation ist falsch bzw. nicht vollständig gemacht ?

  • Autor

Erst mal Vielen Dank

Gut, also ich habe jetzt alles von Anfang an gemacht.

Neues Testprojekt die Datei (XL5EN32.OLB) per import angebunden.

Dann nachgeschaut wie VS die erstellte Dateien nennt und die einschließlich auch dann habe ich includet (#include "xl5en32.h")

und dann im main einfach

Application pEx;

deklariert und es funk. ;)

Hm jetzt versuche ich Excel ansprechen und par Daten einfügen.

Mal schauen ob es mir geling. ;)

PS.

Was ich aber nicht verstehe ist, warum wenn ich

Excel::

schreibe listet er mir die ganze Funktionen usw.

Servus,

weiss jemand wo ich eine gute Dokumentation oder ein Tutorial zur Office Automatisierungsschnittstelle bekomme? (abgesehen von MSDN).

Ich habe bisher mit 'CSpreadsheet' gearbeitet, da gibt es jedoch Probleme mit

Format der Daten. Mit Spreadsheet kann ich nur Daten im Form von 'Text'.

verarbeiten.

Ciao TinTin

  • Autor

Und da sind die ersten Probleme:


HRESULT hRes = CoInitialize(NULL);
if (FAILED(hRes))
return -1;

Application pXL;

Workbooks books;
Worksheets sheets;
Range range_group;

LPDISPATCH lpDisp;

COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covfilename((CString)TRUE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

covfilename = "C:\\test.xls";

try{
// Starten von Excel
pXL.CreateDispatch("Excel.Application");

// Set visible.
pXL.SetVisible(covTrue);

lpDisp = pXL.GetWorkbooks();

books.AttachDispatch( lpDisp );
lpDisp = books.Open(covfilename,covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional);




}catch(COleException& e)
{
TCHAR sz[1024];
e.GetErrorMessage(sz, 1024);
}
[/PHP]

Fehler

[b]error C2039: 'GetWorkbooks' : Ist kein Element von 'Application'[/b]

Ist auch klar, nur im MSDN Beispiel

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q178783

Wurde es eben so gemacht ;(

Wie kann ich es überhaupt umgehen?

  • Autor
Servus,

weiss jemand wo ich eine gute Dokumentation oder ein Tutorial zur Office Automatisierungsschnittstelle bekomme? (abgesehen von MSDN).

Ciao TinTin

wurde mich auch interessieren :confused:

Benutzt CSpreadsheet nicht ODBC ???

jau, ganz genau! aber man kann nur Daten im Textformat behandeln

(oder ich mache etwas falsch, ich glaube jedoch so was gelesen zu haben.).

CSpreadsheet

@BIgPoint:

Hast du denn schon eine Exceldatei öffnen, anlegen oder ändern können?

Wenn ja, hast du eventuell ein wenig Bsp.Code?

:floet:

Ciao TinTin

Ich habe bisher mit 'CSpreadsheet' gearbeitet..

'gearbeitet' ist etwas zuviel des Guten, sagen wir gebastelt ...

:floet:

error C2039: 'GetWorkbooks' : Ist kein Element von 'Application'

Ist auch klar, nur im MSDN Beispiel

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q178783

Wurde es eben so gemacht ;(

Wie kann ich es überhaupt umgehen?

Ich hab genau das Beispiel benutzt und vorher

das hier... nachvollzogen.

welche *.olb hast du denn benutzt?

ich hab office2000 auf dem Rechner und die excel8.olb eingebunden,

den code kopiert, noch ein paar office2000 speziefische änderungen gemacht (Argumente gelöscht und Kommata hinzugefügt, die MS vergessen hatte), und

dann lief der Spass.

Ciao TinTin

Select the Automation tab. Click Add Class and choose "From a type library." Navigate to select the object library for the application you wish to automate (for this example, if you are automating Excel 97, choose the Microsoft Excel 8.0 Object Library; the default location is C:\Program Files\Microsoft Office\Office\Excel8.olb).

If you are automating Microsoft Excel 2000, choose Microsoft Excel 9.0 Object Library for which the default location is the C:\Program Files\Microsoft Office\Office\Excel9.olb.

If you are automating Microsoft Excel 2002 and Microsoft Office Excel 2003, the object library is embedded in the file Excel.exe. The default location for Excel.exe in Office 2002 is C:\program Files\Microsoft Office\Office10\Excel.exe. The default location for Excel.exe in Office 2003 is C:\program Files\Microsoft Office\Office11\Excel.exe. Once you have selected the appropriate object library, click Open. Select all classes in the Confirm Classes list, and then click OK.

NOTE: The list box in the Confirm Classes dialog box contains all of the IDispatch interfaces (which are virtually identical to classes) in the Microsoft Excel type library. In the lower half of the dialog box you will see that an Implementation file named Excel8.cpp contains generated class wrappers derived from ColeDispatchDriver(), and the appropriate declaration header file is named Excel8.h. (For Excel 2002 and Excel 2003, the files are named Excel.cpp and Excel.h.)

hier stehts dann nochmal drin.

  • Autor

@BIgPoint:

Hast du denn schon eine Exceldatei öffnen, anlegen oder ändern können?

Wenn ja, hast du eventuell ein wenig Bsp.Code?

:floet:

Ja , genau diesen MSDN Beispiel zeigt wie es funktioniert.

Was ich noch leider nicht weiß ist:

• Wie ich eine Tabelle umbenennen bzw. ein Name vergeben kann.

• Wie ich spalten Formatieren kann.

• Wie ich den Text Formatieren kann ( Fett, Schriftart, usw.)

  • Autor

da bin ich wieder,

ich versuche jetzt das ganze mit Hilfe von RegisterXLL zu regiestieren.

Leider liefert die Funktion RegisterXLL 0 also ist falsch gelaufen

Da den cod


int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// MFC initialisieren, Ausgabe und Fehlermeldung bei Fehlern
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// ZU ERLEDIGEN: Fehlercode gemäß Ihren Anforderungen ändern
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
HRESULT hRes = CoInitialize(NULL);
if (FAILED(hRes))
return -1;


LPCSTR strfilename;
strfilename = "test.xll";

try
{
_Application app; // app is an _Application object.
_Workbook book; // More object declarations.
_Worksheet sheet;
Workbooks books;
Worksheets sheets;

Range range; // Used for Microsoft Excel 97 components.
LPDISPATCH lpDisp; // Often reused variable.

// Common OLE variants. Easy variants to use for calling arguments.
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

// Start Microsoft Excel, get _Application object,
// and attach to app object.
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't CreateDispatch() for Excel");
return -1;
}


// Set visible.
app.SetVisible(TRUE);


//app.SaveWorkspace(COleVariant(strfilename));

if(!app.RegisterXLL(strfilename))
AfxMessageBox("Didn't register the test.xll"); // Hier rutsche ich rein ;(
[/PHP]

Hiiiiiiiiiiiiilffffffffffe !!!

Huhu bigpoint :D

Was ich noch leider nicht weiß ist:

• Wie ich eine Tabelle umbenennen bzw. ein Name vergeben kann.

• Wie ich spalten Formatieren kann.

• Wie ich den Text Formatieren kann ( Fett, Schriftart, usw.)

Das fragst ansich fast besser im Basic Forum, denn den VBA`lern ist das Objektmodel von Excel gelaeufiger.

In der Not antworte ich aber auch hier, wenn ich n bissl Zeit hab. ;)

if(!app.RegisterXLL(strfilename))

AfxMessageBox("Didn't register the test.xll"); // Hier rutsche ich rein ;(

Hast das denn auch schonmal direkt im VB-Editor vom Excel erfolgreich probiert?

Goos

  • 2 Wochen später...
  • Autor

Also ich habe geschafft in Excel was zu schreiben, jetzt will ich noch lesen können.

Einen Satz zu lesen ist ja auch kein Problem


lpDisp = sheet.GetRange(COleVariant("H1"), COleVariant("H1"));
COleVariant va;
va = range.GetText();
[/PHP]

Wie bekomme ich aber das Anzahl von Datensetzen die in Spalte H stehen ?

Woher weis ich wo die Spalte H anfängt ( ob H1 oder H100 ) ??

Ich habe schon alles mögliche mit dem Range ausprobiert komme leider nicht drauf ;(

  • Autor

Ich konnte mir eine schleife bauen und in der schleife überprüfen ob in der Spalte was drin steht und wenn nicht als ende betrachten.

Mein Problem ist das es eben lehre Spalten vorkommen können ;( und das ich nicht weis wo die Daten in der Excel Tabelle anfangen , ich kenne nur die Spaltename ( H ).

Ich habe auch mit der Funktion GetUsedRange(); versucht es zu machen

range = sheet.GetUsedRange();

// Maximum und Minimum von Column ermitteln
long startcol,endcol;
startcol=range.GetColumn();
range1=range.GetEnd(-4161);
endcol=range1.GetColumn();[/PHP]

Hat aber auch nicht geklappt

Hat hier wirklich keiner so was gemacht ;(

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.