Python library for writing CSV and XLS files from list of OrderedDict or just a list of lists containing 2-item tuples.
pip install excellent
Writing Excel files
from collections import OrderedDict
from excellent import Writer, XL
output = open("superhero-database.xls", "wb")
sheet_manager = XL()
excel = Writer(sheet_manager, output)
sheet_manager.use_sheet("Weaknesses")
excel.write([
OrderedDict([('Superhero', 'Superman'), ('Weakness', 'Kryptonite')]),
OrderedDict([('Superhero', 'Spiderman'), ('Weakness', 'Maryjane')]),
])
sheet_manager.use_sheet("Special Powers")
excel.write([
OrderedDict([('Superhero', 'Superman'), ('Super Powers', 'X-Ray vision')]),
OrderedDict([('Superhero', 'Spiderman'), ('Super Powers', 'Release web')]),
OrderedDict([('Superhero', 'Batman'), ('Super Powers', 'Money')]),
])
sheet_manager.use_sheet("Weaknesses")
excel.write([
OrderedDict([('Superhero', 'Batman'), ('Weakness', 'Social Interactions')]),
])
# save it
excel.save()
# now open superhero-database.xls and be happy
from collections import OrderedDict
from excellent import Writer, CSV
output = open("pokemon-database.csv", "w")
csv = Writer(CSV(delimiter=';'), output)
csv.write([
OrderedDict([('Name', 'Pikachu'), ('Type', 'Electric')]),
OrderedDict([('Name', 'Jigglypuff'), ('Type', 'Normal')]),
OrderedDict([('Name', 'Mew'), ('Type', 'Psychic')]),
])
# save it
csv.save()
# now open pokemon.csv and be happy
Name;Type
Pikachu;Electric
Jigglypuff;Normal
Mew;Psychic
excel.write([
OrderedDict([('Superhero', 'Batman'), ('Weakness', 'Social Interactions')]),
],
bold=True,
bottom_border=True,
)
excel.write([
OrderedDict([('Superhero', 'Batman'), ('Weakness', 'Social Interactions')]),
],
format_string='"$"#,##0_);("$"#,##',
)
See the examples for uses.
from xlwt import XFStyle, Alignment
alignment = Alignment()
alignment.horz = Alignment.HORZ_RIGHT
style = XFStyle()
style.alignment = alignment
excel.write([
OrderedDict([('Superhero', 'Batman'), ('Weakness', 'Social Interactions')]),
],
style=style,
)
from xlwt import XFStyle, Alignment
alignment = Alignment()
alignment.horz = Alignment.HORZ_RIGHT
style = XFStyle()
style.alignment = alignment
backend = XL(default_style=style)
output = open("database.csv", "w")
writer = Writer(backend=backend, output=output)
Excellent.exceptions.TooManyRowsError
: This exception is raised if too many rows are written to an excel spreadsheet.
pip install -r requirements.txt
make unit
make functional
Please check the COPYING
file distributed with this library