🔨 code refactoring

This commit is contained in:
chfw 2020-10-06 23:23:30 +01:00
parent 24813b2d34
commit fb82cf285f
2 changed files with 11 additions and 23 deletions

View File

@ -30,8 +30,8 @@ from odf.table import Table, TableRow, TableCell
from odf.teletype import extractText
from odf.namespaces import OFFICENS
from odf.opendocument import load
from pyexcel_io.plugin_api.abstract_sheet import ISheet
from pyexcel_io.plugin_api.abstract_reader import IReader
from pyexcel_io.plugin_api import ISheet
from pyexcel_io.plugin_api import IReader, NamedContent
class ODSSheet(ISheet):
@ -107,13 +107,13 @@ class ODSBook(IReader):
self._native_book = load(file_alike_object)
self._keywords = keywords
self.content_array = [
NameObject(table.getAttribute("name"), table)
NamedContent(table.getAttribute("name"), table)
for table in self._native_book.spreadsheet.getElementsByType(Table)
]
def read_sheet(self, sheet_index):
"""read a sheet at a specified index"""
table = self.content_array[sheet_index].sheet
table = self.content_array[sheet_index].payload
sheet = ODSSheet(table, **self._keywords)
return sheet
@ -129,9 +129,3 @@ class ODSBookInContent(ODSBook):
def __init__(self, file_content, file_type, **keywords):
io = BytesIO(file_content)
super().__init__(io, file_type, **keywords)
class NameObject(object):
def __init__(self, name, sheet):
self.name = name
self.sheet = sheet

View File

@ -7,19 +7,13 @@
:copyright: (c) 2014-2020 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
import sys
import pyexcel_io.service as converter
from odf.text import P
from odf.table import Table, TableRow, TableCell
from odf.namespaces import OFFICENS
from odf.opendocument import OpenDocumentSpreadsheet
from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter
from pyexcel_io.plugin_api.abstract_writer import IWriter
PY2 = sys.version_info[0] == 2
PY27_BELOW = PY2 and sys.version_info[1] < 7
from pyexcel_io.plugin_api import ISheetWriter
from pyexcel_io.plugin_api import IWriter
class ODSSheetWriter(ISheetWriter):
@ -27,7 +21,7 @@ class ODSSheetWriter(ISheetWriter):
ODS sheet writer
"""
def __init__(self, ods_book, ods_sheet, sheet_name, **keywords):
def __init__(self, ods_book, sheet_name):
self._native_book = ods_book
self._native_sheet = Table(name=sheet_name)
@ -79,20 +73,20 @@ class ODSWriter(IWriter):
"""
def __init__(self, file_alike_object, file_type, **keywords):
self._file_alike_object = file_alike_object
def __init__(self, file_alike_object, file_type, **_):
self.file_alike_object = file_alike_object
self._native_book = OpenDocumentSpreadsheet()
def create_sheet(self, name):
"""
write a row into the file
"""
return ODSSheetWriter(self._native_book, None, name)
return ODSSheetWriter(self._native_book, name)
def close(self):
"""
This call writes file
"""
self._native_book.write(self._file_alike_object)
self._native_book.write(self.file_alike_object)
self._native_book = None