我正在寻找一种方法来快速转换包含多个SPSS输出文件(.spv)到PDF的文件夹。理想情况下,我希望使用Python来完成这项工作,但如果有更简单的解决方案,我会洗耳恭听。
我真的只需要在python中打开.spv文件,然后单击文件->导出->。
我从来没有尝试过在任何语言中自动执行任务,所以我甚至不知道如何开始这项工作。
发布于 2019-04-08 21:00:00
对于任何有类似问题的人:我无法建立一个优雅的转换器或任何东西,但我找到了一个简单的解决方案,只需打开每个文件,然后单击文件->导出-> PDF为我。我使用PyAutoGUI做到了这一点
这是我的代码,供感兴趣的人参考。
from glob import glob
import pyautogui
import subprocess
import os
import time
import signal
all_files = glob("C://Users//directory//*//*")
screen = pyautogui.size()
#Confirm that your screen is 1920 X 1080
#If not, you'll need to change some of these dimensions
if screen == (1920,1080):
for file in all_files:
if file.endswith('.spv'):
#Have SPSS already open for this to work
p = subprocess.Popen(file, shell=True) #open file
#left to right 0 to 1920
#up to down 0 to 1080
pyautogui.moveTo(22, 50, duration=2) #File
pyautogui.click()
pyautogui.moveTo(22, 230) #Export
pyautogui.click()
pyautogui.moveTo(650, 250) #Choose 'All Visible' option
pyautogui.doubleClick()
pyautogui.doubleClick(800, 820) #Ok
try:
time.sleep(5) #Let SPSS Export, this takes time
#Rename the 'Output.pdf' file
#The "output_directory" is just where SPSS is saving your files
current_directory = os.path.dirname(os.path.realpath(file))
os.chdir("C://Users//output_directory")
for filename in os.listdir("C://Users//output_directory"):
if filename.startswith("OUTPUT.pdf"):
base = os.path.basename(os.path.normpath(file))
renamed, file_extension = os.path.splitext(base)
renamed = renamed + '.pdf'
os.rename(filename, renamed)
#Close SPSS file
pyautogui.click(2875, 5) #Filehttps://stackoverflow.com/questions/55456831
复制相似问题