def setUp(self): self.test_file_formatter = "csv_multiple__%s__%s." + self.file_type self.merged_book_file = "csv_multiple." + self.file_type self.data = [ ["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"] ] self.expected_data = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] self.sheets = OrderedDict() self.sheets.update({"sheet1": self.data}) self.sheets.update({"sheet2": self.data}) self.sheets.update({"sheet3": self.data}) self.expected_sheets = OrderedDict() self.expected_sheets.update({"sheet1": self.expected_data}) self.expected_sheets.update({"sheet2": self.expected_data}) self.expected_sheets.update({"sheet3": self.expected_data}) index = 0 for key, value in self.sheets.items(): file_name = self.test_file_formatter % (key, index) with open(file_name, 'w') as f: for row in value: f.write(self.delimiter.join(row) + "\n") index = index + 1
def read_all(self): """read all available sheets""" result = OrderedDict() for sheet in self._native_book.sheets: data_dict = self.read_sheet(sheet) result.update(data_dict) return result
def test_reading(): data = get_data( os.path.join("tests", "fixtures", "date_field.xlsb"), library="pyexcel-xlsbr", ) expected = OrderedDict() # expected.update({ # "Sheet1": [ # ['Date', 'Time'], # [datetime(year=2014, month=12, day=25), # time(hour=11, minute=11, second=11)], # [datetime(2014, 12, 26, 0, 0), # time(hour=12, minute=12, second=12)], # [datetime(2015, 1, 1, 0, 0), # time(hour=13, minute=13, second=13)], # [datetime(year=1899, month=12, day=30), # time(hour=0, minute=0)] # ]}) expected.update({ "Sheet1": [ ["Date", "Time"], [41998.0, 0.466099537037037], [41999.0, 0.508472222222222], [42005.0, 0.550844907407407], [0.0, 0.0], ] }) expected.update({"Sheet2": []}) expected.update({"Sheet3": []}) eq_(data, expected)
def setUp(self): self.content = OrderedDict() self.content.update( {"Sheet1": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]}) self.content.update( {"Sheet2": [[u'A', u'B', u'C'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]}) self.result1 = [{ 'Y': 4, 'X': 1, 'Z': 7 }, { 'Y': 5, 'X': 2, 'Z': 8 }, { 'Y': 6, 'X': 3, 'Z': 9 }] self.result2 = [{ 'B': 4, 'A': 1, 'C': 7 }, { 'B': 5, 'A': 2, 'C': 8 }, { 'B': 6, 'A': 3, 'C': 9 }]
def test_reading(): data = get_data(os.path.join("tests", "fixtures", "date_field.xlsx"), library="pyexcel-xlsx", skip_hidden_row_and_column=False) expected = OrderedDict() expected.update({ "Sheet1": [ ["Date", "Time"], [ datetime(year=2014, month=12, day=25), time(hour=11, minute=11, second=11), ], [ datetime(2014, 12, 26, 0, 0), time(hour=12, minute=12, second=12), ], [ datetime(2015, 1, 1, 0, 0), time(hour=13, minute=13, second=13), ], [ datetime(year=1899, month=12, day=30), datetime(1899, 12, 30, 0, 0), ], ] }) expected.update({"Sheet2": []}) expected.update({"Sheet3": []}) eq_(data, expected)
def read_all(self): result = OrderedDict() for sheet in self._native_book: if self.skip_hidden_sheets and sheet.sheet_state == "hidden": continue data_dict = self.read_sheet(sheet) result.update(data_dict) return result
def read_all(self): """read all sheets""" result = OrderedDict() for sheet in self._native_book.spreadsheet.getElementsByType(Table): ods_sheet = ODSSheet(sheet, **self._keywords) result[ods_sheet.name] = ods_sheet.to_array() return result
def read_all(self): """ read everything from a excel data book """ result = OrderedDict() for sheet in self._native_book: result[sheet.name] = self.read_sheet(sheet) return result
def setUp(self): self.content = OrderedDict() self.content.update( {'Sheet 1': [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]}) self.content.update( {'Sheet 2': [['X', 'Y', 'Z'], [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]}) self.content.update( {'Sheet 3': [['O', 'P', 'Q'], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]]}) save_data(self.file_name, self.content)
def read_all(self): """ read everything from a excel data book """ result = OrderedDict() for sheet_index in range(len(self.reader)): content_dict = self.read_sheet_by_index(sheet_index) result.update(content_dict) return result
def read_all(self): result = OrderedDict() self._native_book = self._get_book() for sheet in self._native_book.sheets(): if self.__skip_hidden_sheets and sheet.visibility != 0: continue data_dict = self.read_sheet(sheet) result.update(data_dict) return result
def test_unknown_sheet(self): importer = SQLTableImporter(None) category_adapter = SQLTableImportAdapter(Category) category_adapter.column_names = [""] importer.append(category_adapter) writer = SQLBookWriter() writer.open_content(importer) to_store = OrderedDict() to_store.update({"you do not see me": [[]]}) writer.write(to_store)
def read_many(self, sheets): """ read everything from a excel data book """ result = OrderedDict() for sheet in sheets: if isinstance(sheet, int): result.update(self.read_sheet_by_index(sheet)) else: result.update(self.read_sheet_by_name(sheet)) return result
def setUp(self): self.content = OrderedDict() self.content.update( {"Sheet 1": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]} ) self.content.update( {"Sheet 2": [["X", "Y", "Z"], [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]} ) self.content.update( {"Sheet 3": [["O", "P", "Q"], [3.0, 2.0, 1.0], [4.0, 3.0, 2.0]]} ) save_data(self.file_name, self.content)
def setUp(self): self.test_file_formatter = "csv_multiple__%s__%s." + self.file_type self.merged_book_file = "csv_multiple." + self.file_type self.data1 = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]] self.data2 = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "1000"]] self.data3 = [["1", "2", "3"], ["4", "5", "6888"], ["7", "8", "9"]] self.expected_data1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] self.expected_data2 = [[1, 2, 3], [4, 5, 6], [7, 8, 1000]] self.expected_data3 = [[1, 2, 3], [4, 5, 6888], [7, 8, 9]] self.sheets = OrderedDict() self.sheets.update({"sheet1": self.data1}) self.sheets.update({"sheet2": self.data2}) self.sheets.update({"sheet3": self.data3}) self.expected_sheets = OrderedDict() self.expected_sheets.update({"sheet1": self.expected_data1}) self.expected_sheets.update({"sheet2": self.expected_data2}) self.expected_sheets.update({"sheet3": self.expected_data3}) self.result_dict = OrderedDict() self.result_dict.update({"sheet1": self.result1}) self.result_dict.update({"sheet2": self.result2}) self.result_dict.update({"sheet3": self.result3})
def setUp(self): Base.metadata.drop_all(engine) Base.metadata.create_all(engine) self.session = Session() data = { "Category": [["id", "name"], [1, "News"], [2, "Sports"]], "Post": [ ["id", "title", "body", "pub_date", "category"], [ 1, "Title A", "formal", datetime.datetime(2015, 1, 20, 23, 28, 29), "News", ], [ 2, "Title B", "informal", datetime.datetime(2015, 1, 20, 23, 28, 30), "Sports", ], ], } def category_init_func(row): c = Category(row["name"]) c.id = row["id"] return c def post_init_func(row): c = (self.session.query(Category).filter_by( name=row["category"]).first()) p = Post(row["title"], row["body"], c, row["pub_date"]) return p importer = SQLTableImporter(self.session) category_adapter = SQLTableImportAdapter(Category) category_adapter.column_names = data["Category"][0] category_adapter.row_initializer = category_init_func importer.append(category_adapter) post_adapter = SQLTableImportAdapter(Post) post_adapter.column_names = data["Post"][0] post_adapter.row_initializer = post_init_func importer.append(post_adapter) writer = SQLBookWriter() writer.open_content(importer) to_store = OrderedDict() to_store.update({category_adapter.get_name(): data["Category"][1:]}) to_store.update({post_adapter.get_name(): data["Post"][1:]}) writer.write(to_store) writer.close()
def parse_styles(style_content): styles = OrderedDict() formats = NUMBER_FMT_MATCHER.findall(style_content) for aformat in formats: partial = io.BytesIO(aformat) for action, element in etree.iterparse(partial, ("end", )): if element.tag != "numFmt": continue numFmtId = element.attrib.get("numFmtId") formatCode = element.attrib.get("formatCode") formatCode = formatCode.lower().replace("\\", "") styles.update({numFmtId: formatCode}) return styles
def setUp(self): self.content = OrderedDict() self.content.update( {"Sheet1": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]}) self.content.update( {"Sheet2": [[u"A", u"B", u"C"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]}) self.result1 = [ { "Y": 4, "X": 1, "Z": 7 }, { "Y": 5, "X": 2, "Z": 8 }, { "Y": 6, "X": 3, "Z": 9 }, ] self.result2 = [ { "B": 4, "A": 1, "C": 7 }, { "B": 5, "A": 2, "C": 8 }, { "B": 6, "A": 3, "C": 9 }, ]
def read_all(self): result = OrderedDict() for sheet in self._native_book: data_dict = self.read_sheet(sheet) result.update(data_dict) return result