Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

openpyxl fast tutorial

# 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 file in python 
Python :: detect operating system using python 
Python :: drop rows from dataframe based on column value 
Python :: extract zip file in python zipfile 
Python :: how to find last index of list in python 
Python :: with in python 
Python :: pandas reemplazar nan por cero 
Python :: como transformar texto a audio y reproducirlo en pyrthon 
Python :: python fillna with mean in a dataframe 
Python :: snakeCase 
Python :: flask heroku 
Python :: How to load .mat file and convert it to .csv file? 
Python :: System.Windows.Forms.DataGridView.CurrentRow.get returned null. c# 
Python :: print statement in python 
Python :: how to remove items from list in python 
Python :: plotly vertical bar chart 
Python :: Python list of dictionaries search 
Python :: Using python permutations function on a list 
Python :: django save image 
Python :: python sort class by attribute 
Python :: python how to draw a square 
Python :: version python 
Python :: tkinter allign 
Python :: How to Count occurrences of an item in a list in python 
Python :: python cmd exec 
Python :: python call function from string 
Python :: how does urllib.parse.urlsplit work in python 
Python :: python format subprocess output 
Python :: convert ndarray to csr_matrix 
Python :: python open all files of type csv 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =