Read and write excel files using table descriptors.
Project description
Use descriptors to get and set Excel table values.
Update
Version 2.0.0 attempts to support openpyxl in the event you do not have Excel on your machine. This support is incomplete and does not have all of the Constants and methods populated. Switching between backends may not be supported.
Another change is how we import the constants. All constants were moved to xl_tables.constants In older versions you could use xl_tables.xlDouble. Now you must use xl_tables.constants.xlDouble
To change the backend call xl_tables.change_backend(windows=True).
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xl_tables-2.0.0.tar.gz.
File metadata
- Download URL: xl_tables-2.0.0.tar.gz
- Upload date:
- Size: 45.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b16beb283e258efab54827ca6fd5c5fe6002bc541700151354cc81cae42d18a
|
|
| MD5 |
089ca9ce7d6d8869f625225db340fa57
|
|
| BLAKE2b-256 |
05fe59908ce900df7241705e4265e9ae4ad15a3a0d2832ac0367a3e54fdae67f
|
File details
Details for the file xl_tables-2.0.0-py3-none-any.whl.
File metadata
- Download URL: xl_tables-2.0.0-py3-none-any.whl
- Upload date:
- Size: 41.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc534c7c213278aa4bdc474adc566d2d90edd9024b614f150e7815a86ce52679
|
|
| MD5 |
d83051cd83e8b49f6a10d473e3478635
|
|
| BLAKE2b-256 |
568abca5d619daf1a9c2f7b17acf7ee7691a803615467182984c0ae19516d073
|