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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
var
oDocType: OleVariant;
oTableB: OleVariant;
oFitB: OleVariant;
oCount: OleVariant;
oExtend: OleVariant;
iRows, iCols: integer;
// avec le composant serveur WordApplication
with WAp do begin
// En premier lieu il faut tester si Word existe
TRY
Connect := true;
Visible := true; // word visible
oDocType := 0;
Documents.Add(EmptyParam, EmptyParam, oDocType, Emptyparam); // New Doc
if Wap.Documents.Count = 0 then begin
ShowMessage('Pas de Document Word vierge chargé !');
WAp.DDETerminateAll; // déconnexion de Word
Exit;
end;
if ActiveWindow.View.SplitSpecial = wdPaneNone then
ActiveWindow.ActivePane.View.type_ := wdNormalView
else
ActiveWindow.View.type_ := wdNormalView;
EXCEPT
MessageDlg('Word n''est pas installé ou indisponible !', mtError, [mbOk], 0);
END;
// nouveau paragraphe
Selection.InsertParagraphAfter;
// retour à la ligne
Selection.TypeParagraph;
// crée 1 tableau
iRows := 2; // nb colonnes
iCols := 5; // nb lignes
oTableB := wdWord9TableBehavior;
oFitB := wdAutoFitFixed; // dimension perso, pour Automatic = wdAutoFitContent
// créer le tableau et se positionner dans la 1ère ligne / colonne
ActiveDocument.Tables.Add(Selection.Range, iRows, iCols, oTableB, oFitB);
// Attributs de la colonne
Selection.SelectColumn; // celle en cours
Selection.Columns.PreferredWidthType := wdPreferredWidthPoints;
Selection.Columns.PreferredWidth := CentimetersToPoints(1.5);
Selection.Cells.VerticalAlignment := wdCellAlignVerticalCenter;
// on peut aussi utiliser pour la colonne ref par iCols
iCols = 1
Selection.Tables.Item(iCols).Columns.PreferredWidth := CentimetersToPoints(1.5);
Selection.Tables.Item(iCols).AllowAutoFit := false;
// insérer une ligne
oRows := 1;
TRY
Selection.InsertRowsAbove(oRows);
EXCEPT
oUnit := wdLine;
oCount := 1;
oExtend := wdMove;
Selection.MoveUp(oUnit, oCount, oExtend);
Selection.InsertRowsAbove(oRows);
END;
// se déplacer
oUnit := wdCharacter; // se déplacer d'un caractère, si vide = change de cellule
oCount := 1; // nb de cellule
oExtend := wdExtend;
Selection.MoveRight(oUnit, oCount, oExtend); // à droite
Selection.MoveLeft(oUnit, oCount, oExtend); // à gauche
// possible aussi
oUnit := wdColumn; // change colonne
oCount := 1; // Nb de cellule
Selection.Move(oUnit, oCount);
// par ligne
oUnit := wdLine; // mode ligne
oCount := 1;
Selection.MoveDown(oUnit, oCount, oExtend); // en bas
Selection.MoveUp(oUnit, oCount, oExtend); // en bas
// remplir ligne 1
Selection.TypeText('Cellule 1.1'); // écrire
// pour modifier des cellules, on peut utiliser aussi
Selection.Tables.Item(1)...
// définir les attributs du texte
with Wap.Selection.Font do begin
Name := 'Arial';
Size := 10;
Bold := 1; // gras activé
Italic := 0;
Underline := 0;
UnderlineColor := wdColorAutomatic;
StrikeThrough := 0;
DoubleStrikeThrough := 0;
Outline := 0;
Emboss := 0;
Shadow := 0;
Hidden := 0;
SmallCaps := 0;
AllCaps := 0;
Color := clBlue; // en bleu
Engrave := 0;
Superscript := 0;
Subscript := 0;
Spacing := 0;
Scaling := 100;
Position := 0;
Kerning := 0;
Animation := wdAnimationNone;
end;
// aller en fin de document
oUnit := wdStory;
oExtend := wdMove;
Selection.EndKey(oUnit, oExtend);
oType := wdPageBreak;
Selection.InsertBreak(oType); |
Partager