gpt4 book ai didi

python - 在 Python 中自动执行将 SPSS 文件 (.spv) 转换为 PDF 的任务

转载 作者:太空宇宙 更新时间:2023-11-03 21:05:11 27 4
gpt4 key购买 nike

我正在寻找一种将包含多个 SPSS 输出文件 (.spv) 的文件夹快速转换为 PDF 的方法。理想情况下,我想使用 Python 来完成此操作,但如果有更简单的解决方案,我会洗耳恭听。

我真的只需要在 python 中打开 .spv 文件,然后单击"file"->“导出”->“PDF”。

我以前从未尝试过用任何语言自动化任务,所以我什至不知道如何开始。

最佳答案

对于有类似问题的人:我无法构建一个优雅的转换器或任何东西,但我确实找到了一个简单的解决方案,只需打开每个文件并单击"file"->“导出”->“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) #File

关于python - 在 Python 中自动执行将 SPSS 文件 (.spv) 转换为 PDF 的任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55456831/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com