# Path: pytablewriter/writer/_common.py
# HEADER_ROW = -1
# 
# Path: pytablewriter/writer/binary/_excel_workbook.py
# class ExcelWorkbookInterface(metaclass=abc.ABCMeta):
#     @abc.abstractproperty
#     def workbook(self):  # pragma: no cover
#         pass
# 
#     @abc.abstractproperty
#     def file_path(self):  # pragma: no cover
#         pass
# 
#     @abc.abstractmethod
#     def open(self, file_path: str) -> None:  # pragma: no cover
#         pass
# 
#     @abc.abstractmethod
#     def close(self) -> None:  # pragma: no cover
#         pass
# 
#     @abc.abstractmethod
#     def add_worksheet(self, worksheet_name):  # pragma: no cover
#         pass
# 
# class ExcelWorkbookXls(ExcelWorkbook):
#     def __init__(self, file_path: str) -> None:
#         super().__init__(file_path)
# 
#         self.open(file_path)
# 
#     def open(self, file_path: str) -> None:
#         try:
#             import xlwt
#         except ImportError:
#             warnings.warn(import_error_msg_template.format("excel"))
#             raise
# 
#         self._workbook = xlwt.Workbook()
# 
#     def close(self) -> None:
#         if self.workbook is None:
#             return
# 
#         try:
#             self.workbook.save(self._file_path)
#         except IndexError as e:
#             logger.debug(to_error_message(e))
# 
#         self._clear()
# 
#     def add_worksheet(self, worksheet_name):
#         worksheet_name = sanitize_excel_sheet_name(worksheet_name)
# 
#         if typepy.is_not_null_string(worksheet_name):
#             if worksheet_name in self._worksheet_table:
#                 # the work sheet is already exists
#                 return self._worksheet_table.get(worksheet_name)
#         else:
#             sheet_id = 1
#             while True:
#                 worksheet_name = f"Sheet{sheet_id:d}"
#                 if worksheet_name not in self._worksheet_table:
#                     break
#                 sheet_id += 1
# 
#         worksheet = self.workbook.add_sheet(worksheet_name)
#         self._worksheet_table[worksheet_name] = worksheet
# 
#         return worksheet
# 
# class ExcelWorkbookXlsx(ExcelWorkbook):
#     def __init__(self, file_path: str) -> None:
#         super().__init__(file_path)
# 
#         self.open(file_path)
# 
#     def open(self, file_path: str) -> None:
#         try:
#             import xlsxwriter
#         except ImportError:
#             warnings.warn(import_error_msg_template.format("excel"))
#             raise
# 
#         self._workbook = xlsxwriter.Workbook(file_path)
# 
#     def close(self) -> None:
#         if self.workbook is None:
#             return
# 
#         self._workbook.close()  # type: ignore
#         self._clear()
# 
#     def add_worksheet(self, worksheet_name):
#         worksheet_name = sanitize_excel_sheet_name(worksheet_name)
# 
#         if typepy.is_not_null_string(worksheet_name):
#             if worksheet_name in self._worksheet_table:
#                 # the work sheet is already exists
#                 return self._worksheet_table.get(worksheet_name)
#         else:
#             worksheet_name = None
# 
#         worksheet = self.workbook.add_worksheet(worksheet_name)
#         self._worksheet_table[worksheet_name] = worksheet
# 
#         return worksheet
# 
# Path: pytablewriter/writer/binary/_interface.py
# class AbstractBinaryTableWriter(AbstractTableWriter, BinaryWriterInterface):
#     @property
#     def stream(self):
#         return self._stream
# 
#     @stream.setter
#     def stream(self, value) -> None:
#         raise RuntimeError(
#             "cannot assign a stream to binary format writers. use open method instead."
#         )
# 
#     @property
#     def support_split_write(self) -> bool:
#         return True
# 
#     def __init__(self, **kwargs) -> None:
#         super().__init__(**kwargs)
# 
#         self.table_name = kwargs.get("table_name", "")
# 
#         self._stream = None
# 
#     def __del__(self) -> None:
#         self.close()
# 
#     def is_opened(self) -> bool:
#         return self.stream is not None
# 
#     def dumps(self) -> str:
#         raise NotImplementedError("binary format writers did not support dumps method")
# 
#     def _verify_stream(self) -> None:
#         if self.stream is None:
#             raise OSError("null output stream. required to open(file_path) first.")
# 
#     def _write_value_row_separator(self) -> None:
#         pass


import abc
import copy
import warnings
import dataproperty
import typepy
            import xlwt
from typing import Any, Dict, Optional, cast
from dataproperty import DataProperty
from tabledata import TableData
from typepy import Integer
from .._common import import_error_msg_template
from ._excel_workbook import ExcelWorkbookInterface, ExcelWorkbookXls, ExcelWorkbookXlsx
from ._interface import AbstractBinaryTableWriter




class ExcelTableWriter(AbstractBinaryTableWriter, metaclass=abc.ABCMeta):
    """
    An abstract class of a table writer for Excel file format.
    """

    FORMAT_NAME = "excel"

    @property
    def format_name(self) -> str:
        return self.FORMAT_NAME

    @property
    def workbook(self) -> Optional[ExcelWorkbookInterface]:
        return self._workbook

    def __init__(self, **kwargs) -> None:
        super().__init__(**kwargs)


