Codebase list pyexcel-ods / fb82cf2
:hammer: code refactoring chfw 3 years ago
2 changed file(s) with 11 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
2929 from odf.teletype import extractText
3030 from odf.namespaces import OFFICENS
3131 from odf.opendocument import load
32 from pyexcel_io.plugin_api.abstract_sheet import ISheet
33 from pyexcel_io.plugin_api.abstract_reader import IReader
32 from pyexcel_io.plugin_api import ISheet
33 from pyexcel_io.plugin_api import IReader, NamedContent
3434
3535
3636 class ODSSheet(ISheet):
106106 self._native_book = load(file_alike_object)
107107 self._keywords = keywords
108108 self.content_array = [
109 NameObject(table.getAttribute("name"), table)
109 NamedContent(table.getAttribute("name"), table)
110110 for table in self._native_book.spreadsheet.getElementsByType(Table)
111111 ]
112112
113113 def read_sheet(self, sheet_index):
114114 """read a sheet at a specified index"""
115 table = self.content_array[sheet_index].sheet
115 table = self.content_array[sheet_index].payload
116116 sheet = ODSSheet(table, **self._keywords)
117117 return sheet
118118
128128 def __init__(self, file_content, file_type, **keywords):
129129 io = BytesIO(file_content)
130130 super().__init__(io, file_type, **keywords)
131
132
133 class NameObject(object):
134 def __init__(self, name, sheet):
135 self.name = name
136 self.sheet = sheet
66 :copyright: (c) 2014-2020 by Onni Software Ltd.
77 :license: New BSD License, see LICENSE for more details
88 """
9 import sys
10
119 import pyexcel_io.service as converter
1210 from odf.text import P
1311 from odf.table import Table, TableRow, TableCell
1412 from odf.namespaces import OFFICENS
1513 from odf.opendocument import OpenDocumentSpreadsheet
16 from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter
17 from pyexcel_io.plugin_api.abstract_writer import IWriter
18
19 PY2 = sys.version_info[0] == 2
20
21 PY27_BELOW = PY2 and sys.version_info[1] < 7
14 from pyexcel_io.plugin_api import ISheetWriter
15 from pyexcel_io.plugin_api import IWriter
2216
2317
2418 class ODSSheetWriter(ISheetWriter):
2620 ODS sheet writer
2721 """
2822
29 def __init__(self, ods_book, ods_sheet, sheet_name, **keywords):
23 def __init__(self, ods_book, sheet_name):
3024 self._native_book = ods_book
3125 self._native_sheet = Table(name=sheet_name)
3226
7872
7973 """
8074
81 def __init__(self, file_alike_object, file_type, **keywords):
82 self._file_alike_object = file_alike_object
75 def __init__(self, file_alike_object, file_type, **_):
76 self.file_alike_object = file_alike_object
8377 self._native_book = OpenDocumentSpreadsheet()
8478
8579 def create_sheet(self, name):
8680 """
8781 write a row into the file
8882 """
89 return ODSSheetWriter(self._native_book, None, name)
83 return ODSSheetWriter(self._native_book, name)
9084
9185 def close(self):
9286 """
9387 This call writes file
9488
9589 """
96 self._native_book.write(self._file_alike_object)
90 self._native_book.write(self.file_alike_object)
9791 self._native_book = None