Skip to content

Commit 1ebff83

Browse files
committed
Added ExcelToList Converter
1 parent c5f6bf0 commit 1ebff83

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

Excel_to_ListofList/ExcelToList.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import xlrd
2+
import sys
3+
4+
class ExcelToList():
5+
6+
def __init__(self, file, sheet):
7+
self.file = file
8+
self.sheet = sheet
9+
10+
def convert(self):
11+
converted_list = []
12+
inputexcel = xlrd.open_workbook(self.file)
13+
inputsheet = inputexcel.sheet_by_name(self.sheet)
14+
numberofrows = inputsheet.nrows
15+
numberofcols = inputsheet.ncols
16+
start_row,start_col = 0,0
17+
for current_row in range(start_row,numberofrows):
18+
currentlist = []
19+
for current_col in range(start_col,numberofcols):
20+
currentlist.append(inputsheet.cell(current_row,current_col).value)
21+
converted_list.append(currentlist)
22+
return converted_list

Excel_to_ListofList/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Excel to Python List of List Converter
2+
A simple tool which reads an excel file and any corresponding sheet, and converts it to python list of list data structure.
3+
4+
## Libraries Required
5+
1. xlrd
6+
`$pip install xlrd`
7+
8+
## Usage
9+
A sample script `excel_to_list_usage.py` has been provided to show the usage of the ExcelToList. It reads the excel and its sheet, and prints the list of list.

Excel_to_ListofList/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ExcelToList import ExcelToList
2+
3+
exceltolist = ExcelToList("input.xlsx","Sheet1") ## args : Input filename, Sheet name
4+
list_of_list = exceltolist.convert()
5+
6+
print "List of List : ",list_of_list

Excel_to_ListofList/input.xlsx

4.91 KB
Binary file not shown.

0 commit comments

Comments
 (0)