• 用DDE控制Word


    DDE(Dynamic Data Exchange),称为动态数据交换。用于进程间的通讯,看看他如何来和Word交互。

    在System页签下有TDdeClientConv组件,拖一个放到界面上,然后我们写如下代码:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, OleServer, StdCtrls, DdeMan;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        DdeClientConv1: TDdeClientConv;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
    //执行word的宏命令
        procedure RunMacro(macname:PChar);
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    //执行保存文件的宏命令
      RunMacro('[FileSave]');
    end;
    
    procedure TForm1.RunMacro(macname: PAnsiChar);
    var
      macro: array [0..80] of char;
    begin
      //设置于word的连接
      DdeClientConv1.SetLink('WinWord','System');
      //打开连接
      if not DdeClientConv1.OpenLink then
      begin
        ShowMessage('打开连接出错!');
      end;
      if not DdeClientConv1.ExecuteMacro(macname,False) then
      begin
        ShowMessage('执行宏命令出错!');
      end;
    end;
    
    end.
    View Code
  • 相关阅读:
    Ubuntu 18.04.4 系统优化
    Ubuntu 18.04.4 LTS 更换国内系统源
    django 数据库迁移
    django2.0解决跨域问题
    python requests get请求传参
    python 常用排序方法
    python 电脑说话
    centos6.x配置虚拟主机名及域名hosts
    php 合并,拆分,追加,查找,删除数组教程
    PHP统计在线用户数量
  • 原文地址:https://www.cnblogs.com/key-ok/p/3428895.html
Copyright © 2020-2023  润新知