Skip to content

Commit 1fd67b9

Browse files
committed
SQL convert from xlsx
0 parents  commit 1fd67b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+26162
-0
lines changed

Indentwise-Menu.sql

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

Indentwise-Menu.xlsx

18.2 MB
Binary file not shown.

sqlconvert.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#-*- coding: utf-8 -*-
2+
import xlrd
3+
#import csv
4+
from os import sys
5+
6+
# Example of sql query template:
7+
TEMPLATE_TABLE_1 = 'insert into TABLE_NAME(col1, col2, col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13,col14,col15,col16) values("{0}", "{1}", "{2}","{3}","{4}","{5}","{6}","{7}","{8}","{9}","{10}","{11}","{12}","{13}","{14}","{15}");';
8+
# Edit the above line to the required schema
9+
10+
def convert(excel_file):
11+
try:
12+
excel = xlrd.open_workbook(excel_file)
13+
except:
14+
print 'Error the file {0}, not found ;('.format(excel_file)
15+
exit(0)
16+
17+
all_sheets = excel.sheet_names()
18+
for sheet_name in all_sheets:
19+
sheet = excel.sheet_by_name(sheet_name)
20+
21+
my_sql = open(''.join([sheet_name, '.sql']), 'w+')
22+
23+
#my_csv = open(''.join([sheet_name, '.csv']), 'wb')
24+
#writer = csv.writer(my_csv, quoting=csv.QUOTE_ALL)
25+
26+
for row in xrange(sheet.nrows):
27+
items = []
28+
for a in sheet.row_values(row):
29+
items.append(unicode(a).encode('utf-8'))
30+
#print TEMPLATE_TABLE_1.format(items[0], items[1], items[2])
31+
my_sql.write(TEMPLATE_TABLE_1.format(items[0], items[1], items[2],items[3],items[4],items[5],items[6],items[7],items[8],items[9],items[10],items[11],items[12],items[13],items[14],items[15]))
32+
#writer.writerow([unicode(entry).encode("utf-8") for entry in sheet.row_values(row)])
33+
#my_csv.close()
34+
my_sql.close()
35+
36+
37+
if __name__ == '__main__':
38+
if len(sys.argv) == 2:
39+
convert(sys.argv[1])
40+
else:
41+
print 'the xlsx file ?'

xlrd/PKG-INFO

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Metadata-Version: 1.1
2+
Name: xlrd
3+
Version: 0.9.2
4+
Summary: Library for developers to extract data from Microsoft Excel (tm) spreadsheet files
5+
Home-page: http://www.python-excel.org/
6+
Author: John Machin
7+
Author-email: [email protected]
8+
License: BSD
9+
Description: Extract data from Excel spreadsheets (.xls and .xlsx, versions 2.0 onwards) on any platform. Pure Python (2.6, 2.7, 3.2+). Strong support for Excel dates. Unicode-aware.
10+
Keywords: xls,excel,spreadsheet,workbook
11+
Platform: Any platform -- don't need Windows
12+
Classifier: Development Status :: 5 - Production/Stable
13+
Classifier: Intended Audience :: Developers
14+
Classifier: License :: OSI Approved :: BSD License
15+
Classifier: Programming Language :: Python
16+
Classifier: Programming Language :: Python :: 2
17+
Classifier: Programming Language :: Python :: 3
18+
Classifier: Operating System :: OS Independent
19+
Classifier: Topic :: Database
20+
Classifier: Topic :: Office/Business
21+
Classifier: Topic :: Software Development :: Libraries :: Python Modules

