diff --git a/Excel_to_ListofList/ExcelToList.py b/Excel_to_ListofList/ExcelToList.py new file mode 100644 index 0000000..3f14167 --- /dev/null +++ b/Excel_to_ListofList/ExcelToList.py @@ -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 \ No newline at end of file diff --git a/Excel_to_ListofList/README.md b/Excel_to_ListofList/README.md new file mode 100644 index 0000000..7aa89de --- /dev/null +++ b/Excel_to_ListofList/README.md @@ -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. \ No newline at end of file diff --git a/Excel_to_ListofList/__init__.py b/Excel_to_ListofList/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Excel_to_ListofList/excel_to_list_usage.py b/Excel_to_ListofList/excel_to_list_usage.py new file mode 100644 index 0000000..5957cc1 --- /dev/null +++ b/Excel_to_ListofList/excel_to_list_usage.py @@ -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 \ No newline at end of file diff --git a/Excel_to_ListofList/input.xlsx b/Excel_to_ListofList/input.xlsx new file mode 100644 index 0000000..c403bdd Binary files /dev/null and b/Excel_to_ListofList/input.xlsx differ