修改下面的python3代码Excel列宽+2import osimport reimport subprocessimport openpyxlfrom openpyxlstyles import Font PatternFill Alignment# 支持的视频格式supported_formats = mp4 avi mkv wmv mov flv m2ts ts rm rmvb
将以下代码替换原有的自动调整列宽部分即可:
自动调整列宽
for col in ws.columns: max_length = 0 column = col[0].column_letter for cell in col: try: if len(str(cell.value)) > max_length: max_length = len(str(cell.value)) except: pass adjusted_width = (max_length + 2) ws.column_dimensions[column].width = adjusted_width + 2 # 将列宽+2
保存Excel文件
if not os.path.exists(excel_folder): os.makedirs(excel_folder) excel_file_path = os.path.join(excel_folder, excel_file) wb.save(excel_file_path) print(f'视频信息已保存到 {excel_file_path}')
原文地址: https://www.cveoy.top/t/topic/bap7 著作权归作者所有。请勿转载和采集!