去servers控件板上看看,导出word文档去SMExport控件板看看

解决方案 »

  1.   

    procedure TForm1.SaveDocument;
    var
      FileName, FileFormat, LockComments, Password,
      AddToRecentFiles, WritePassword, ReadOnlyRecommended,
      EmbedTrueTypeFonts, SaveNativePictureFormat,
      SaveFormsData, SaveAsAOCELetter :olevariant;
    begin
      FileName := 'd:\2.doc';
      FileFormat := wdFormatDocument;
      LockComments := false;
      Password := '';
      AddToRecentFiles := false;
      WritePassword := '';
      ReadOnlyRecommended := false;
      EmbedTrueTypeFonts := false;
      SaveNativePictureFormat := false;
      SaveFormsData := false;
      SaveAsAOCELetter := false;  worddocument.SaveAs(FileName, FileFormat, LockComments, Password,
                          AddToRecentFiles, WritePassword, ReadOnlyRecommended,
                          EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData,
                          SaveAsAOCELetter);
    end;
    procedure TForm1.RepalceString;
    //让word替换标记字符串要使用worddocument.range.find.execute,这里用delphi替换了<#name>:
    var
    //一共15个参数
      findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
      matchallwordforms, forward1, wrap, format, replacewith, replace,
      MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl : olevariant; //后四个均为可选项,默认false  num : olevariant;
    begin
      findtext := '数据上报操作说明';
      matchcase := false;
      matchwholeword := true;
      matchwildcards := false;
      matchsoundslike := false;
      matchallwordforms := false;
      forward1 := true;
      wrap := wdfindcontinue;
      format := false;
      replacewith := 'delphi';
      replace := true;
      MatchKashida := false;
      MatchDiacritics := false;
      MatchAlefHamza := false;
      MatchControl := false;//  num := 1;
    //  WordApplication.Documents.Item(num);
      worddocument.ConnectTo(WordApplication.ActiveDocument);
      worddocument.range.find.execute( findtext, matchcase, matchwholeword,
                                       matchwildcards, matchsoundslike, matchallwordforms,
                                       forward1, wrap, format, replacewith, replace,
                                       matchKashida, MatchDiacritics,
                                       MatchAlefHamza, MatchControl );
    end;
    procedure TForm1.OpenDocument;
    var
      FileName : OleVariant;
    //Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument,
    //PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format,
    //Encoding, Visible)
    begin
      FileName := 'd:\2.doc';  try
        WordApplication.Documents.Open(FileName, EmptyParam, EmptyParam, EmptyParam,
                                       EmptyParam, EmptyParam, EmptyParam, EmptyParam,
                                       EmptyParam, EmptyParam, EmptyParam, EmptyParam);
      except
        showmessage('该文件不存在!')
      end;
    end;
    procedure TForm1.CloseWord;
    var
      savechanges, originalformat, routedocument: olevariant;
    begin
      savechanges := wdSaveChanges;
      originalformat := unassigned;
      routedocument := unassigned;
      try
        wordapplication.quit(savechanges, originalformat, routedocument);
        wordapplication.disconnect;
      except
        on e: exception do
      begin
        showmessage(e.message);
        wordapplication.disconnect;
      end;
      end;
    end;
    procedure TForm1.startword;
    begin
      if (wordapplication.Documents.Count <> 0 ) then
      begin
        messagedlg('请先关闭word!', mterror, [mbok], 0);
        exit;
      end;  try
        wordapplication.connect;
      except
        messagedlg('word 没有正确安装', mterror, [mbok], 0);
        abort;
      end;
      wordapplication.visible := true;
      wordapplication.caption := 'delphi automation';
    end;