Merge pull request #46 from nitish-iiitd/master

Added ExcelToList Converter
This commit is contained in:
Ayush Bhardwaj 2018-10-12 00:42:48 +05:30 committed by GitHub
commit 6b76884868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.