Solved

Creating good-looking Word files

Posted on 2004-04-15
6
1,255 Views
Last Modified: 2011-09-20
Hello!
  I need to create good-looking Doc files for my current project.
  I may need things like creating tables in the file, insert images, draw shapes etc.
  So, basically I need a list of commands I can use with OLE automation, and also some sample code (I haven't created word files using Delphi before).
  Looking forward to your help.
Thanks,
...Shu
0
Comment
Question by:snehanshu
  • 3
  • 3
6 Comments
 
LVL 5

Author Comment

by:snehanshu
ID: 10839883
Wow!
I got a sample fine now, and I would need the following:
* Writing in headers/footers of the word document
* Bulleting, tabs etc.
* Text boxes (and text inside them), other shapes (lines, circle)
* Tables (and formatting the table like background of first row, changing color of some cell etc.)
* Inserting images in the document as well as the header/footer
* Other goodies you can suggest

Please help!
Thanks,
...Shu
0
 
LVL 2

Expert Comment

by:ferhad
ID: 10840234
You can find the list of commands from vbawd10.chm file located in your system. Its located in the following path:
C:\Program Files\Microsoft Office\Office10\1049
I will send you working examples too.
Regards Ferhad
0
 
LVL 5

Author Comment

by:snehanshu
ID: 10840280
Thanks ferhad!
Working samples of each of the things in my wish-list above would be a just what I need.
...Shu
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 2

Accepted Solution

by:
ferhad earned 250 total points
ID: 10840476
The following code opens an existing *.doc file, creates table and inserts data into this table. Create *.doc file and call it Doc1. Wait new codes from me. They will come soon. :)

var pmainDir: string;
const wdLine = $00000005;
      FILE_REPORT = 'Doc1.doc';

pMainDir := ExtractFilePath(Application.ExeName);
wrdApp := CreateOleObject('Word.Application');
wrdApp.Application.Visible := True;
wrdApp.Application.WindowState := wdWindowStateMinimize;
wrdApp.Documents.Add(Template := pMainDir + FILE_REPORT);
wrdApp.Selection.Font.Bold := True;
wrdApp.Selection.Font.Size := 8;
wrdApp.Selection.Font.Name := 'Verdana Azeri Lat';

wrdApp.ActiveDocument.Tables.Add(wrdApp.Selection.Range, NumRows := 20, NumColumns :=8);
wrdApp.Selection.TypeText(Text := 'Name');
wrdApp.Selection.MoveRight(Count := 1);
wrdApp.Selection.TypeText(Text := 'Surname');
wrdApp.Selection.MoveRight(Count := 1);
wrdApp.Selection.TypeText(Text := 'Phone');
wrdApp.Selection.MoveRight(Count := 1);
wrdApp.Selection.TypeText(Text := 'Address');
wrdApp.Selection.MoveRight(Count := 1);
wrdApp.Selection.TypeText(Text := 'Mobil');
wrdApp.Selection.MoveRight(Count := 1);
wrdApp.Selection.TypeText(Text := 'Country');
wrdApp.Selection.MoveRight(Count := 1);
wrdApp.Selection.TypeText(Text := 'City');
wrdApp.Selection.MoveRight(Count := 1);
wrdApp.Selection.TypeText(Text := 'Zip Postal Code');
wrdApp.Selection.MoveDown(Unit := wdLine, Count := 1);
wrdApp.Selection.MoveLeft(Count := 8);
0
 
LVL 2

Expert Comment

by:ferhad
ID: 10840504
Add into uses list ComObj.
And one important thing type of the variable wrdApp is "Variant".
0
 
LVL 5

Author Comment

by:snehanshu
ID: 10841534
ferhad,
I am leaving for the day: will be only able to check things on Monday now.
Looking forward to more examples!
Thanks,
...Shu


P.S.
  Here's what I did so far: (Write to header and create a table)

procedure TAutoDocFOrm.FlNmBtnClick(Sender: TObject);
const
  Line1 = 'January,February,March';
  Line2 = '31,28,31';
  Line3 = '31,59,90';
var
  r,s,
  Direction, Separator, Format: OleVariant;

  Word, rng, Sec, Sel, HdrTyp, hdr: Variant;
  SaveChanges, MyFlNm: OleVariant;
  MyRange: Range;
begin
  If FileExists(FlNmBox.Text) then
    SaveFlNmDlg.FileName := FlNmBox.Text
  Else
  If DirectoryExists(FlNmBox.Text) then
    SaveFlNmDlg.InitialDir := FlNmBox.Text;
  If SaveFlNmDlg.Execute Then
  Begin

    MyFlNm := SaveFlNmDlg.FileName;

    Word := CreateOleObject('Word.Application');
    Word.Application.Visible := True;

    Word.Documents.Add(EmptyParam, EmptyParam, EmptyParam, EmptyParam);
    S := Word.Selection;
    R := S.Range;

    Sec := Word.Application.ActiveDocument.Sections.Item(1);
    HdrTyp := wdHeaderFooterPrimary;
    Hdr := sec.Headers.Item(HdrTyp);
    rng := Hdr.Range;

    rng.Select;
    Word.Selection.TypeText( text := ' Snehanshu. Page ');
    Word.Selection.Fields.Add(Range:= Word.Selection.Range , Type:=wdFieldPage);
    Word.Selection.TypeText( text := ' of ');
    Word.Selection.Fields.Add(Range:= Word.Selection.Range, Type:=wdFieldNumPages);
    R.Select;
    Direction := wdCollapseEnd;
    R.Collapse(Direction);
    R.InsertAfter(Line1);
    R.InsertParagraphAfter;
    R.InsertAfter(Line2);
    R.InsertParagraphAfter;
    R.InsertAfter(Line3);
    R.InsertParagraphAfter;
    Separator := ',';
    Format := wdTableFormatGrid1;
    R.ConvertToTable(Separator, EmptyParam, EmptyParam,
                     EmptyParam, Format, EmptyParam,
                     EmptyParam, EmptyParam, EmptyParam,
                     EmptyParam, EmptyParam, EmptyParam,
                     EmptyParam, EmptyParam);
    R.Tables.Item(1).Rows.Item(1).Shading.Texture := wdTexture5Percent;



    Word.ActiveDocument.SaveAs(MyFlNm, EmptyParam, EmptyParam , EmptyParam, EmptyParam,
    EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);

    SaveChanges := wdPromptToSaveChanges;
    Word.Quit(SaveChanges, EmptyParam, EmptyParam);



  End;


end;
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert a string into a TDateTime 5 63
Base1 Encode/Decode 3 81
Twebbrowser in Fire monkey android scrolling to bottom 1 44
Twebbrowser add css to the header 3 27
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question