问题
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