Autor Beitrag
Mike_C
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: Do 05.08.04 10:47 
Servus!

ich habe ein Problem mit den Office-Komponenten von Delphi (im speziellen Fall mit den Komponenten für den Zugriff auf Word):
mit einer kleinen Anwendung möchte ich den Text aus einem Memo in ein Word-Dokument schreiben und dieses speichern. Word starten und das Dokument schreiben ist kein problem, aber das speichern funktioniert nicht.
Aus der Word-Hilfe habe ich mir abgeschaut, wie die SaveAs-Funktion aussieht und welche Werte übergeben werden und habe versucht das nach zu programmieren, ohne Erfolg. :? hier mein versuch:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm1.Button2Click(Sender: TObject);
var Filename, FileFormat, LockComments, Password,
    AddToRecentFiles, WritePassword, ReadOnlyRecommended,
    EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData,
    SaveAsAOCELetter, Encoding, InsertLineBreaks, AllowSubstitutions,
    LineEnding, AddBiDiMarks: OLEVariant;

begin
  Filename := 'Testdocument.doc';
  FileFormat := wdFormatDocument;
  LockComments := False;
  Password := '';
  AddToRecentFiles := False;
  WritePassword := False;
  ReadOnlyRecommended := False;
  EmbedTrueTypeFonts := False;
  SaveNativePictureFormat := False;
  SaveFormsData := False;
  SaveAsAOCELetter := False;
//  Encoding := msoEncodingCentralEuropean;  //Konstanten werden von Delphi nicht gefunden ?!
  InsertLineBreaks := TRUE;
  AllowSubstitutions := True;
  LineEnding := wdCRLF;
  AddBiDiMarks := False;

  WordApplication1.ActiveDocument.SaveAs(Filename, FileFormat, LockComments,
  Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts,
  SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter, Encoding, InsertLineBreaks,
  AllowSubstitutions, LineEnding, AddBiDiMarks);

  WordApplication1.Quit;
end;


Ich bekomme mit diesem Code immer eine EOLEException mit der Nachricht "Typkonflikt". Hat es jemand schonmal geschafft, erfolgreich ein Word-Dokument auf ähnliche Weise zu speichern? Word sollte dabei nicht veranlasst werden seinen SaveDailog zu öffnen!

Danke schonmal für eure Hilfe

Gruß
Mike_C

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 05.08.04 18:02 
Hallo

du brauchst nicht alle Parameter zu füllen, gugg in die VB-Hilfe, dort wo "optional" steht, reicht auch ein emptyparam.

Zitat:

// Encoding := msoEncodingCentralEuropean; //Konstanten werden von Delphi nicht gefunden ?!

im verzeichnis Delphi/ocx/servers/ liegen die Source-dateien zu den servern. msoEncodingCentralEuropean ist in Office97/2000.pas definiert, die mit in die usesliste rein und schon gehts.

Die Methoden sind meist overloaded, es reicht ein
ausblenden Delphi-Quelltext
1:
2:
        Ole_filename:=def_directory+'\temp\Sendungsdaten.doc';
        WordDocument1.SaveAs(ole_filename);


Ansonsten kommt mir deine Parameterliste eh recht lang vor, woher hast du die?

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Mike_C Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: Do 05.08.04 18:16 
Also die Parameterliste habe ich aus der Word-Hilfe. Nebenbei: wenn du die Delphi-Komponenten verwendest, wird dir auch die Parameterliste angezeigt, wie normale Parameter einer Funktion :)

Hmm. also also ich versucht habe, einzelne Parameter weg zu lassen (was anderes ist emptyparam ja nicht oder?), hat Delphi die Fehlermeldung "Not enough actual parameters." rausgegeben.
Naja, mal sehen, ob ich noch irgendwie hinbekomme...

edit: Die Encoding-Konstanten sind bei mir in "$DelphiDir$\ocx\server\officexp.pas" gespeichert.

Gruß
Mike_C

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 05.08.04 18:24 
Zitat:

Nebenbei: wenn du die Delphi-Komponenten verwendest, wird dir auch die Parameterliste angezeigt, wie normale Parameter einer Funktion

das weiß ich, nur gehen die bei mir nur bis SaveAsAOCELetter,sonst hätt ich nicht gefragt. (ich nutze die office2K-server).

Zitat:

Hmm. also also ich versucht habe, einzelne Parameter weg zu lassen

nein, du sollst das hinschreiben (savesas(dateiname,emptypraram,emptypraram,...)

aber wie gesagt, obiges codebsp funktioniert bei mir auch. Es ist allerdings für ein worddocument, nicht activedocument.

mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Mike_C Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: Do 05.08.04 18:31 
*g* auf die sache mit den Emptyparam's bin ich auch grade gekommen, ich meine, dass ich die hinschreiben muss :oops:

naja und wenn ich alle parameter (außer filename) mit emptyparam angebe, funktioniert es bei mir mit nem activedocument. dein code funktioniert mit nem activedocument nicht.

trotzdem thx
Mike_C

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 05.08.04 18:49 
Zitat:

dein code funktioniert mit nem activedocument nicht.

das kann sein, das die overloaded-methoden nur beim worddoc dabei sind, zieh noch ein worddocument auf die Form, stell autoconnect auf false,

ausblenden Delphi-Quelltext
1:
2:
3:
4:
WordDocument1.ConnectTo(WordApplication1.activeDocument);
Ole_filename:=def_directory+'\temp\Sendungsdaten.doc';  
WordDocument1.SaveAs(ole_filename); 
WordDocument1.disconnect;


M;fg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Mike_C Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: Do 05.08.04 19:21 
thx, das scheint zu funzen

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?