mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Added ExcelToList Converter
This commit is contained in:
parent
c5f6bf0609
commit
1ebff83516
22
Excel_to_ListofList/ExcelToList.py
Normal file
22
Excel_to_ListofList/ExcelToList.py
Normal 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
|
9
Excel_to_ListofList/README.md
Normal file
9
Excel_to_ListofList/README.md
Normal 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.
|
0
Excel_to_ListofList/__init__.py
Normal file
0
Excel_to_ListofList/__init__.py
Normal file
6
Excel_to_ListofList/excel_to_list_usage.py
Normal file
6
Excel_to_ListofList/excel_to_list_usage.py
Normal 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
|
BIN
Excel_to_ListofList/input.xlsx
Normal file
BIN
Excel_to_ListofList/input.xlsx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user