convert_xls_to_xlsx.py 621 B

1234567891011121314151617181920
  1. # convert_xls_to_xlsx.py
  2. import pandas as pd
  3. import sys
  4. def convert_xls_to_xlsx(input_file, output_file):
  5. try:
  6. df = pd.read_excel(input_file, engine='xlrd')
  7. df.to_excel(output_file, index=False)
  8. print("SUCCESS") # 打印成功消息
  9. except Exception as e:
  10. print(f"ERROR: {e}") # 打印错误消息
  11. if __name__ == "__main__":
  12. if len(sys.argv) != 3:
  13. print("ERROR: Usage: python convert_xls_to_xlsx.py <input_xls_file> <output_xlsx_file>")
  14. sys.exit(1)
  15. input_file = sys.argv[1]
  16. output_file = sys.argv[2]
  17. convert_xls_to_xlsx(input_file, output_file)