请问如何在delphi操作word时设置缩进????????????????????????如何设置整个文本或某一段落的右缩进和左缩进请各位高手给出详细的代码!!谢谢!!

解决方案 »

  1.   

    只能给个方向...
    1.用 TWordApplication、TWordDocument
    2.到 Word 里录制 Macro,然后看它 VBA 怎幺写的
    3.回 Delphi 中设置参数,传入 Selection.ParagraphFormat关键方法是 Selection.ParagraphFormat
    关键参数是 CharacterUnitLeftIndent, CharacterUnitRightIndent我手边没有左右缩进的例子,但我前个项目(从题库表中输出考卷到 Word)用到前后段落间距,也是用到ParagraphFormat。大约是这样的码,你自己改参数试试。
    其中有些是像是 DoEndKey 是我自己写的 procedure,用来控制目前打字输出的位置,让它常保在最后。waMain 是 TWordApplication。procedure TfmRender.DoHeader;
    begin
      with waMain.Selection, adotblPaper do
      begin
        TypeText(FieldByName('School').AsString + ' ');
        TypeText(FieldByName('Term').AsString + ' ');
        TypeText(FieldByName('Subject').AsString + ' ');
        TypeText(FieldByName('Time').AsString + ' ');
        TypeText(FieldByName('Exam').AsString);
        TypeParagraph;    ParagraphFormat.LineUnitBefore := 0.5;
        ParagraphFormat.SpaceBefore := 2.5;
        TypeText('命题老师:' + FieldByName('Teacher').AsString + ' ');
        TypeText(FieldByName('Class').AsString);
        TypeParagraph;
        DoEndKey(wdStory);
      end;
    end;