當前位置: 首頁>>代碼示例>>Python>>正文


Python pyexcel.save_as方法代碼示例

本文整理匯總了Python中pyexcel.save_as方法的典型用法代碼示例。如果您正苦於以下問題:Python pyexcel.save_as方法的具體用法?Python pyexcel.save_as怎麽用?Python pyexcel.save_as使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyexcel的用法示例。


在下文中一共展示了pyexcel.save_as方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_xls_output_stringio

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def test_xls_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())
        result = [1, 2, 3, 4, 5, 6]
        actual = list(r.enumerate())
        eq_(result, actual) 
開發者ID:pyexcel,項目名稱:pyexcel-xlsxw,代碼行數:12,代碼來源:test_stringio.py

示例2: test_writing_date_format

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def test_writing_date_format(self):
        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-xls")
        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) 
開發者ID:pyexcel,項目名稱:pyexcel-xlsxw,代碼行數:16,代碼來源:test_formatters.py

示例3: create_sample_file1

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def create_sample_file1(file):
    data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1]
    table = []
    table.append(data[:4])
    table.append(data[4:8])
    table.append(data[8:12])
    pyexcel.save_as(array=table, dest_file_name=file) 
開發者ID:pyexcel,項目名稱:pyexcel-xlsxw,代碼行數:9,代碼來源:base.py

示例4: test_series_table

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
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) 
開發者ID:pyexcel,項目名稱:pyexcel-xlsxw,代碼行數:6,代碼來源:base.py

示例5: _create_a_file

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def _create_a_file(self, file):
        pyexcel.save_as(dest_file_name=file, array=self.content) 
開發者ID:pyexcel,項目名稱:pyexcel-xlsxw,代碼行數:4,代碼來源:base.py

示例6: test_ods_output_stringio

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def test_ods_output_stringio(self):
        data = [
            [1, 2, 3],
            [4, 5, 6]
        ]
        io = pyexcel.save_as(dest_file_type="ods",
                             array=data)
        r = pyexcel.get_sheet(file_type="ods", file_content=io.getvalue())
        result = [1, 2, 3, 4, 5, 6]
        actual = list(r.enumerate())
        eq_(result, actual) 
開發者ID:pyexcel,項目名稱:pyexcel-odsr,代碼行數:13,代碼來源:test_stringio.py

示例7: setUp

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def setUp(self):
        self.content = [[1, 2, 3.1]]
        self.test_file = "test_auto_detect_init.ods"
        pe.save_as(array=self.content, dest_file_name=self.test_file) 
開發者ID:pyexcel,項目名稱:pyexcel-odsr,代碼行數:6,代碼來源:test_formatters.py

示例8: handle

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def handle(self, *args, **options):
        self.stdout.write('Successfully created .. ')
        data = []
        ss_index = {}
        stages_rows = []
        head_row = ["Site ID", "Name", "Address", "Latitude", "longitude", "Status"]
        project = Project.objects.get(pk=1)
        stages = project.stages.filter(stage__isnull=True)
        for stage in stages:
            sub_stages = stage.parent.all()
            if len(sub_stages):
                head_row.append("Stage :" + stage.name)
                stages_rows.append("Stage :" + stage.name)

                for ss in sub_stages:
                    head_row.append("Sub Stage :" + ss.name)
                    ss_index.update({head_row.index("Sub Stage :" + ss.name): ss.id})
        data.append(head_row)
        total_cols = len(head_row) - 6  # for non stages
        for site in project.sites.filter(is_active=True, is_survey=False):
            site_row = [site.identifier, site.name, site.address, site.latitude, site.longitude, site.status]
            site_row.extend([None] * total_cols)
            for k, v in ss_index.items():
                if Stage.objects.filter(project_stage_id=v, site=site).count() == 1:
                    site_sub_stage = Stage.objects.get(project_stage_id=v, site=site)
                    site_row[k] = site_sub_stage.form_status
            data.append(site_row)

        p.save_as(array=data, dest_file_name="media/stage-report/{}_stage_data.xls".format(project.id)) 
開發者ID:awemulya,項目名稱:fieldsight-kobocat,代碼行數:31,代碼來源:excel_data_substages.py

