import os
import openpyxl
from openpyxl.worksheet.views import SheetView
def set_cell_selection_and_zoom(file_path):
workbook = openpyxl.load_workbook(file_path, keep_vba=True)
for sheet in workbook.worksheets:
sheet.sheet_view.selection[0].sqref = 'A1'
sheet.sheet_view.zoomScale = 100
workbook.save(file_path)
print(f"Processed {file_path}")
def process_folder(folder_path):
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith('.xlsx') or file.endswith('.xlsm'):
file_path = os.path.join(root, file)
set_cell_selection_and_zoom(file_path)
# 特定のフォルダパスを指定します
folder_path = 'XXXXX'
process_folder(folder_path)
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme