【问题标题】:Save Word files as DOCX using SAS DDE使用 SAS DDE 将 Word 文件另存为 DOCX
【发布时间】:2019-05-25 21:51:27
【问题描述】:

我使用的是 SAS v9.4

我正在尝试编写一个宏来读取单词模板,进行一些修改,然后将新文档保存为 .docx 文件。我已经设法让它工作以保存到 .doc 文件,但是当我更改扩展名时,我收到以下错误:

文件类型和文件扩展名不兼容

有谁知道我如何将文件保存为 docx 或者这是否可能? 任何帮助将不胜感激

代码如下:

filename sas2word dde 'winword|system';

 %macro setupWd(outfile);
   options noxsync noxwait xmin;

   /* Open Blank Word Document */
   data _null_; 
     length fid rc start stop time 8;
     fid=fopen('sas2word','s');
     if (fid le 0) then do;
        rc=system('start winword');
        start=datetime();
        stop=start+1;
     do while (fid le 0);
        fid=fopen('sas2word','s');
        time=datetime();
        if (time ge stop) then fid=1;
        end;
     end;
     rc=fclose(fid);
   run;

   /* Save to given location */
   data _null_; 
     file sas2word;
     put '[FileSaveAs.Name="' "&outfile" '",.Format=0]';
   run;
%mend setupWd;

作品:

%setupWd(outfile = M:\SAS\Output\MacroTest.doc)

不起作用:

%setupWd(outfile = M:\SAS\Output\MacroTest.docx)

【问题讨论】:

  • 仅更改名称不会更改文件格式。您正在调用的 FileSaveAs 方法的 FORMAT= 选项的可能值是什么?
  • 这是一个很好的观点,老实说不知道选项是什么。 SAS 不是对谷歌最友好的语言,但我会继续尝试:P
  • 不是 SAS 问题。这是 SAS 代码调用的 WORD 函数。
  • 是的,soz,不知道哪个最好标记,所以我两个都做了
  • DDE 已经过时,不应该使用。改用完全可在 Google 上搜索的 VB 脚本。 DDE 对 Google 不友好,因为它早于 Google。

标签: ms-word sas


【解决方案1】:

重写不带格式选项的保存位:

data _null_; 
   file sas2word;
   put '[FileSaveAs.Name="' "&outfile" '"]';
run;

另外,格式选项(如果有人想知道的话)是:

Format = 0: .doc
Format = 1: .dot
Format = 2: .txt

获取.docx的唯一方法是将其放在文件路径名中,不指定格式

【讨论】:

  • 谢谢大家!此外,您对他们的人数越高,他们在 2 之后都只是 .txt
  • DOCX 不是一个选项,因为 DDE 和这种类型的命令早于 DOCX 的存在。
猜你喜欢
  • 1970-01-01
  • 2015-06-13
  • 2012-08-16
  • 2019-05-28
  • 2016-11-20
  • 1970-01-01
  • 1970-01-01
  • 2016-01-02
  • 1970-01-01
相关资源
最近更新 更多