Saving data from SPSS to Excel - custom sheet name

删除回忆录丶 提交于 2020-01-24 19:06:31

问题


Is it possible, When exporting a dataset from SPSS to Excel, to control the name of the worksheet the data is being saved into ? The "SAVE TRANSLATE OUTFILE" command does not allow for this. I have SPSS 21, with Python installed (although I am fairly new to Python...)


回答1:


Yes. See this weblink on IBM website for details.

get file="C:\Program Files\IBM\SPSS\Statistics\23\Samples\English\Employee data.sav".

SAVE TRANSLATE 
  /TYPE=ODBC
  /CONNECT='DSN=Excel Files;DBQ=C:\Daten\Temp\EmployeeDataExcelExport.xlsx;'
  /ENCRYPTED
  /MISSING=IGNORE
  /REPLACE
  /TABLE='EmployeeData'.

EDIT:

The syntax provided in the link on IBM website does NOT work for me however the below does:

save translate
    /connect="dsn=excel files;dbq=C:\Temp\EmployeeDataExcelExport.xls;driverid=790;maxbuffersize=2048;pagetimeout=5;"
    /table="EmployeeData"
    /type=odbc /map /replace.




回答2:


SAVE TRANSLATE relies on ODBC drivers, which means that your Statistics and Office bitness has to match - 64-bit Statistics with 32-bit Office won't work. Otherwise, you can write to an Excel file with SAVE TRANSLATE and then use VBA automation via a Basic script in Statistics to rename the sheet. There is a Basic module available from the SPSS Community website that writes output tables to an Excel file that does some sheet renaming that you could adapt for your purposes.

You can find the module here
https://www.ibm.com/developerworks/community/files/app?lang=en#/file/8e0dfcb6-aa57-4639-a20e-1780010cfe83



来源:https://stackoverflow.com/questions/31344178/saving-data-from-spss-to-excel-custom-sheet-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!