Skip to content
/ xls2db Public

Old habits die hard, but at least you can now convert your spreadsheets into sqlite databases, right?

Notifications You must be signed in to change notification settings

99blues/xls2db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xls2db

xls2db is a python program that takes an excel spreadsheet following a certain schema into an sqlite database that can be opened using python's sqlite3 module. It can also be used as a module.

Why??

Because fuck you, that's why.

But seriously: I was getting sick of doing data entry for this toy project of mine using cursor.execute()'s, so I figured I'd try entering the data into an excel spreadsheet, converting it into the db, and then manipulating it from there. Crazy, I know.

Usage:

As a script:

xls2db infile.xls outfile.db

As a module:

from xls2db import xls2db
xls2db("infile.xls", "outfile.db")

Alternately, you can use an instance of xlrd.Book instead of an .xls filename, and you can use an instance of sqlite3.Connection instead of an sqlite database filename. For example:

from xls2db import xls2db
import xlrd
import sqlite3 as sqlite

db = sqlite.connect(":memory:")
xls2db(xlrd.open_workbook("infile.xls"), db)

Schema:

Each worksheet represents a table with that name. Each table is written with headers corresponding to column names/types/etc. expected in an sqlite database, and the rest of the rows are, well, rows. For example, I have data in a worksheet called "links" that looks like this:

src string  dst string  dir string
kitchen     outside     West
kitchen     w_hwy       East
w_hwy       ctr_hwy     East
ctr_hwy     e_hwy       East
e_hwy       living      East
w_hwy       w_bath      North
ctr_hwy     e_bath      North
w_hwy       josh_bdr    South
ctr_hwy     guest_bdr   South
e_hwy       james_bdr   South

If you're familiar with sql, this probably makes sense. Somewhat.

Installation:

sudo pip install -U xls2db

Dependencies:

  • xlrd
  • xlwt
  • plac (for command line args)

Tests:

I haven't written any yet, because I'm lazy.

Developers! Developers! Developers!

I suspect most of you are stabbing your eyes out with rusty nails. If you're not, however, why not give it a try? Help me track down some bugs? Fix anything that seems like it's begging for sql injection?

License:

MIT.

About

Old habits die hard, but at least you can now convert your spreadsheets into sqlite databases, right?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages