Added ExcelToList Converter

This commit is contained in:
nitish-iiitd 2018-10-11 23:54:46 +05:30
parent c5f6bf0609
commit 1ebff83516
5 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import xlrd
import sys
class ExcelToList():
def __init__(self, file, sheet):
self.file = file
self.sheet = sheet
def convert(self):
converted_list = []
inputexcel = xlrd.open_workbook(self.file)
inputsheet = inputexcel.sheet_by_name(self.sheet)
numberofrows = inputsheet.nrows
numberofcols = inputsheet.ncols
start_row,start_col = 0,0
for current_row in range(start_row,numberofrows):
currentlist = []
for current_col in range(start_col,numberofcols):
currentlist.append(inputsheet.cell(current_row,current_col).value)
converted_list.append(currentlist)
return converted_list

View File

@ -0,0 +1,9 @@
# Excel to Python List of List Converter
A simple tool which reads an excel file and any corresponding sheet, and converts it to python list of list data structure.
## Libraries Required
1. xlrd
`$pip install xlrd`
## Usage
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.

View File

View File

@ -0,0 +1,6 @@
from ExcelToList import ExcelToList
exceltolist = ExcelToList("input.xlsx","Sheet1") ## args : Input filename, Sheet name
list_of_list = exceltolist.convert()
print "List of List : ",list_of_list

Binary file not shown.