Skip to main content

Read and write excel files using table descriptors.

Project description

Use descriptors to get and set Excel table values.

Examples

import xl_tables as xl
import datetime

class MyTable(xl.Table):
    label_first = xl.Constant('First Name', (1, 1))  # Constants initialize their value on Table creation
    first_name = xl.Cell((1, 2))
    label_last = xl.Constant('Last Name', (2, 1))
    last_name = xl.Cell(2, 2)
    label_now = xl.Constant('Now', (3, 1))
    now = xl.DateTime(3, 2)
    label_today = xl.Constant('Today', (4, 1))
    today = xl.Date(4, 2)
    label_time = xl.Constant('Time', (5, 1))
    time = xl.Time(5, 2)

    header = xl.Constant(['Data 1', 'Data 2', 'Data 3'], rows=7, row_length=3)
    array_item = xl.RangeItem('A8:C10')  # Contiguous Range is preferable
    array = xl.Range('A8:C10')
    # array_item = xl.RowItem(8, 9, 10, row_length=3)
    # array = xl.Row(8, 9, 10, row_length=3)

tbl = MyTable()

tbl.first_name = 'John'
tbl.last_name = 'Doe'
tbl.now = datetime.datetime.now()
tbl.today = datetime.datetime.today()
tbl.time = datetime.time(20, 1, 1)  # datetime.datetime.now().time()

tbl.array = [(1, 2, 3),
             (4, 5, 6),
             (7, 8, 9)]

# Make a border around the cells in the table
tbl.array_item.Borders(xl.xlEdgeTop).LineStyle = xl.xlDouble

text = '{lbl1} = {opt1}\n' \
       '{lbl2} = {opt2}\n' \
       '{lbl3} = {now}\n' \
       '{lbl4} = {today}\n' \
       '{lbl5} = {time}\n' \
       '\n' \
       '{header}\n' \
       '{arr}\n'.format(lbl1=tbl.label_first, opt1=tbl.first_name, lbl2=tbl.label_last, opt2=tbl.last_name,
                        lbl3=tbl.label_now, now=tbl.now, lbl4=tbl.label_today, today=tbl.today,
                        lbl5=tbl.label_time, time=tbl.time,
                        header=tbl.get_row_text(tbl.header, delimiter=', '),
                        arr=tbl.get_table_text(tbl.array, delimiter=', '))

with open('person_text.txt', 'w') as f:
    f.write(text)
print('===== Manual Text =====')
print(text)
print('===== End =====')

# Short function provided for this
txt = tbl.get_table_text(tbl.array, header=tbl.header, head={tbl.label_first: tbl.first_name,
                                                             tbl.label_last: tbl.last_name,
                                                             tbl.label_now: tbl.now,
                                                             tbl.label_today: tbl.today,
                                                             tbl.label_time: tbl.time})
print('===== Get Table Text =====')
print(txt)
print('===== End =====')

tbl.save('person.txt')  # 'person.txt' or '.tsv' will save every cell separated by '\t'
tbl.save('person.csv')  # 'person.csv' will save every cell separated by ','
tbl.save('person.xlsx')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xl_tables-0.0.1.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xl_tables-0.0.1-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

Details for the file xl_tables-0.0.1.tar.gz.

File metadata

  • Download URL: xl_tables-0.0.1.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.1

File hashes

Hashes for xl_tables-0.0.1.tar.gz
Algorithm Hash digest
SHA256 702685a1621e0fb8238fcbcb06512640520b215b76dd264bca9719f571bcb96b
MD5 cb6870a2c9a5a8ca9ecd70219dd2aa69
BLAKE2b-256 5cc5a3c948f8c284d8784c2049df7e80959890d7f6b883abfa54033842895c2b

See more details on using hashes here.

File details

Details for the file xl_tables-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: xl_tables-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 60.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.1

File hashes

Hashes for xl_tables-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 027652157a77e9f773fe1f4b8698431767bf168b72901db364ade9b472b0576d
MD5 38ba5db89a363f46bc7e88d43504c463
BLAKE2b-256 78f8c9beb3dda850573dbad2ad1eed2425818429495e6328c58f8b47953c34c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page