from abc import ABCMeta, abstractmethod
from openpyxl import load_workbook
import xlrd, xlwt
class ExcelHelper(metaclass=ABCMeta):
@abstractmethod
def read_row(self):
pass
@abstractmethod
def read_column(self):
pass
class DTSHelper:
__metaclass__ = ABCMeta
@abstractmethod
def read(self):
xlrd.book
pass
@abstractmethod
def write(self):
pass
class XLSHelper(ExcelHelper):
def __init__(self, filename):
self.__workbook = xlrd.open_workbook(filename)
self.__worksheets = self.__workbook.sheets()
self.__cur_sheet = self.__worksheets[0] if len(self.__worksheets) > 0 else None
def use_sheet(self, sheet_name):
self.__cur_sheet = self.__workbook.sheet_by_name(sheet_name)
def new_sheet(self, sheet_name):
self.__cur_sheet = xlwt.Workbook(self.__workbook, encoding='utf-8').add_sheet(sheet_name) # 难道不能修改文件吗???
def read_row(self):
pass
def read_column(self):
pass
def read_cell(self):
pass
class XLSXHelper(ExcelHelper):
def __init__(self, filename, readonly=True):
self.__workbook = load_workbook(filename, readonly)
self.__worksheets = self.__workbook.worksheets
self.__cur_sheet = self.__worksheets[0] if len(self.__worksheets) > 0 else None
def use_sheet(self, sheet_name):
self.__cur_sheet = self.__workbook.get_sheet_by_name(sheet_name)
def new_sheet(self, sheet_name):
self.__cur_sheet = self.__workbook.create_sheet(title=sheet_name)
def read_row(self):
pass
def read_column(self):
pass
def read_cell(self):
pass
if __name__ == '__main__':
pass