Skip to content

Instantly share code, notes, and snippets.

@powerexploit
Created September 5, 2019 14:40
Show Gist options
  • Save powerexploit/eb3cfcc395c715b0f3c5e6934fe34171 to your computer and use it in GitHub Desktop.
Save powerexploit/eb3cfcc395c715b0f3c5e6934fe34171 to your computer and use it in GitHub Desktop.
Script to read and show sheet of your excel file
#!/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