How to use the pyexcel.Book function in pyexcel

To help you get started, we’ve selected a few pyexcel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyexcel-webwares / Flask-Excel / tests / test_extra_methods_of_request.py View on Github external
def test_book(self):
        test_sample = ["book", "book_dict"]
        expected = {
            u'result': {
                u'Sheet1': [[1.0, 1.0, 1.0, 1.0],
                            [2.0, 2.0, 2.0, 2.0],
                            [3.0, 3.0, 3.0, 3.0]],
                u'Sheet3': [[u'X', u'Y', u'Z'],
                            [1.0, 4.0, 7.0], [2.0, 5.0, 8.0],
                            [3.0, 6.0, 9.0]],
                u'Sheet2': [[4.0, 4.0, 4.0, 4.0],
                            [5.0, 5.0, 5.0, 5.0],
                            [6.0, 6.0, 6.0, 6.0]]}}
        for struct_type in test_sample:
            io = BytesIO()
            book = pe.Book(self.content)
            book.save_to_memory('xls', io)
            io.seek(0)
            response = self.app.post(
                '/respond/%s' % struct_type, buffered=True,
                data={"file": (io, "test.xls")},
                content_type="multipart/form-data")
            assert json.loads(response.data.decode('utf-8')) == expected
github pyexcel / pyexcel / tests / test_file_type_as_attribute.py View on Github external
def test_set_book_attribute():
    file_name = os.path.join("tests", "fixtures", "test-multiple.csvz")
    with open(file_name, "rb") as f:
        csvz_content = f.read()
        book = Book()
        book.csvz = csvz_content
        expected = (
            "---pyexcel:sheet1---\r\n"
            + "1,4,9\r\n"
            + "2,5,8\r\n"
            + "3,6,7\r\n"
            + "---pyexcel---\r\n"
            + "---pyexcel:sheet2---\r\n"
            + "1,4,9\r\n"
            + "2,5,8\r\n"
            + "3,6,7\r\n"
            + "---pyexcel---\r\n"
            + "---pyexcel:sheet3---\r\n"
            + "1,4,9\r\n"
            + "2,5,8\r\n"
            + "3,6,7\r\n"
github pyexcel / pyexcel / tests / test_book.py View on Github external
def test_a_dictionary_of_sheet():
    test_data = [["a", "b"]]

    book_dict = {"test": p.Sheet(test_data)}

    book = p.Book(book_dict)
    eq_(book.test.array, test_data)
github pyexcel / pyexcel / tests / test_signature_fuction.py View on Github external
def test_look_at_sheet_names_decides_to_read_seond_one(self):
        test_file = "test_get_book.xls"
        content = _produce_ordered_dict()

        book = pe.Book(content)
        book.save_as(test_file)
        book_stream = pe.iget_book(file_name=test_file)
        data = pe.iget_array(sheet_stream=book_stream["Sheet1"])
        assert isinstance(data, GeneratorType)
        eq_(list(data), [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]])
        os.unlink(test_file)
github pyexcel / pyexcel / tests / test_signature_fuction.py View on Github external
def test_book_save_a_dict2(self):
        data = [[1, 4, "X"], [2, 5, "Y"], [3, 6, "Z"]]
        data1 = [[1, 4, "A"], [2, 5, "B"], [3, 6, "C"]]
        sheet1 = Signature.__tablename__
        sheet2 = Signature2.__tablename__
        sheet_dict = {sheet1: data, sheet2: data1}
        book = pe.Book(sheet_dict)
        book[sheet1].transpose()
        book[sheet1].name_columns_by_row(2)
        book[sheet2].transpose()
        book[sheet2].name_columns_by_row(2)
        book.save_to_database(self.session, [Signature, Signature2])
        result = pe.get_dict(session=self.session, table=Signature)
        assert result == {"X": [1, 4], "Y": [2, 5], "Z": [3, 6]}
        result = pe.get_dict(session=self.session, table=Signature2)
        assert result == {"A": [1, 4], "B": [2, 5], "C": [3, 6]}
github pyexcel / pyexcel / tests / test_signature_fuction.py View on Github external
def test_book_save_a_dict(self):
        data = [[1, 4, "X"], [2, 5, "Y"], [3, 6, "Z"]]
        sheet1 = Signature.__tablename__
        sheet_dict = {sheet1: data}
        book = pe.Book(sheet_dict)
        book[sheet1].transpose()
        book[sheet1].name_columns_by_row(2)
        book.save_to_database(self.session, [Signature])
        result = pe.get_dict(session=self.session, table=Signature)
        assert result == {"X": [1, 4], "Y": [2, 5], "Z": [3, 6]}
github pyexcel / pyexcel / tests / test_bug_fixes.py View on Github external
def test_issue_09():
    p.book.LOCAL_UUID = 0
    merged = p.Book()
    sheet1 = p.Sheet(sheet=[[1, 2]])
    sheet2 = p.Sheet(sheet=[[1, 2]])
    merged += sheet1
    merged += sheet2
    eq_(merged[1].name, "pyexcel sheet_1")
github pyexcel / pyexcel / tests / test_bug_fixes.py View on Github external
def test_issue_06():
    import logging

    logger = logging.getLogger("test")
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    logger.addHandler(ch)
    output = StringIO()
    book = p.Book({"hoja1": [["datos", "de", "prueba"], [1, 2, 3]]})
    book.save_to_memory("csv", output)
    logger.debug(output.getvalue())
github pyexcel / pyexcel / tests / test_django_related_functions.py View on Github external
def test_book_save_to_models(self):
        model1 = FakeDjangoModel("Sheet1")
        model2 = FakeDjangoModel("Sheet2")
        book = pe.Book(self.content)
        book.save_to_django_models([model1, model2])
        assert model1.objects.objs == self.result1
        assert model2.objects.objs == self.result2