How to use the pyexcel.save_as 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 / pyexcel-xls / tests / base.py View on Github external
def test_series_table(self):
        pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
        r = pyexcel.get_sheet(file_name=self.testfile, name_columns_by_row=0)
        eq_(r.dict, self.content)
github pyexcel / pyexcel / tests / test_stringio.py View on Github external
def do_write_stringio(file_type):
    data = [[1, 2, 3], [4, 5, 6]]
    io = pe.save_as(dest_file_type=file_type, array=data)
    r = pe.get_sheet(file_type=file_type, file_content=io.getvalue())
    result = [1, 2, 3, 4, 5, 6]
    actual = list(r.enumerate())
    eq_(result, actual)
github pyexcel / pyexcel / tests / test_django_related_functions.py View on Github external
def test_model_save_to_django_model_2(self):
        model = FakeDjangoModel()
        pe.save_as(array=self.data, dest_model=model, name_columns_by_row=0)
        assert model.objects.objs == self.result
github pyexcel / pyexcel-ods3 / tests / base.py View on Github external
def test_series_table(self):
        pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
        r = pyexcel.get_sheet(file_name=self.testfile, name_columns_by_row=0)
        eq_(r.dict, self.content)
github pyexcel / pyexcel-xlsx / tests / test_stringio.py View on Github external
def test_xlsx_output_stringio(self):
        data = [[1, 2, 3], [4, 5, 6]]
        io = pyexcel.save_as(dest_file_type="xlsx", array=data)
        r = pyexcel.get_sheet(
            file_type="xlsx",
            file_content=io.getvalue(),
            library="pyexcel-xlsx",
        )
        result = [1, 2, 3, 4, 5, 6]
        actual = list(r.enumerate())
        eq_(result, actual)
github pyexcel / pyexcel / tests / test_examples.py View on Github external
def test_upload(self):
        data = [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]
        expected = {"result": {"X": [1, 4], "Y": [2, 5], "Z": [3, 6]}}
        io = pe.save_as(dest_file_type="csv", array=data)
        io.seek(0)
        if not PY2:
            # have to convert it to bytesio
            # because python 3 socket sends only bytes
            from io import BytesIO

            nio = BytesIO()
            # to convert str to bytes is to do a encode
            nio.write(io.getvalue().encode("utf-8"))
            io = nio
            io.seek(0)
        response = self.app.post(
            "/upload",
            buffered=True,
            data={"excel": (io, "test.csv")},
            content_type="multipart/form-data",
github pyexcel / pyexcel-xlsx / tests / test_formatters.py View on Github external
def test_writing_date_format(self):
        import datetime

        excel_filename = "testdateformat.xlsx"
        data = [
            [
                datetime.date(2014, 12, 25),
                datetime.time(11, 11, 11),
                datetime.datetime(2014, 12, 25, 11, 11, 11),
            ]
        ]
        pe.save_as(dest_file_name=excel_filename, array=data)
        r = pe.get_sheet(file_name=excel_filename, library="pyexcel-xlsx")
        assert isinstance(r[0, 0], datetime.date) is True
        assert r[0, 0].strftime("%d/%m/%y") == "25/12/14"
        assert isinstance(r[0, 1], datetime.time) is True
        assert r[0, 1].strftime("%H:%M:%S") == "11:11:11"
        assert isinstance(r[0, 2], datetime.date) is True
        assert r[0, 2].strftime("%d/%m/%y %H:%M:%S") == "25/12/14 11:11:11"
        os.unlink(excel_filename)
github pyexcel / pyexcel / tests / test_signature_fuction.py View on Github external
def test_force_file_type_for_save_book_as(self):
        pe.save_as(
            bookdict={"sheet1": [[1, 2]]},
            dest_file_name="a.bin",
            dest_force_file_type="xls",
        )
        actual = pe.get_book_dict(file_name="a.bin", force_file_type="xls")
        eq_({"sheet1": [[1, 2]]}, actual)
        os.unlink("a.bin")
github pyexcel / pyexcel / tests / test_signature_fuction.py View on Github external
def test_source_library_parameter_1():
    data = [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]
    pe.save_as(
        array=data,
        dest_file_name="test_file.xls",
        dest_source_library="pyexcel-unknown",
    )
github awemulya / kobo-predict / onadata / apps / fieldsight / tasks.py View on Github external
try:
            for site in sites:
                # import pdb; pdb.set_trace();
                
                site_row = [site['identifier'], site['name'], site['region__identifier'], site['address'], site_dict[site.get('id')]['latitude'], site_dict[site.get('id')]['longitude'], site_dict[site.get('id')]['site_status']]
                
                for stage in ss_index:
                    site_row.append(site.get(stage, ""))

                site_row.extend([site_dict[site.get('id')]['visits'], site['submission'], site['flagged'], site['rejected']])

                data.append(site_row)
        except:
            pass

        p.save_as(array=data, dest_file_name="media/stage-report/{}_stage_data.xls".format(project.id))
        xl_data = open("media/stage-report/{}_stage_data.xls".format(project.id), "rb")
        
        #Its only quick fix for now, save it in aws bucket whenever possible.

        task.file.name = xl_data.name
        task.status = 2
        task.save()
        noti = task.logs.create(source=task.user, type=32, title="Site Stage Progress report generation in Project",
                                   recipient=task.user, content_object=project, extra_object=project,
                                   extra_message=" <a href="/&quot;+ &quot;media/stage-report/{}_stage_data.xls&quot;.format(project.id) +&quot;">Site Stage Progress report </a> generation in project")
    except Exception as e:
        task.description = "ERROR: " + str(e.message) 
        task.status = 3
        task.save()
        print 'Report Gen Unsuccesfull. %s' % e
        print e.__dict__