Giter Club home page Giter Club logo

excellent's Introduction

Excellent (v0.0.5)

Python library for writing CSV and XLS files from list of OrderedDict or just a list of lists containing 2-item tuples.

Installing

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

https://raw.github.com/Yipit/excellent/master/docs/superhero-database.png

Writing CSV files

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

pokemon-database.csv:

Name;Type
Pikachu;Electric
Jigglypuff;Normal
Mew;Psychic

Styles

excel.write([
    OrderedDict([('Superhero', 'Batman'), ('Weakness', 'Social Interactions')]),
    ],
    bold=True,
    bottom_border=True,
)

Format Strings

excel.write([
    OrderedDict([('Superhero', 'Batman'), ('Weakness', 'Social Interactions')]),
    ],
    format_string='"$"#,##0_);("$"#,##',
)

See the examples for uses.

Custom Styles

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,
)

Default 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)

Exceptions

Excellent.exceptions.TooManyRowsError: This exception is raised if too many rows are written to an excel spreadsheet.

Hacking

Install dependencies

pip install -r requirements.txt

Run the tests

make unit
make functional

Licensing

Please check the COPYING file distributed with this library

excellent's People

Contributors

gabrielfalcao avatar spulec avatar suneel0101 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.