-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_excel.py
More file actions
72 lines (61 loc) · 2.51 KB
/
Copy pathrender_excel.py
File metadata and controls
72 lines (61 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import pyautogui
import time
import subprocess
import pygetwindow as gw
def take_screenshot(file_path, output_folder):
base_name = os.path.basename(file_path).replace('.xls', '.png')
outname = os.path.join(output_folder, base_name)
if not os.path.exists(outname):
print(f"Processing file: {file_path}")
# Open the Excel file
subprocess.Popen(['start', 'excel', file_path], shell=True)
time.sleep(1) # Wait for Excel to open
# Handle potential popup by hitting Tab twice and Enter
pyautogui.press('tab')
time.sleep(0.1)
pyautogui.press('tab')
time.sleep(0.1)
pyautogui.press('enter')
time.sleep(0.1)
# Ensure Excel is the active window
excel_windows = gw.getWindowsWithTitle('Excel')
if excel_windows:
excel_window = excel_windows[0]
excel_window.activate()
time.sleep(0.1)
# Adjust the zoom level using the ribbon
pyautogui.press('alt')
time.sleep(0.1)
pyautogui.press('w')
time.sleep(0.1)
pyautogui.press('q')
time.sleep(0.1)
pyautogui.press('tab')
time.sleep(0.1)
pyautogui.hotkey('1', '0') # Set the zoom level to 10%
time.sleep(0.1)
pyautogui.press('enter')
time.sleep(0.5)
# Take a screenshot of the specific window
left, top, right, bottom = excel_window.left, excel_window.top, excel_window.right, excel_window.bottom
screenshot = pyautogui.screenshot(region=(left, top, right-left, bottom-top))
screenshot.save(outname)
# Close Excel
pyautogui.hotkey('alt', 'f4')
time.sleep(0.5) # Wait for Excel to close
def main(input_folder, output_folder):
print(f"Input folder: {input_folder}")
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for file_name in os.listdir(input_folder):
print(f"Processing file: {file_name}")
if file_name.endswith('.xls'):
file_path = os.path.join(input_folder, file_name)
print('taking screenshot')
take_screenshot(file_path, output_folder)
print("Screenshot capture complete.")
if __name__ == "__main__":
input_folder = r'G:\Projects\Excel2video\pixel-spreadsheet\stardog_spreadsheets'
output_folder = r'G:\Projects\Excel2video\pixel-spreadsheet\stardog_in_excel'
main(input_folder, output_folder)