Python: 练习 Excel 删除某列数据
from openpyxl import * import os def modify_file(): file_list = os.listdir(cwd) for file in file_list: if os.path.isfile(file): print(f"公司:{file} 文件修改 >>> ", end="") wb = load_workbook(file) ws_name=wb.sheetnames[0] ws = wb[ws_name] ws.delete_cols(1) # 删除第 13 列数据 ws['A1'].comment = None wb.save(file) print(f"OK!") print("全部完成") if __name__ == '__main__': os.chdir("../files") cwd = os.getcwd() dir_confirm = input(f"工作目录 {cwd},是否正确(y/n):") if dir_confirm == "y": modify_file()