Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

openpyxl load file

# To Install It...
# pip install openpyxl
# python -m pip install openpyxl
import openpyxl

# The Following Will Be The Fast Tutorial Of It...
global wb

def createNewFile(new_name):
  global wb
  ## create a new excel-file-object
  wb = openpyxl.Workbook()
  ## get the first tab of the file
  sheet = wb.worksheets[0]
  ## Write Data To C3 Cell
  sheet['C3'] = 'Hello World'
  ## Create New Sheet
  wb.create_sheet('New Sheet')
  ## Save Edition into File
  wb.save(new_name+'.xlsx')

def loadOld(filename_with_direc):
  global wb
  ## read the excel file with name
  wb = openpyxl.load_workbook(filename_with_direc, read_only=True)

def pickWantedSheet():
  # LOAD
  loadOld(filename_with_direc)
  ## show all tabs
  print(wb.sheetnames)
  name = input('Input The Name You Want---->')
  ## load tabs / get sheet from name
  sheet = wb[name]

def CreateNewSheet():
  # LOAD
  loadOld(filename_with_direc)
  ## create a new tab
  wb.create_sheet(input('Input A Name--->'))
  wb.save(filename_with_direc)

def ReadCell(filename_with_direc):
  # LOAD
  loadOld(filename_with_direc)
  ## First Version :: A1, B1, C1 order
  for row in sheet.rows:
    for cell in row:
    	print(cell.value)
  ## Second Version :: A1, A2, A3 order
  for column in sheet.columns:
    for cell in column:
    	print(cell.value)
  ## Third Version :: Read specific cell with number
  for i in range(sheet.max_row):
    for j in range(sheet.max_column):
      print(sheet.cell(row=i+1, column=j+1).value)
Comment

PREVIOUS NEXT
Code Example
Python :: how to send file in django response 
Python :: Select rows in pandas MultiIndex DataFrame 
Python :: check if two strings are anagrams python 
Python :: pandas drop row from a list of value 
Python :: how to put in code to download discord py 
Python :: how to change python version 
Python :: lowercase all text in a column 
Python :: date.month date time 
Python :: run streamlit from python 
Python :: dictionary size in python 
Python :: remove first 3 columns pandas 
Python :: matplotlib boxplot colors 
Python :: print all unique values in a dictionary 
Python :: Python program to draw star 
Python :: print all attributes of object python 
Python :: create dataframe from two variables 
Python :: comment out a block in python 
Python :: publisher python ros 
Python :: discord.py how get user input 
Python :: remove item from list python 
Python :: randint python 
Python :: send telegram bot message python 
Python :: delete dataframe from memory python 
Python :: python socket recv set timeout 
Python :: check anonim user django 
Python :: pdf to csv python 
Python :: python list 
Python :: change tkinter app icon 
Python :: python save dictionary 
Python :: pyqt disable maximize button 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =