# Path: util/excel/ExcelEditor.py
# class ExcelEditor:
# 
#     def __init__(self, wb, fileName):
#         self.__workBook = wb
#         self.__fileName = fileName
# 
#     # 各种写操作执行完之后，一定要调用这个方法保存
#     def commit(self):
#         self.__workBook.save(self.__fileName)
# 
#     def getSheet(self, index):
#         return self.__workBook.get_sheet(index)


import xlwt
import xlrd
import xlsxwriter
from xlutils.copy import copy
from util.excel.ExcelEditor import ExcelEditor

    # 添加表
    def addSheet(self, sheet):
        return self.getExcel("WRITE").add_sheet(sheet)

    # 获取表
    def getSheet(self, which, mode):
        try:
            wb = self.getExcel(mode)
            if isinstance(which, str):
                if mode.upper() == "READ":
                    return wb.sheet_by_name(which)
                else:
                    return None
            elif isinstance(which, int):
                if mode.upper() == "READ":
                    return wb.sheet_by_index(which)
                elif mode.upper() == "WRITE":
                    return wb.get_sheet(which)
                else:
                    return None
            else:
                return None
        except Exception as e:
            print("excel报错-------------------------------" + str(e))
            return

    # 调用这个方法生成editor,主要模仿安卓的SharedPreferences
    def edit(self):
        wb = self.getExcel("write")

# Path: util/excel/ExcelEditor.py
# class ExcelEditor:
# 
#     def __init__(self, wb, fileName):
#         self.__workBook = wb
#         self.__fileName = fileName
# 
#     # 各种写操作执行完之后，一定要调用这个方法保存
#     def commit(self):
#         self.__workBook.save(self.__fileName)
# 
#     def getSheet(self, index):
#         return self.__workBook.get_sheet(index)


# Path: util/excel/ExcelUtil.py
import xlwt
import xlrd
import xlsxwriter
from xlutils.copy import copy
from util.excel.ExcelEditor import ExcelEditor


    # 添加表
    def addSheet(self, sheet):
        return self.getExcel("WRITE").add_sheet(sheet)

    # 获取表
    def getSheet(self, which, mode):
        try:
            wb = self.getExcel(mode)
            if isinstance(which, str):
                if mode.upper() == "READ":
                    return wb.sheet_by_name(which)
                else:
                    return None
            elif isinstance(which, int):
                if mode.upper() == "READ":
                    return wb.sheet_by_index(which)
                elif mode.upper() == "WRITE":
                    return wb.get_sheet(which)
                else:
                    return None
            else:
                return None
        except Exception as e:
            print("excel报错-------------------------------" + str(e))
            return

    # 调用这个方法生成editor,主要模仿安卓的SharedPreferences
    def edit(self):
        wb = self.getExcel("write")

        return ExcelEditor(wb, self.__fileName)