-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxslx_utils.py
More file actions
22 lines (19 loc) · 732 Bytes
/
Copy pathxslx_utils.py
File metadata and controls
22 lines (19 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Created By: Theodore Tenedorio
# Date: 10/29/2015
# Requires: Python2.7 & openpyxl
# 'https://pypi.python.org/pypi/openpyxl' or 'pip install openpyxl'
from openpyxl import load_workbook
# Reads the active worksheet of .xlsx (MS Excel 2010) into an array of columns.
# header variable skips the first row if true.
# WARNING: DATA MUST BE IN A SQUARE MATRIX (NO UNEVEN COLUMNS OR ROWS)
def read_xlsx(filename, header=True):
wb = load_workbook(filename)
rows = len(wb.active.rows)
cols = len(wb.active.columns)
data = []
for x in range(cols):
col = []
for y in range(1 if header else 0, rows):
col.append(wb.active.rows[y][x].value)
data.append(col)
return data