|
! 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说明DescriptionApplication commands[app.activate]激活应用activate the application[quit]关闭应用quit the applicationWorkbook commands[activate("WorkbookName")]激活指定的文档activate a workbook[new(1)]新建一个 workbooknew a workbook[open("filepath.xlsx")]打开一个 workbookopen a workbook[save.as("test1.xlsx")]保存文档save as a workbook[close(false)]关闭文档close a workbook[file.close(false)]关闭文档close a workbookWorksheet commands[workbook.select("worksheetName")]激活一个 worksheetactivate a worksheet[workbook.insert(1)]新建一个 worksheetnew a worksheet[workbook.prev]移动到上一个 worksheetmove to the previous worksheet[workbook.next]移动到下一个 worksheetmove to the next worksheet[workbook.move("", "", 1)]移动一个 worksheetmove a worksheet[workbook.name("Sheet1", "SheetA")]命名一个 worksheetrename a worksheet[workbook.delete("Sheet1")]删除一个 worksheetdelete a worksheet[workbook.new]打开插入对话框open the insert dialogdata 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
- [edit.delete]: 下方的单元会上移。 ↩︎
- [paste]: 支持 Range 的粘贴。 ↩︎
来源:https://www.cnblogs.com/steven-yang/archive/2023/06/08/17466313.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作! |
|