• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pyexcel.save_book_as函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyexcel.save_book_as函数的典型用法代码示例。如果您正苦于以下问题:Python save_book_as函数的具体用法?Python save_book_as怎么用?Python save_book_as使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了save_book_as函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: Open

 def Open(self):
     try:
         if not os.path.isfile(self.v_filename):
             raise Spartacus.Utils.Exception('File {0} does not exist or is not a file.'.format(self.v_filename))
         if self.v_extension == 'csv':
             self.v_file = open(self.v_filename, encoding=self.v_encoding)
             v_sample = self.v_file.read(1024)
             self.v_file.seek(0)
             v_sniffer = csv.Sniffer()
             if not v_sniffer.has_header(v_sample):
                 raise Spartacus.Utils.Exception('CSV file {0} does not have a header.'.format(self.v_filename))
             v_dialect = v_sniffer.sniff(v_sample)
             if self.v_delimiter is not None:
                 v_dialect.delimiter = self.v_delimiter
             self.v_object = csv.DictReader(self.v_file, self.v_header, None, None, v_dialect)
             self.v_open = True
         elif self.v_extension == 'xlsx':
             self.v_object = openpyxl.load_workbook(self.v_filename, read_only=True)
             self.v_open = True
         elif self.v_extension == 'xls':
             v_tmp_file = tempfile.NamedTemporaryFile(suffix='.xlsx')
             v_tmp_file.file.close()
             pyexcel.save_book_as(file_name=self.v_filename, dest_file_name=v_tmp_file.name)
             self.v_object = openpyxl.load_workbook(v_tmp_file.name, read_only=True)
             self.v_open = True
         else:
             raise Spartacus.Utils.Exception('File extension "{0}" not supported.'.format(self.v_extension))
     except Spartacus.Utils.Exception as exc:
         raise exc
     except Exception as exc:
         raise Spartacus.Utils.Exception(str(exc))
开发者ID:wind39,项目名称:spartacus,代码行数:31,代码来源:Utils.py


