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-1.0.2.tar.gz
(29.9 kB
view details)
Built Distribution
xl_tables-1.0.2-py3-none-any.whl
(68.0 kB
view details)
File details
Details for the file xl_tables-1.0.2.tar.gz
.
File metadata
- Download URL: xl_tables-1.0.2.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44c59d33426ccf1f6eb8fa6001bfd4e45f63cd73a26c36ee0ed6e2256ded00ea |
|
MD5 | aeec972e77af8f742192c29b04e1992e |
|
BLAKE2b-256 | cc7d225279295bd718fbf3c57d9941ef2469ea3cea2d4055bb902636866b1206 |
File details
Details for the file xl_tables-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: xl_tables-1.0.2-py3-none-any.whl
- Upload date:
- Size: 68.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af186085c9b679f38f2508e6cc086717b4ccac27583c71098923c51ebc4ee686 |
|
MD5 | 6f9192f1b015f5b0017337187ae21696 |
|
BLAKE2b-256 | 2047cff9184021ba7fb1206b46180c2a1e12d031dd7750361ef14ee393685eab |