ExcelDDECommands

博客 分享
0 316
张三
张三 2023-06-08 14:10:41
悬赏:0 积分 收藏

Excel DDE Commands

! https://zhuanlan.zhihu.com/p/635569763

Excel DDE Commands

连接参数

Application: Excel
Topic:
System: 整个应用。
[sheetname] 指定 worksheet。

我使用的是 .NET 组件 Specshell.NDde

		private DdeClient _ddeClient;
        public void Init()
        {
            try
            {
                _ddeClient = new DdeClient("EXCEL", "System");
                _ddeClient.Context.Encoding = System.Text.Encoding.Default;
                _ddeClient.Connect();
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }

	    public void Execute(string cmd, bool needEsc = false)
        {
            if (needEsc)
            {
                _ddeClient.TryExecute("[ESC]", 10);
            }
            _ddeClient.TryExecute(cmd, 5);
        }

	    public void Dispose()
        {
            try
            {
                _ddeClient?.Disconnect();
            }
            catch { }
        }

DDE commands

  • 命令大小写不敏感(case insensitivity)
  • 命令可以带括号,也可以不带括号
    [paste] = [paste()]
Command 说明 Description
Application commands
[app.activate] 激活应用 activate the application
[quit] 关闭应用 quit the application
Workbook commands
[activate("WorkbookName")] 激活指定的文档 activate a workbook
[new(1)] 新建一个 workbook new a workbook
[open("filepath.xlsx")] 打开一个 workbook open a workbook
[save.as("test1.xlsx")] 保存文档 save as a workbook
[close(false)] 关闭文档 close a workbook
[file.close(false)] 关闭文档 close a workbook
Worksheet commands
[workbook.select("worksheetName")] 激活一个 worksheet activate a worksheet
[workbook.insert(1)] 新建一个 worksheet new a worksheet
[workbook.prev] 移动到上一个 worksheet move to the previous worksheet
[workbook.next] 移动到下一个 worksheet move to the next worksheet
[workbook.move("", "", 1)] 移动一个 worksheet move a worksheet
[workbook.name("Sheet1", "SheetA")] 命名一个 worksheet rename a worksheet
[workbook.delete("Sheet1")] 删除一个 worksheet delete a worksheet
[workbook.new] 打开插入对话框 open the insert dialog
data commands
[clear] 清除当前选择的值 clear selection values
[copy] 复制。 copy selection values
[edit.delete][1] 删除当前选择的单元 delete selection values
[esc] 发送一个 Escape 键? send the escape key?
[insert(shiftDirectionAndMode)] 插入 insert
[paste][2] 粘贴 paste
[paste("R1C1")] 粘贴到指定的单元 paste to the cells
[select("R1C1")] 选择单元 select cells
[select("R1:R2")] 选择行 select rows
[select("R[1]:R[1]")] 相对位置,选择下一行 select a relative row
[select("R[1]")] 相对位置,选择下一行 select a relative row
[formula("=formula")] 设置值 set a value
[format.font("Verdana",12)] 设置字体 set font
[patterns(1,0,3)] 设置单元格式 set format of cells
[column.width(20,"c1:c2")] 设置列宽 set width of columns
[column.width(,"c1:c2",false,1)] 隐藏/显示列 hide/un-hide columns
[row.height(20,"r1:r2")] 设置列宽 set height of rows
[row.height(,"r1:r2",false,1)] 隐藏/显示行 hide/un-hide rows

  1. [edit.delete]: 下方的单元会上移。 ??

  2. [paste]: 支持 Range 的粘贴。 ??

posted @ 2023-06-08 14:04  SNYang  阅读(0)  评论(0编辑  收藏  举报
回帖
    张三

    张三 (王者 段位)

    921 积分 (2)粉丝 (41)源码

     

    温馨提示

    亦奇源码

    最新会员