Re: Delphi problem with font in Word document

Posted by DelphiLand Team on August 21, 2005

In Reply to: Delphi problem with font? posted by greenfrog on August 19, 2005

: I used worddocument to write a text line to word (in russian), word file was created but when i opened it didn't display the right letters(russian).
This problem didn't happen when i tried to use wordapplication to copy this text from another word file and then paste it by worddocument.

First solution:
Modify "Normal.dot". The template Normal.dot is the basis for each new Word document. If there's a setting you'd like to change for all of your new documents -- for example, the default font or point size -- Normal.dot is the file to modify. These changes will apply to every document you create afterwards.

Example for changing the default font:
1. Find Normal.dot on your system. Where it's located depends upon your Windows configuration.
2. RIGHT-click its icon and choose Open (if you simply double-click, Windows opens a blank document based on the template instead of opening the .dot file itself).
3. Change the default font: simply choose a font it in the font drop-down list
4. Save Normal.dot, making sure to use the .dot file extension.

Second solution:
Just create a document and afterwards, just before saving it, change the font of the entire document. Example of Delphi code that I tested succesfully:

procedure TForm1.Button1Click(Sender: TObject);
var
  WordApplication, WordDocument: variant;
begin
  WordApplication := CreateOleObject('Word.Application');
  WordDocument := WordApplication.Documents.Add;
  WordApplication.Selection.TypeText('This is a line of text.');
  // Change font of entire document:
  WordDocument.Content.Font.Name:= 'Courier New';
  WordDocument.SaveAs(FileName := 'C:\Test\CourierNew.Doc',
    AddToRecentFiles := False);
  WordApplication.Quit(False);
end;

Can you let us know if it worked? Thanks!
John, DelphiLand Team

Related Articles and Replies