def __init__(self, file_path, new_path=None, override=False, date_format=DateFormat(), number_format=NumberFormat(), bool_format=BoolFormat()): self.is_update = new_path is None or new_path == file_path self.new_path = None if self.is_update else get_file_path(new_path) self.override = override if self.new_path and is_file(self.new_path): if self.override: del_file(self.new_path) else: message = 'File ' + self.new_path + ' already existed. Use `override=True` to force override file' raise IOError(message) if PY2 else FileExistsError(message) try: super(ExcelWriter, self).__init__(file_path, date_format, number_format, bool_format) self.writer = XlsWriter( self.workbook) if self.is_xls else XlsxWriter(self.file_path) self.is_new = False except (IOError if PY2 else FileNotFoundError) as _: LOGGER.debug('Create new Excel file in %s', self.file_path) self.writer = XlsWriter() if self.is_xls else XlsxWriter( self.file_path, is_new=True) self.is_new = True
def __init__(self, date_format=DateFormat(), number_format=NumberFormat(), bool_format=BoolFormat()): """ Init Excel Keyword with some default configuration. Excel Date Time format https://support.office.com/en-us/article/format-numbers-as-dates-or-times-418bd3fe-0577-47c8-8caa-b4d30c528309 """ self.date_format = date_format self.number_format = number_format self.bool_format = bool_format self.active = None
def __init__(self, date_format='yyyy-mm-dd', time_format='HH:MM:SS AM/PM', datetime_format='yyyy-mm-dd HH:MM', decimal_sep='.', thousand_sep=',', precision='2', bool_format='Yes/No'): logging.basicConfig() logging.getLogger().setLevel(logging.INFO) logger = logging.getLogger(__name__) logger.info('ExcelRobot::Robotframework Excel Library') super(ExcelRobot, self).__init__( DateFormat(date_format, time_format, datetime_format), NumberFormat(decimal_sep, thousand_sep, precision), BoolFormat(bool_format))
def __init__(self, file_path, date_format=DateFormat(), number_format=NumberFormat(), bool_format=BoolFormat()): self.file_path = get_file_path(file_path) LOGGER.info('Opening file at %s', self.file_path) if not self.file_path or not is_file(self.file_path): self._workbook = None raise IOError('Excel file is not found') if PY2 else FileNotFoundError('Excel file is not found') self._workbook = open_workbook(self.file_path, formatting_info=self.is_xls, on_demand=True) self.date_format = date_format self.number_format = number_format self.bool_format = bool_format