Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 11.01.09 11:45 
Hallo.

Ich habe folgendes Problem:
Ich möchte für eine Art Report-Ausgabe Werte an Word übergeben. Das ganze geht auch recht gut mit folgendem Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
var
  FileName: OleVariant;
  vWhat, vBookmark, Marke: OleVariant;
begin
  FileName := ExtractFilePath(paramstr(0)) + 'marke.dot';
  WordApplication1.Connect;
  WordApplication1.Documents.OpenOld(FileName, EmptyParam, EmptyParam,
    EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
    EmptyParam, EmptyParam);
  WordDocument1.ConnectTo(WordApplication1.ActiveDocument);
  WordApplication1.Visible := True;
  vWhat:=wdGoToBookmark;
  vBookmark:='adresse';
  //WordDocument1.Bookmarks.Item(vBookmark).Range.InsertAfter('test');

  if WordDocument1.Bookmarks.Exists(vBookmark) then
  begin
    Marke := WordDocument1.Bookmarks.Item(vBookmark).Range;
    Marke.InsertAfter(memAdresse.Text);
  end;
end;
Sorry, dass der Code so gruslig ist, aber das ist nur zum Testen.
Mein Problem ist nun, dass Word diese Dot-Datei öffnet und nicht ein neues, ungespeichertes Dokument draus macht. Wenn also jetzt der Anwender auf Speichern klickt, überschreibt er die Dot-Datei.
Wie kann ich das umgehen? Ich würde mir irgendwas vorstellen, dass eine Word-Datei geöffnet wird, aber wie eine neue Datei behandelt wird.
Geht das?

Danke,
Matze

_________________
In the beginning was the word.
And the word was content-type: text/plain.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 14.01.09 10:13 
*push* Ist mein Problem unverständlich, oder weiß niemand eine Lösung?

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mi 14.01.09 10:19 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  FileName: OleVariant;
  vWhat, vBookmark, Marke: OleVariant;
begin
  FileName := ExtractFilePath(paramstr(0)) + 'marke.dot';
  WordApplication1.Connect;
  WordApplication1.Documents.OpenOld(FileName, EmptyParam, EmptyParam,
    EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
    EmptyParam, EmptyParam);

{Ich vermute hier liegt der Hund begraben. Statt Documents.OpenOld musst Du vermutlich Document.AddOld verwenden}
[snip]


Edit: Vermutlich ist es besser, Documents.add zu verwenden.
Siehe auch hier:
msdn.microsoft.com/d...ents.add(VS.80).aspx

Gruß,
Jens

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)


Zuletzt bearbeitet von Nersgatt am Mi 14.01.09 10:23, insgesamt 1-mal bearbeitet
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 14.01.09 10:22 
Hui. Das ging ja flott! :zustimm:
Nur leider habe ich jetzt kein Delphi da um es zu testen :-( Aber ich denke ich komme heute Abend noch dazu!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Sa 17.01.09 14:54 
SO jetzt bin ich mal dazu gekommen das zu testen.
Wie muss ich denn AddOld aufrufen, damit das funktioniert? Mein Delphi meckert, dass die Parameter nicht stimmen, ich kann aber auch keine Doku finden, wie das richtig sein muss...

_________________
In the beginning was the word.
And the word was content-type: text/plain.
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Sa 17.01.09 16:45 
das funktioniert bei mir so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
// Open document with template
function TStartWordDocument.fnStartDocument: Boolean;
var
  vTemp: OleVariant;
  vTemp1: OleVariant;
  vDocType: OleVariant;
begin
  try
    vTemp:= stTemplateName; // template name, e.g. normal.dot
    vTemp1:= true;
    vDocType:= wdTypeDocument;
    WordApplication.Connect;
    WordApplication.Documents.Add(vTemp,emptyParam,vDocType,vTemp1);
    WordDocument.ConnectTo(WordApplication.ActiveDocument);
    WordDocument.PageSetup.Orientation:= wdOrientPortrait;
    WordDocument.ActiveWindow.ActivePane.View.Zoom.Percentage:= 100;
    Result:= True;
  except
    Result:= False;
  end;
end;


:-)Msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
Chemiker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 194
Erhaltene Danke: 14

XP, Vista 32 Bit, Vista 64 Bit, Win 7 64 Bit
D7, BDS 2006, RAD Studio 2009+C++, Delphi XE2, XE3, VS 2010 Prof.
BeitragVerfasst: Sa 17.01.09 18:09 
Hallo matze,

Zitat:
Mein Delphi meckert, dass die Parameter nicht stimmen, ich kann aber auch keine Doku finden, wie das richtig sein muss...

Ich vermute, dass Nersgatt eine andere Word-Version benutzt als Du. Dann meckert Delphi die unterschiedlichen Parameter an.
Wenn Du die Hilfe von Word aufrufst und die Befehle nachschaust die Du einsetzt, so müssen die Parameter angepasst werden.

Bis bald Chemiker
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Sa 17.01.09 18:14 
du kannst in D zwei Versionen von Word verwenden: Word2000.pas und WordXP.pas
Je nach dem was du in der Installation angegeben hast.

Die Aufrufkonventionen sind zwischen beiden Versionen unterschiedlich. Das o.g. verwendet
WordXP.pas.

Ab D2009 musst du dann var Parameter übergeben.

:-)Msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 18.01.09 15:13 
Hallo ihr alle!

Vielen vielen Dank für eure Hilfe. Der Code von user profile iconMSCH war goldrichtig. Es funktioniert. Das mit den unterschiedlichen Wordversionen wusste ich schon. Da habe ich auch die richtige installiert.

Für die die es interessiert und für dich Nachwelt hier mein Code, der eine .dot Datei startet und darin einen Text bei einer Marke einfügt:
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:
var
  vTemp: OleVariant;
  vTemp1: OleVariant;
  vDocType: OleVariant;
  vWhat: OleVariant;
  vBookmark: OleVariant;
  Marke: OleVariant;
begin
  try
    vTemp:= ExtractFilePath(paramstr(0)) + 'marke.dot'// template name, e.g. normal.dot
    vTemp1:= true;
    vDocType:= wdTypeDocument;
    WordApplication.Connect;
    WordApplication.Documents.Add(vTemp,emptyParam,vDocType,vTemp1);
    WordDocument.ConnectTo(WordApplication.ActiveDocument);
    WordApplication.Visible := true;
    WordDocument.ActiveWindow.ActivePane.View.Zoom.Percentage:= 100

    // Jetzt die Bookmarks ersetzen:
    vWhat:=wdGoToBookmark;
    vBookmark:='adresse';
    if WordDocument.Bookmarks.Exists(vBookmark) then
    begin
      Marke := WordDocument.Bookmarks.Item(vBookmark).Range;
      Marke.InsertAfter(memAdresse.Text);
    end;
    Result:= True;
  except
    Result:= False;
  end;
end;


Eine Frage bleibt aber noch:
user profile iconMSCH hat folgendes geschrieben Zum zitierten Posting springen:
Ab D2009 musst du dann var Parameter übergeben.

Kannst du bitte mal ausführlich erklären, was du meinst... Denn ich werde mir demnächst D2009 zulegen, da ist das nicht ganz uninteressant!

Nochmal: Vielen Dank an alle!

Euer Matze

_________________
In the beginning was the word.
And the word was content-type: text/plain.