# Path: pytablewriter/writer/_common.py
# HEADER_ROW = -1
# 
# Path: pytablewriter/writer/binary/_excel_workbook.py
# class ExcelWorkbookInterface(metaclass=abc.ABCMeta):
#     @abc.abstractproperty
#     def workbook(self):  # pragma: no cover
#         pass
# 
#     @abc.abstractproperty
#     def file_path(self):  # pragma: no cover
#         pass
# 
#     @abc.abstractmethod
#     def open(self, file_path: str) -> None:  # pragma: no cover
#         pass
# 
#     @abc.abstractmethod
#     def close(self) -> None:  # pragma: no cover
#         pass
# 
#     @abc.abstractmethod
#     def add_worksheet(self, worksheet_name):  # pragma: no cover
#         pass
# 
# class ExcelWorkbookXls(ExcelWorkbook):
#     def __init__(self, file_path: str) -> None:
#         super().__init__(file_path)
# 
#         self.open(file_path)
# 
#     def open(self, file_path: str) -> None:
#         try:
#             import xlwt
#         except ImportError:
#             warnings.warn(import_error_msg_template.format("excel"))
#             raise
# 
#         self._workbook = xlwt.Workbook()
# 
#     def close(self) -> None:
#         if self.workbook is None:
#             return
# 
#         try:
#             self.workbook.save(self._file_path)
#         except IndexError as e:
#             logger.debug(to_error_message(e))
# 
#         self._clear()
# 
#     def add_worksheet(self, worksheet_name):
#         worksheet_name = sanitize_excel_sheet_name(worksheet_name)
# 
#         if typepy.is_not_null_string(worksheet_name):
#             if worksheet_name in self._worksheet_table:
#                 # the work sheet is already exists
#                 return self._worksheet_table.get(worksheet_name)
#         else:
#             sheet_id = 1
#             while True:
#                 worksheet_name = f"Sheet{sheet_id:d}"
#                 if worksheet_name not in self._worksheet_table:
#                     break
#                 sheet_id += 1
# 
#         worksheet = self.workbook.add_sheet(worksheet_name)
#         self._worksheet_table[worksheet_name] = worksheet
# 
#         return worksheet
# 
# class ExcelWorkbookXlsx(ExcelWorkbook):
#     def __init__(self, file_path: str) -> None:
#         super().__init__(file_path)
# 
#         self.open(file_path)
# 
#     def open(self, file_path: str) -> None:
#         try:
#             import xlsxwriter
#         except ImportError:
#             warnings.warn(import_error_msg_template.format("excel"))
#             raise
# 
#         self._workbook = xlsxwriter.Workbook(file_path)
# 
#     def close(self) -> None:
#         if self.workbook is None:
#             return
# 
#         self._workbook.close()  # type: ignore
#         self._clear()
# 
#     def add_worksheet(self, worksheet_name):
#         worksheet_name = sanitize_excel_sheet_name(worksheet_name)
# 
#         if typepy.is_not_null_string(worksheet_name):
#             if worksheet_name in self._worksheet_table:
#                 # the work sheet is already exists
#                 return self._worksheet_table.get(worksheet_name)
#         else:
#             worksheet_name = None
# 
#         worksheet = self.workbook.add_worksheet(worksheet_name)
#         self._worksheet_table[worksheet_name] = worksheet
# 
#         return worksheet
# 
# Path: pytablewriter/writer/binary/_interface.py
# class AbstractBinaryTableWriter(AbstractTableWriter, BinaryWriterInterface):
#     @property
#     def stream(self):
#         return self._stream
# 
#     @stream.setter
#     def stream(self, value) -> None:
#         raise RuntimeError(
#             "cannot assign a stream to binary format writers. use open method instead."
#         )
# 
#     @property
#     def support_split_write(self) -> bool:
#         return True
# 
#     def __init__(self, **kwargs) -> None:
#         super().__init__(**kwargs)
# 
#         self.table_name = kwargs.get("table_name", "")
# 
#         self._stream = None
# 
#     def __del__(self) -> None:
#         self.close()
# 
#     def is_opened(self) -> bool:
#         return self.stream is not None
# 
#     def dumps(self) -> str:
#         raise NotImplementedError("binary format writers did not support dumps method")
# 
#     def _verify_stream(self) -> None:
#         if self.stream is None:
#             raise OSError("null output stream. required to open(file_path) first.")
# 
#     def _write_value_row_separator(self) -> None:
#         pass


# Path: pytablewriter/writer/binary/_excel.py
import abc
import copy
import warnings
import dataproperty
import typepy
            import xlwt
from typing import Any, Dict, Optional, cast
from dataproperty import DataProperty
from tabledata import TableData
from typepy import Integer
from .._common import import_error_msg_template
from ._excel_workbook import ExcelWorkbookInterface, ExcelWorkbookXls, ExcelWorkbookXlsx
from ._interface import AbstractBinaryTableWriter





class ExcelTableWriter(AbstractBinaryTableWriter, metaclass=abc.ABCMeta):
    """
    An abstract class of a table writer for Excel file format.
    """

    FORMAT_NAME = "excel"

    @property
    def format_name(self) -> str:
        return self.FORMAT_NAME

    @property
    def workbook(self) -> Optional[ExcelWorkbookInterface]:
        return self._workbook

    def __init__(self, **kwargs) -> None:
        super().__init__(**kwargs)


        self._workbook: Optional[ExcelWorkbookInterface] = None