楼主: Imasasor
7054 24

[问答] 如果批量将excel 2007变成excel 2000,如何导入一个excel的多个sheet [推广有奖]

21
新人2012 发表于 2013-2-26 15:57:39
并且每个datasets中增加一个变量,值为sheet的名字。

本文来自: 人大经济论坛 SAS专版 版,详细出处参考: https://bbs.pinggu.org/forum.php? ... amp;from^^uid=3523323
后面通过j这个loop j 中加上一小段merge代码,应该可以实现。
但以sheet名作为变量名,如果有大批sheets且名称无规律,不宜批量处理。

供参考。

22
bobguy 发表于 2013-3-3 10:56:25
bobguy 发表于 2013-2-25 22:59
1) The first one can be done in a excel vba.

2) The second one can be done by using libname engin ...
Here is the VBS for open files of xlsx (2007) into xls (2003). Suppose you have
c:\temp\Book1.xlsx
c:\temp\Book2.xlsx

and want to save them as

c:\temp\_Book1.xls
c:\temp\_Book2.xls

The following vbs can be easily generated by a simple sas macro or by a data step dynamicly.

Then issues a x command in SAS or goes dos window to execute it.
data _null_;

  x 'c:\temp\openxlsx.vbs';

run;

-----------------------------------------------------------------------

Const xlDelimited  = 1
Const xlWorkbookNormal = -4143

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False

objExcel.Workbooks.Open("c:\temp\Book1.xlsx")
objExcel.Workbooks.Open("c:\temp\Book2.xlsx")

objExcel.Workbooks("Book1.xlsx").SaveAs _
    "c:\temp\_Book1.xls", xlWorkbookNormal

objExcel.Workbooks("Book2.xlsx").SaveAs _
    "c:\temp\_Book2.xls", xlWorkbookNormal

objExcel.Workbooks("_Book1.xls").Close
objExcel.Workbooks("_Book2.xls").Close

objExcel.Quit

已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 80 + 100 + 3 + 4 + 3 精彩帖子

总评分: 经验 + 80  论坛币 + 100  学术水平 + 3  热心指数 + 4  信用等级 + 3   查看全部评分

23
Imasasor 发表于 2013-3-3 11:01:09
新人2012 发表于 2013-2-26 15:45
尊敬的版主
您看下面的代码是不是您所需要的东西?从去年写过的一段代码摘录过来的(oop i for excel files ...
非常感谢,太长了,抽个时间看一下
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

24
Imasasor 发表于 2013-3-3 11:01:56
bobguy 发表于 2013-3-3 10:56
Here is the VBS for open files of xlsx (2007) into xls (2003). Suppose you have
c:\temp\Book1.xl ...
抽个时间了解一下vba,太感谢了
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

25
zhentao 发表于 2013-3-4 10:23:42
Imasasor 发表于 2013-2-26 10:29
都没报错,但格式没转变啊
options noxwait xsync;
x "ren C:\Documents and Settings\chao\桌面\待整理 ...
我觉得你不应该放在桌面上,而且你的路径里面有中文。
我过去碰上几次这样的事情,后来尽量不放在桌面上,而且路径里面尽量不要有空格和中文。
我也不知道我的经验对你有没有用。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 23:21