0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

エクセルファイルの各シートの選択位置と表示倍率を一括返還する

Posted at
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)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?