示例9: stages_status_download

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def stages_status_download(request, pk):
    try:
        data = []
        ss_index = {}
        stages_rows = []
        head_row = ["Site ID", "Name", "Address", "Latitude", "longitude", "Status"]
        project = Project.objects.get(pk=pk)
        stages = project.stages.filter(stage__isnull=True)
        for stage in stages:
            sub_stages = stage.parent.all()
            if len(sub_stages):
                head_row.append("Stage :"+stage.name)
                stages_rows.append("Stage :"+stage.name)

                for ss in sub_stages:
                    head_row.append("Sub Stage :"+ss.name)
                    ss_index.update({head_row.index("Sub Stage :"+ss.name): ss.id})
        data.append(head_row)
        total_cols = len(head_row) - 6 # for non stages
        for site in project.sites.filter(is_active=True, is_survey=False):
            site_row = [site.identifier, site.name, site.address, site.latitude, site.longitude, site.status]
            site_row.extend([None]*total_cols)
            for k, v in ss_index.items():
                if Stage.objects.filter(project_stage_id=v, site=site).count() == 1:
                    site_sub_stage = Stage.objects.get(project_stage_id=v, site=site)
                    site_row[k] = site_sub_stage.form_status
            data.append(site_row)

        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")
        response = HttpResponse(xl_data, content_type='application/vnd.ms-excel')
        response['Content-Disposition'] = 'attachment; filename="report.xls"'
        return response
    except Exception as e:
        messages.info(request, 'Data Creattion Failed {}'.format(str(e)))
    return HttpResponse("failed Data Creattion Failed {}".format(str(e))) 
開發者ID:awemulya,項目名稱:fieldsight-kobocat,代碼行數:38,代碼來源:views.py

示例10: get_xlsx

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def get_xlsx(curent_dir):
    wdata = []
    wdata.append(['IP', '??', '??', '??', '??', '??'])
    wdata.extend(traverse_dir(curent_dir))
    wfile = '[email protected]{}.xlsx'.format(time.strftime(ISOTIMEFORMAT, time.localtime(time.time())))
    try:
        pyexcel.save_as(array=wdata, dest_file_name=wfile)
    except:
        print('Build xlsx error!')
        return False
    print('Successful output file: {}'.format(wfile)) 
開發者ID:Shad0wpf,項目名稱:SecTools,代碼行數:13,代碼來源:Get_html_portInfo_from_RSAS_Repo@20161116.py

示例11: get_xlsx

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def get_xlsx(self):
        try:
            pyexcel.save_as(array=self.array,
                            dest_file_name=self.xlsx_name,
                            dest_sheet_name=self.sheet)
        except KeyboardInterrupt as e:
            print(str(e))
            return False
        print('Successful output file: {}'.format(self.xlsx_name)) 
開發者ID:Shad0wpf,項目名稱:SecTools,代碼行數:11,代碼來源:Get_vul_from_RSAS_Repo.py

示例12: transcode

# 需要導入模塊: import pyexcel [as 別名]
# 或者: from pyexcel import save_as [as 別名]
def transcode(source_file_type, output_file_type,
              sheet_name, sheet_index,
              name_columns_by_row, name_rows_by_column,
              csv_source_delimiter, csv_source_encoding,
              csv_source_lineterminator, csv_source_quotechar,
              csv_source_escapechar, csv_source_quoting,
              csv_source_no_doublequote,
              csv_output_delimiter, csv_output_encoding,
              csv_output_lineterminator, csv_output_quotechar,
              csv_output_escapechar, csv_output_quoting,
              csv_output_no_doublequote,
              source, output):
    """
    Trancode an excel file from one format to another.

    \b
    SOURCE: a file name or '-'. '-' tells the command to use stdin
    OUTPUT: a file name or '-'. '-' tells the command to use stdout
    """
    params = {}
    if source == '-':
        params['file_content'] = get_input_content(source_file_type)
        params['file_type'] = source_file_type
    elif source.startswith("http"):
        params['url'] = source
    else:
        params['file_name'] = source
    if output == '-':
        params['dest_file_stream'] = get_output_stream(output_file_type)
        params['dest_file_type'] = output_file_type
    else:
        params['dest_file_name'] = output

    if source_file_type == 'csv' or source.endswith('csv'):
        csv_params = _make_csv_params(
            csv_source_lineterminator, csv_source_encoding,
            csv_source_delimiter, csv_source_quoting,
            csv_source_quotechar, csv_source_escapechar,
            csv_source_no_doublequote)
        params.update(csv_params)

    if output_file_type == 'csv' or output.endswith('csv'):
        csv_params = _make_csv_params(
            csv_output_lineterminator, csv_output_encoding,
            csv_output_delimiter, csv_output_quoting,
            csv_output_quotechar, csv_output_escapechar,
            csv_output_no_doublequote, prefix="dest_")
        params.update(csv_params)

    sheet_parameters = [sheet_name, sheet_index,
                        name_columns_by_row, name_rows_by_column]
    if _is_sheet_operation(sheet_parameters):
        if name_columns_by_row is not None:
            params['name_columns_by_row'] = name_columns_by_row
        elif name_rows_by_column is not None:
            params['name_rows_by_column'] = name_rows_by_column
        params['sheet_name'] = sheet_name
        params['sheet_index'] = sheet_index
        pe.save_as(**params)
    else:
        pe.save_book_as(**params) 
開發者ID:pyexcel,項目名稱:pyexcel-cli,代碼行數:63,代碼來源:transcode.py


注:本文中的pyexcel.save_as方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。