snehanshu
asked on
Creating good-looking Word files
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
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
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
C:\Program Files\Microsoft Office\Office10\1049
I will send you working examples too.
Regards Ferhad
ASKER
Thanks ferhad!
Working samples of each of the things in my wish-list above would be a just what I need.
...Shu
Working samples of each of the things in my wish-list above would be a just what I need.
...Shu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Add into uses list ComObj.
And one important thing type of the variable wrdApp is "Variant".
And one important thing type of the variable wrdApp is "Variant".
ASKER
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.Te xt) then
SaveFlNmDlg.InitialDir := FlNmBox.Text;
If SaveFlNmDlg.Execute Then
Begin
MyFlNm := SaveFlNmDlg.FileName;
Word := CreateOleObject('Word.Appl ication');
Word.Application.Visible := True;
Word.Documents.Add(EmptyPa ram, EmptyParam, EmptyParam, EmptyParam);
S := Word.Selection;
R := S.Range;
Sec := Word.Application.ActiveDoc ument.Sect ions.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).Shadin g.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;
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(
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.Te
SaveFlNmDlg.InitialDir := FlNmBox.Text;
If SaveFlNmDlg.Execute Then
Begin
MyFlNm := SaveFlNmDlg.FileName;
Word := CreateOleObject('Word.Appl
Word.Application.Visible := True;
Word.Documents.Add(EmptyPa
S := Word.Selection;
R := S.Range;
Sec := Word.Application.ActiveDoc
HdrTyp := wdHeaderFooterPrimary;
Hdr := sec.Headers.Item(HdrTyp);
rng := Hdr.Range;
rng.Select;
Word.Selection.TypeText( text := ' Snehanshu. Page ');
Word.Selection.Fields.Add(
Word.Selection.TypeText( text := ' of ');
Word.Selection.Fields.Add(
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, Format, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam);
R.Tables.Item(1).Rows.Item
Word.ActiveDocument.SaveAs
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
SaveChanges := wdPromptToSaveChanges;
Word.Quit(SaveChanges, EmptyParam, EmptyParam);
End;
end;
ASKER
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