xlrd/README.html

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv='Content-Type' content='text/html; charset=us-ascii' />
5+
<title>The xlrd Module -- README</title>
6+
</head>
7+
<body>
8+
9+
<h3>Python package "xlrd"</h3>
10+
11+
<p><b>Purpose</b>: Provide a library for developers to use to extract data
12+
from Microsoft Excel (tm) spreadsheet files.
13+
It is not an end-user tool.
14+
</p>
15+
<p><b>Author</b>: John Machin, Lingfo Pty Ltd ([email protected])
16+
</p>
17+
<p><b>Licence</b>: BSD-style (see licences.py)
18+
</p>
19+
<p><b>Version of xlrd</b>: 0.7.1 -- 2009-05-31
20+
</p>
21+
<p><b>Versions of Python supported</b>: 2.6-2.7.
22+
</p>
23+
<p><b>External modules required</b>:
24+
</p>
25+
<dl><dd> The package itself is pure Python with no dependencies on modules or packages
26+
outside the standard Python distribution.
27+
</dd>
28+
</dl>
29+
<p><b>Versions of Excel supported</b>:
30+
2004, 2003, XP, 2000, 97, 95, 5.0, 4.0, 3.0, 2.1, 2.0.
31+
Support for Excel 2007 .xlsx files scheduled for version 0.7.1.
32+
</p>
33+
<p><b>Outside the current scope</b>: xlrd will safely and reliably ignore any of these
34+
if present in the file:
35+
</p>
36+
<ul>
37+
<li> Charts, Macros, Pictures, any other embedded object. WARNING: currently
38+
this includes embedded worksheets.
39+
</li>
40+
<li> VBA modules
41+
</li>
42+
<li> Formulas (results of formula calculations are extracted, of course).
43+
</li>
44+
<li> Comments
45+
</li>
46+
<li> Hyperlinks
47+
</li>
48+
<li> Autofilters, advanced filters, pivot tables, conditional formatting, data validation
49+
</li>
50+
</ul>
51+
<p><b>Unlikely to be done</b>:
52+
</p>
53+
<ul><li> Handling password-protected (encrypted) files.
54+
</li>
55+
</ul>
56+
<p><b>Particular emphasis (refer docs for details)</b>:
57+
</p>
58+
<ul><li> Operability across OS, regions, platforms
59+
</li>
60+
<li> Handling Excel's date problems, including the Windows / Macintosh
61+
four-year differential.
62+
</li>
63+
<li> Providing access to named constants and named groups of cells (from version 0.6.0)
64+
</li>
65+
<li> Providing access to "visual" information: font, "number format", background, border,
66+
alignment and protection for cells, height/width etc for rows/columns (from version 0.6.1)
67+
</li>
68+
</ul>
69+
<p><b>Quick start</b>:
70+
</p>
71+
<pre><code> import xlrd
72+
book = xlrd.open_workbook("myfile.xls")
73+
print "The number of worksheets is", book.nsheets
74+
print "Worksheet name(s):", book.sheet_names()
75+
sh = book.sheet_by_index(0)
76+
print sh.name, sh.nrows, sh.ncols
77+
print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
78+
for rx in range(sh.nrows):
79+
print sh.row(rx)
80+
# Refer to docs for more details.
81+
# Feedback on API is welcomed.
82+
</code></pre><p>
83+
</p>
84+
<p><b>Another quick start</b>: This will show the first, second and last rows of each
85+
sheet in each file:
86+
</p>
87+
88+
<pre><code> OS-prompt>python PYDIR/scripts/runxlrd.py 3rows *blah*.xls</code></pre>
89+
90+
<p><b>Installation</b>:
91+
</p>
92+
<ul><li> On Windows: use the installer.
93+
</li>
94+
<li> Any OS: Unzip the .zip file into a suitable directory,
95+
chdir to that directory, then do "python setup.py install".
96+
</li>
97+
<li> If PYDIR is your Python installation directory:
98+
the main files are in PYDIR/Lib/site-packages/xlrd
99+
the docs are in the doc subdirectory,
100+
and there's a sample script: PYDIR/Scripts/runxlrd.py
101+
</li>
102+
<li> If os.sep != "/": make the appropriate adjustments.
103+
</li>
104+
</ul>
105+
<p><b>Download URLs</b>:
106+
</p>
107+
<ul><li> http://pypi.python.org/pypi/xlrd
108+
</li>
109+
<li> http://www.lexicon.net/sjmachin/xlrd.htm
110+
</li>
111+
</ul>
112+
<p><b>Acknowledgements</b>:
113+
</p>
114+
<ul><li> This package started life as a translation from C into Python
115+
of parts of a utility called "xlreader" developed by David Giffin.
116+
"This product includes software developed by David Giffin &lt;[email protected]&gt;."
117+
</li>
118+
<li> OpenOffice.org has truly excellent documentation of the Microsoft Excel file formats
119+
and Compound Document file format, authored by Daniel Rentz. See http://sc.openoffice.org
120+
</li>
121+
<li> U+5F20 U+654F: over a decade of inspiration, support, and interesting decoding opportunities.
122+
</li>
123+
<li> Ksenia Marasanova: sample Macintosh and non-Latin1 files, alpha testing
124+
</li>
125+
<li> Backporting to Python 2.1 was partially funded by Journyx - provider of
126+
timesheet and project accounting solutions (http://journyx.com/).
127+
</li>
128+
<li> Provision of formatting information in version 0.6.1 was funded by Simplistix Ltd
129+
(http://www.simplistix.co.uk/)
130+
</li>
131+
<li> &lt;&lt; a growing list of names; see HISTORY.html &gt;&gt;: feedback, testing, test files, ...
132+
</li></ul>
133+
134+
</body>
135+
</html>

0 commit comments

Comments
 (0)