convert_xls.py 887 B

1234567891011121314151617181920212223242526272829
  1. import os
  2. import sys
  3. sys.path.append(os.path.dirname(__file__) + "/../")
  4. import logging
  5. import traceback
  6. from format_convert import get_memory_info
  7. from format_convert.convert_need_interface import from_office_interface
  8. from format_convert.convert_xlsx import xlsx2text
  9. from format_convert.utils import judge_error_code
  10. @get_memory_info.memory_decorator
  11. def xls2text(path, unique_type_dir):
  12. logging.info("into xls2text")
  13. try:
  14. # 调用libreoffice格式转换
  15. file_path = from_office_interface(path, unique_type_dir, 'xlsx')
  16. if judge_error_code(file_path):
  17. return file_path
  18. text = xlsx2text(file_path, unique_type_dir)
  19. if judge_error_code(text):
  20. return text
  21. return text
  22. except Exception as e:
  23. logging.info("xls2text error!")
  24. print("xls2text", traceback.print_exc())
  25. return [-1]