コード例 #1
0
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" + "---pyexcel---\r\n")
        eq_(book.csv, expected)
コード例 #2
0
def test_set_bookdict():
    b = Book()
    b.bookdict = {"sheet1": [[1]], "sheet2": [[2]]}
    expected = dedent("""
    sheet1:
    +---+
    | 1 |
    +---+
    sheet2:
    +---+
    | 2 |
    +---+""").strip()
    eq_(str(b), expected)
コード例 #3
0
def test_set_bookdict():
    b = Book()
    b.bookdict = {"sheet1": [[1]], "sheet2": [[2]]}
    expected = dedent("""
    sheet1:
    +---+
    | 1 |
    +---+
    sheet2:
    +---+
    | 2 |
    +---+""").strip()
    eq_(str(b), expected)
    expected = OrderedDict([("sheet1", [[1]]), ("sheet2", [[2]])])
    eq_(b.bookdict, expected)
コード例 #4
0
def book_to_sale(book: pyexcel.Book) -> MutableMapping:
    """ Extracts RSU/ESPP sale data from a SPC Sale Excel workbook.

    :param book: the loaded workbook
    :return: all the data relevant to the sale.
    :raises BookParseError: if sale type couldn't be determined.
    :raises SaleSheetParseError: if first sheet couldn't be parsed as a sale.
    """
    # Convert the sale sheet
    sale_sheet = book.sheet_by_index(0)
    sale: MutableMapping = sale_sheet_to_dict(sale_sheet)

    if sale['plan_type'] is PlanType.RSU:
        rsu_sheet = book.sheet_by_index(1)
        sale['rsus'] = rsu_sheet_to_rsus(rsu_sheet)
    elif sale['plan_type'] is PlanType.ESPP:
        espp_sheet = book.sheet_by_index(1)
        sale['espps'] = espp_sheet_to_espps(espp_sheet)
    else:
        raise BookParseError("Couldn't determine sale type of book")

    return sale
コード例 #5
0
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" +
                    "---pyexcel---\r\n")
        eq_(book.csv, expected)
コード例 #6
0
ファイル: sheet.py プロジェクト: technolog281/fsli_fix
    def group_rows_by_column(self, column_index_or_name):
        """Group rows with similiar column into a two dimensional array.

        Example::

            >>> import pyexcel as p
            >>> sample_data = [
            ...     ["22/09/2017", "morning"],
            ...     ["22/09/2017", "afternoon"],
            ...     ["23/09/2017", "morning"],
            ...     ["23/09/2017", "afternoon"]
            ... ]
            >>> sheet = p.Sheet(sample_data)
            >>> sheet.group_rows_by_column(0)
            22/09/2017:
            +------------+-----------+
            | 22/09/2017 | morning   |
            +------------+-----------+
            | 22/09/2017 | afternoon |
            +------------+-----------+
            23/09/2017:
            +------------+-----------+
            | 23/09/2017 | morning   |
            +------------+-----------+
            | 23/09/2017 | afternoon |
            +------------+-----------+

        :returns: an instance of a Book
        """
        from pyexcel import Book

        groups = defaultdict(list)

        if isinstance(column_index_or_name, int):
            for row in self.to_array():
                groups[row[column_index_or_name]].append(row)
        else:
            if len(self.colnames) == 0:
                self.name_columns_by_row(0)
            column_index = self.colnames.index(column_index_or_name)
            for row in self.rows():
                if len(groups[row[column_index]]) == 0:
                    groups[row[column_index]].append(self.colnames)
                groups[row[column_index]].append(row)
        return Book(groups)
コード例 #7
0
def test_book_register_presentation():
    Book.register_presentation(FIXTURE)
    b = Book({"sheet": [[1, 2]]})
    assert b.dummy == FIXTURE
コード例 #8
0
def test_book_register_presentation():
    Book.register_presentation('dummy')
    b = Book({"sheet": [[1, 2]]})
    assert b.dummy == FIXTURE
コード例 #9
0
 def dump_book(self, book: pyexcel.Book, fo, encoding_hint="utf-8"):
     book.save_to_memory(self.extension, fo)