123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import os
- import sys
- from format_convert.convert_tree import _Document
- sys.path.append(os.path.dirname(__file__) + "/../")
- import logging
- import traceback
- from format_convert import get_memory_info
- from format_convert.convert_need_interface import from_office_interface
- from format_convert.convert_xlsx import xlsx2text, XlsxConvert
- from format_convert.utils import judge_error_code
- @get_memory_info.memory_decorator
- def xls2text(path, unique_type_dir):
- logging.info("into xls2text")
- try:
- # 调用libreoffice格式转换
- file_path = from_office_interface(path, unique_type_dir, 'xlsx')
- if judge_error_code(file_path):
- return file_path
- text = xlsx2text(file_path, unique_type_dir)
- if judge_error_code(text):
- return text
- return text
- except Exception as e:
- logging.info("xls2text error!")
- print("xls2text", traceback.print_exc())
- return [-1]
- class XlsConvert:
- def __init__(self, path, unique_type_dir):
- self._doc = _Document(path)
- self.path = path
- self.unique_type_dir = unique_type_dir
- def convert(self):
- # 调用office格式转换
- file_path = from_office_interface(self.path, self.unique_type_dir, 'xlsx')
- if judge_error_code(file_path):
- self._doc = file_path
- return
- _xlsx = XlsxConvert(file_path, self.unique_type_dir)
- _xlsx.convert()
- self._doc = _xlsx._doc
- def get_html(self):
- try:
- self.convert()
- except:
- traceback.print_exc()
- self._doc.error_code = [-1]
- if self._doc.error_code is not None:
- return self._doc.error_code
- print(self._doc.children)
- return self._doc.get_html()
|