Beispiel #1
0
def test_issue_83_ods_file_handle():
    # this proves that odfpy
    # does not leave a file handle open at all
    proc = psutil.Process()
    test_file = get_fixtures("issue_61.ods")
    open_files_l1 = proc.open_files()

    # start with a csv file
    data = pe.iget_array(file_name=test_file, library="pyexcel-ods")
    open_files_l2 = proc.open_files()
    delta = len(open_files_l2) - len(open_files_l1)
    # cannot catch open file handle
    assert delta == 0

    # now the file handle get opened when we run through
    # the generator
    list(data)
    open_files_l3 = proc.open_files()
    delta = len(open_files_l3) - len(open_files_l1)
    # cannot catch open file handle
    assert delta == 0

    # free the fish
    pe.free_resources()
    open_files_l4 = proc.open_files()
    # this confirms that no more open file handle
    eq_(open_files_l1, open_files_l4)
Beispiel #2
0
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 21 21:04:54 2019

@author: x230
"""

import pyexcel as p

records = p.iget_records(file_name="your_file.xls")

for record in records:

    print("%s is aged at %d" % (record['Name'], record['Age']))

p.free_resources()
Beispiel #3
0
def test_isave_book_as():
    content = _produce_ordered_dict()
    io = pe.isave_book_as(dest_file_type="xls", bookdict=content)
    book2 = pe.get_book(file_content=io.getvalue(), file_type="xls")
    assert book2.to_dict() == content
    pe.free_resources()
Beispiel #4
0
 def tearDown(self):
     pe.free_resources()
Beispiel #5
0
import pyexcel as pe
from pptx import Presentation

print("""
    Exemplo de criação de apresentação PPTX simples utilizando dados de Excel
    Day 24 Code Python - 23/05/2018
""")

records = pe.iget_records(file_name="/mnt/VersaoBeta/Python/PythonBasico/Projetos/apresentacao_automatica.xlsx")

texto = ['python-pptx funcionou legal!']

for record in records:
    texto.append(str(record['nome']) + ' com idade ' + str(record['idade']))

pe.free_resources()

prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]

title.text = "Yes mano!"
subtitle.text = str(texto)

prs.save('/mnt/VersaoBeta/Python/PythonBasico/Projetos/apresentacao_automatica.pptx')

print(texto)
Beispiel #6
0
 def free_resources(self):
     """
     After you have used iget_array and iget_records, it's
     recommended to call this function
     """
     pe.free_resources()
Beispiel #7
0
    "Age": 28
}, {
    "Name": 'Beatrice',
    "Age": 29
}, {
    "Name": 'Ceri',
    "Age": 30
}, {
    "Name": 'Dean',
    "Age": 26
}]
pyexcel.save_as(records=a_list_of_dictionaries,
                dest_file_name="your_file.xlsx")

records = pyexcel.iget_records(file_name="your_file.xlsx")
print(type(records))

for record in records:
    print("%s is aged at %d" % (record['Name'], record['Age']))

# search_field = 'Name'
# search_sub_field = 'Beatrice'

for record in records:
    # print(type(record['Name']))
    # if record[search_field] == record[search_sub_field]:
    #     print("oh hi, it's me!! | ")
    print("%s is aged at %d" % (record['Name'], record['Age']))

pyexcel.free_resources()