Example #1
0
    def test_normal_excel(self, tmpdir):
        file_path = "/tmp/valid/test/data/validdata.xlsx"
        p_file_path = Path(str(tmpdir.join(file_path)))
        p_file_path.parent.makedirs_p()

        tabledata_list = [
            TableData(
                "testsheet1",
                ["a1", "b1", "c1"],
                [["aa1", "ab1", "ac1"], [1.0, 1.1, "a"], [2.0, 2.2, "bb"], [3.0, 3.3, 'cc"dd"']],
            ),
            TableData(
                "testsheet3",
                ["a3", "b3", "c3"],
                [["aa3", "ab3", "ac3"], [4.0, 1.1, "a"], [5.0, "", "bb"], [6.0, 3.3, ""]],
            ),
        ]

        writer = ExcelXlsxTableWriter()
        writer.open(p_file_path)
        for tabledata in tabledata_list:
            writer.from_tabledata(tabledata)
        writer.write_table()
        writer.close()

        loader = ptr.TableFileLoader(p_file_path)

        assert loader.format_name == "excel"

        for tabledata in loader.load():
            print(dump_tabledata(tabledata))

            assert tabledata in tabledata_list
def main():
    writer = ExcelXlsxTableWriter()

    writer.table_name = "example"
    writer.headers = ["int", "float", "str", "bool", "mix", "time"]
    writer.value_matrix = [
        [0, 0.1, "hoge", True, 0, "2017-01-01 03:04:05+0900"],
        [2, "-2.23", "foo", False, None, "2017-12-23 12:34:51+0900"],
        [3, 0, "bar", "true", "inf", "2017-03-03 22:44:55+0900"],
        [-10, -9.9, "", "FALSE", "nan", "2017-01-01 00:00:00+0900"],
    ]
    writer.dump("sample.xlsx")
def main():
    writer = ExcelXlsxTableWriter()
    filepath = "multi_sheet_example.xlsx"

    # write the first worksheet
    writer.table_name = "example"
    writer.headers = ["int", "float", "str", "bool", "mix", "time"]
    writer.value_matrix = [
        [0, 0.1, "hoge", True, 0, "2017-01-01 03:04:05+0900"],
        [2, "-2.23", "foo", False, None, "2017-12-23 12:34:51+0900"],
        [3, 0, "bar", "true", "inf", "2017-03-03 22:44:55+0900"],
        [-10, -9.9, "", "FALSE", "nan", "2017-01-01 00:00:00+0900"],
    ]
    writer.dump(filepath, close_after_write=False)

    # write the second worksheet
    writer.table_name = "Timezone"
    writer.headers = [
        "zone_id",
        "abbreviation",
        "time_start",
        "gmt_offset",
        "dst",
    ]
    writer.value_matrix = [
        ["1", "CEST", "1017536400", "7200", "1"],
        ["1", "CEST", "1048986000", "7200", "1"],
        ["1", "CEST", "1080435600", "7200", "1"],
        ["1", "CEST", "1111885200", "7200", "1"],
        ["1", "CEST", "1143334800", "7200", "1"],
    ]
    writer.dump(filepath)
#!/usr/bin/env python
# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi <*****@*****.**>
"""

from pytablewriter import ExcelXlsxTableWriter


writer = ExcelXlsxTableWriter()

writer.table_name = "example"
writer.headers = ["int", "float", "str", "bool", "mix", "time"]
writer.value_matrix = [
    [0,   0.1,      "hoge", True,   0,      "2017-01-01 03:04:05+0900"],
    [2,   "-2.23",  "foo",  False,  None,   "2017-12-23 12:34:51+0900"],
    [3,   0,        "bar",  "true",  "inf", "2017-03-03 22:44:55+0900"],
    [-10, -9.9,     "",     "FALSE", "nan", "2017-01-01 00:00:00+0900"],
]
writer.dump("sample.xlsx")
#!/usr/bin/env python
# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi <*****@*****.**>
"""

from pytablewriter import ExcelXlsxTableWriter


writer = ExcelXlsxTableWriter()
filepath = "multi_sheet_example.xlsx"

# write the first worksheet
writer.table_name = "example"
writer.headers = ["int", "float", "str", "bool", "mix", "time"]
writer.value_matrix = [
    [0,   0.1,      "hoge", True,   0,      "2017-01-01 03:04:05+0900"],
    [2,   "-2.23",  "foo",  False,  None,   "2017-12-23 12:34:51+0900"],
    [3,   0,        "bar",  "true",  "inf", "2017-03-03 22:44:55+0900"],
    [-10, -9.9,     "",     "FALSE", "nan", "2017-01-01 00:00:00+0900"],
]
writer.dump(filepath, close_after_write=False)

# write the second worksheet
writer.table_name = "Timezone"
writer.headers = [
    "zone_id", "abbreviation", "time_start", "gmt_offset", "dst",
]
writer.value_matrix = [
    ["1", "CEST", "1017536400", "7200", "1"],
Example #6
0
def args_to_excel(model, header, value_matrix):
    writer = ExcelXlsxTableWriter()
    writer.table_name = model
    writer.headers = header
    writer.value_matrix = value_matrix
    writer.dump("results.xlsx")