示例2: setUp

 def setUp(self):
     self.testfile = "multiple1.xls"
     self.content = OrderedDict()
     self.content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
     self.content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
     self.content.update({"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
     pe.save_book_as(dest_file_name=self.testfile, bookdict=self.content)
开发者ID:dardevelin,项目名称:pyexcel,代码行数:7,代码来源:test_multiple_sheets.py


示例3: test_save_book_as_to_database

 def test_save_book_as_to_database(self):
     data = [
         ["X", "Y", "Z"],
         [1, 2, 3],
         [4, 5, 6]
     ]
     data1 = [
         ["A", "B", "C"],
         [1, 2, 3],
         [4, 5, 6]
     ]
     sheet_dict = {
         Signature.__tablename__: data,
         Signature2.__tablename__: data1
     }
     pe.save_book_as(bookdict=sheet_dict,
                     dest_session=self.session,
                     dest_tables=[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]
     }
开发者ID:ChiangFamily,项目名称:pyexcel,代码行数:30,代码来源:test_signature_fuction.py


示例4: diff

def diff(source_file_type, file_type, source, dest):
    """
    Find difference in plain data format

    Both files are transcoded into a file stream of a common file type.
    Then a diff operation is run on them.

    \b
    SOURCE: a file name or '-'. '-' tells the command to use stdin
    DEST: a file name
    """
    params = {}
    if source == '-':
        params['file_content'] = get_input_content(source_file_type)
        params['file_type'] = source_file_type
    else:
        params['file_name'] = source
    params['dest_file_type'] = file_type
    source_lines = pe.save_book_as(**params)
    dest_lines = pe.save_book_as(file_name=dest,
                                 dest_file_type=file_type)
    result = unified_diff(source_lines.getvalue().splitlines(),
                          dest_lines.getvalue().splitlines(),
                          source, dest)
    has_difference = 0
    for difference in result:
        has_difference = 1
        click.echo(difference)
    sys.exit(has_difference)
开发者ID:pyexcel,项目名称:pyexcel-cli,代码行数:29,代码来源:diff.py


示例5: test_dict

    def test_dict(self):
        adict = {
            'sheet 1': [[1,2],[3,4]],
            'sheet 2': [[5,6],[7,8]]
        }
        pe.save_book_as(bookdict=adict, dest_file_name=self.testfile)

        self._check_test_file('dict')
开发者ID:jayvdb,项目名称:pyexcel-text,代码行数:8,代码来源:test_io.py


示例6: setUp

 def setUp(self):
     self.testfile4 = "multiple_sheets.xls"
     self.content4 = {
         "Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],
         "Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]],
         "Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
     }
     pe.save_book_as(dest_file_name=self.testfile4,
                     bookdict=self.content4)
开发者ID:CHEN-JIANGHANG,项目名称:pyexcel,代码行数:9,代码来源:test_cookbook.py


示例7: test_dict

 def test_dict(self):
     adict = {
         'sheet 1': [[1,2],[3,4]],
         'sheet 2': [[5,6],[7,8]]
     }
     pe.save_book_as(bookdict=adict, dest_file_name=self.testfile)
     with open(self.testfile, "r") as f:
         written_content = json.load(f)
         assert written_content == adict
开发者ID:i3visio,项目名称:pyexcel-text,代码行数:9,代码来源:test_io.py


示例8: test_no_title_multiple_sheets

    def test_no_title_multiple_sheets(self):
        adict = {
            'sheet 1': [[1,2],[3,4]],
            'sheet 2': [[5,6],[7,8]]
        }
        pe.save_book_as(bookdict=adict, dest_file_name=self.testfile,
                        dest_write_title=False)

        self._check_test_file('no_title_multiple_sheets')
开发者ID:jayvdb,项目名称:pyexcel-text,代码行数:9,代码来源:test_io.py


示例9: test_save_book_as_file_from_sql

 def test_save_book_as_file_from_sql(self):
     test_file = "book_from_sql.xls"
     pe.save_book_as(out_file=test_file, session=Session(), tables=[Signature, Signature2])
     book_dict = pe.get_book_dict(file_name=test_file)
     expected = OrderedDict()
     expected.update({"signature": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]})
     expected.update({"signature2": [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]})
     assert book_dict == expected
     os.unlink(test_file)
开发者ID:bdeeney,项目名称:pyexcel,代码行数:9,代码来源:test_signature_fuction.py


示例10: _write_test_file

    def _write_test_file(self, filename, content):
        """
        Make a test file as:

        1,1,1,1
        2,2,2,2
        3,3,3,3
        """
        pe.save_book_as(dest_file_name=filename, bookdict=content)
开发者ID:ChiangFamily,项目名称:pyexcel,代码行数:9,代码来源:test_multiple_sheets.py


示例11: _write_test_file

    def _write_test_file(self, file):
        """
        Make a test file as:

        1,1,1,1
        2,2,2,2
        3,3,3,3
        """
        self.rows = 3
        pyexcel.save_book_as(bookdict=self.content,dest_file_name=file)
开发者ID:mromero107,项目名称:pyexcel-xls,代码行数:10,代码来源:test_mutliple_sheets.py


示例12: test_save_book_as_file_from_sql

 def test_save_book_as_file_from_sql(self):
     test_file="book_from_sql.xls"
     pe.save_book_as(out_file=test_file,
                     session=Session(),
                     tables=[Signature, Signature2])
     book_dict = pe.get_book_dict(file_name=test_file)
     expected = OrderedDict()
     expected.update({'signature': [['X', 'Y', 'Z'], [1, 2, 3], [4, 5, 6]]})
     expected.update({'signature2': [['A', 'B', 'C'], [1, 2, 3], [4, 5, 6]]})
     assert book_dict == expected
     os.unlink(test_file)
开发者ID:dardevelin,项目名称:pyexcel,代码行数:11,代码来源:test_signature_fuction.py


示例13: save_book_to_database

 def save_book_to_database(self, models=None, initializers=None,
                           mapdicts=None, batch_size=None,
                           **keywords):
     """
     Save data from a book to a nominated django models
     """
     params = self.get_params(**keywords)
     params['dest_models'] = models
     params['dest_initializers']=initializers
     params['dest_mapdicts'] = mapdicts
     params['dest_batch_size'] = batch_size
     pe.save_book_as(**params)
开发者ID:andersonfr,项目名称:Project,代码行数:12,代码来源:__init__.py


示例14: test_dict

 def test_dict(self):
     adict = {
         'sheet 1': [[1,2],[3,4]],
         'sheet 2': [[5,6],[7,8]]
     }
     pe.save_book_as(bookdict=adict, dest_file_name=self.testfile)
     f = open(self.testfile, "r")
     written_content = f.read()
     f.close()
     content = dedent("""
         {"sheet 1": [[1, 2], [3, 4]], "sheet 2": [[5, 6], [7, 8]]}""").strip('\n')
     assert written_content == content
开发者ID:fuhrysteve,项目名称:pyexcel-text,代码行数:12,代码来源:test_io.py


示例15: test_write_texttable_book

def test_write_texttable_book():
    content = {"Sheet": [[1,2]]}
    test_file = "test.texttable"
    expected = dedent("""
    Sheet:
    +---+---+
    | 1 | 2 |
    +---+---+""").strip('\n')
    pe.save_book_as(bookdict=content, dest_file_name=test_file)
    with open(test_file, 'r') as f:
        written = f.read()
        eq_(written, expected)
    os.unlink(test_file)
开发者ID:dardevelin,项目名称:pyexcel,代码行数:13,代码来源:test_fileio.py


示例16: test_save_book_to_memory_from_sql

 def test_save_book_to_memory_from_sql(self):
     test_file = pe.save_book_as(dest_file_type="xls", session=Session(), tables=[Signature, Signature2])
     book_dict = pe.get_book_dict(file_content=test_file.getvalue(), file_type="xls")
     expected = OrderedDict()
     expected.update({"signature": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]})
     expected.update({"signature2": [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]})
     assert book_dict == expected
开发者ID:bdeeney,项目名称:pyexcel,代码行数:7,代码来源:test_signature_fuction.py


示例17: setUp

    def setUp(self):
        """
        Make a test csv file as:

        1,2,3,4
        5,6,7,8
        9,10,11,12
        """
        self.testfile = "testcsv.xls"
        self.content = {
            "Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],
            "Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]],
            "Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
        }
        pe.save_book_as(bookdict=self.content,
                        dest_file_name=self.testfile)
开发者ID:dardevelin,项目名称:pyexcel,代码行数:16,代码来源:test_utils.py


示例18: test_book_file

 def test_book_file(self):
     data = {
         "Category":[
             ["id", "name"],
             [1, "News"],
             [2, "Sports"]
         ],
         "Post":[
             ["id", "title", "body", "pub_date", "category"],
             [1, "Title A", "formal", datetime(2015,1,20,23,28,29), "News"],
             [2, "Title B", "informal", datetime(2015,1,20,23,28,30), "Sports"]
         ]
     }
     for upload_file_type in ['xls']:
         with app.app_context():
             db.drop_all()
             db.create_all()
         print("Uploading %s" % upload_file_type)
         file_name = "test.%s" % upload_file_type
         io = pe.save_book_as(bookdict=data, dest_file_type=upload_file_type)
         response = self.app.post('/upload/all',
                                  buffered=True,
                                  data={"file": (io, file_name)},
                                  content_type="multipart/form-data")
         ret = pe.get_book_dict(file_type="xls", file_content=response.data)
         assert data['Category'] == ret['category']
         sheet = pe.Sheet(data['Post'], name_columns_by_row=0)
         sheet.column.format("pub_date", lambda d: d.isoformat())
         sheet2 = pe.Sheet(ret['post'], name_columns_by_row=0)
         for key in sheet.colnames:
             if key == "category":
                 continue
             assert sheet.column[key] == sheet2.column[key]
         assert sheet2.column['category_id'] == [1, 2]
开发者ID:Averroes,项目名称:Flask-Excel,代码行数:34,代码来源:test_database_io.py


示例19: test_book_file

 def test_book_file(self):
     data = {
         "Category": [["id", "name"], [1, "News"], [2, "Sports"]],
         "Post": [
             ["id", "title", "body", "pub_date", "category"],
             [1, "Title A", "formal", datetime(2015, 1, 20, 23, 28, 29), "News"],
             [2, "Title B", "informal", datetime(2015, 1, 20, 23, 28, 30), "Sports"],
         ],
     }
     for upload_file_type in ["xls"]:
         print("Uploading %s" % upload_file_type)
         file_name = "test.%s" % upload_file_type
         io = pe.save_book_as(bookdict=data, dest_file_type=upload_file_type)
         if not PY2:
             if isinstance(io, BytesIO):
                 content = io.getvalue()
             else:
                 content = io.getvalue().encode("utf-8")
         else:
             content = io.getvalue()
         response = self.app.post("/upload/all", upload_files=[("file", file_name, content)])
         ret = pe.get_book_dict(file_type="xls", file_content=response.body)
         assert data["Category"] == ret["category"]
         sheet = pe.Sheet(data["Post"], name_columns_by_row=0)
         sheet.column.format("pub_date", lambda d: d.isoformat())
         sheet2 = pe.Sheet(ret["post"], name_columns_by_row=0)
         for key in sheet.colnames:
             if key == "category":
                 continue
             assert sheet.column[key] == sheet2.column[key]
         assert sheet2.column["category_id"] == [1, 2]
开发者ID:mromero107,项目名称:pyramid-excel,代码行数:31,代码来源:test_database_io.py


示例20: test_get_book_from_file_stream

 def test_get_book_from_file_stream(self):
     content = OrderedDict()
     content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
     content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
     content.update({"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
     io = pe.save_book_as(dest_file_type="xls", bookdict=content)
     book2 = pe.get_book(file_stream=io, file_type="xls")
     assert book2.to_dict() == content
开发者ID:dardevelin,项目名称:pyexcel,代码行数:8,代码来源:test_signature_fuction.py



注:本文中的pyexcel.save_book_as函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nominablesheet.NominableSheet类代码示例发布时间:2022-05-25
下一篇:
Python pyexcel.save_as函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap