Created
September 5, 2019 14:40
-
-
Save powerexploit/eb3cfcc395c715b0f3c5e6934fe34171 to your computer and use it in GitHub Desktop.
Script to read and show sheet of your excel file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
#excel_checker.py ->Script will read your excel file | |
import sys | |
import openpyxl | |
from os import getcwd | |
if len(sys.argv) > 2 : | |
a = getcwd() #getcwd() to find out current directory | |
print("Your current directory is : ",a) | |
sys.exit("So Plese provide one argument -> Name of your excel file in current directory!") | |
def workbook(): | |
wb = openpyxl.load_workbook(sys.argv[1]) | |
#openpyxl.load_workbook() function takes in the filename | |
#and returns a value of the workbook data type | |
print(type(wb)) #return Workbook object which represent your excel file | |
list1 = wb.get_sheet_names() | |
print(list1) | |
sheet = wb.get_sheet_by_name('Sheet1') | |
print(sheet) # | |
print(type(sheet)) | |
print(sheet.title) | |
anothersheet = wb.get_active_sheet() | |
print(anothersheet) | |
workbook() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment