Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

openpyxl create new 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 select a file in python 
Python :: python lock using a file 
Python :: isolate row based on index pandas 
Python :: how to open a file with python 
Python :: python date range 
Python :: python date to timestamp 
Python :: complex arrays python 
Python :: python tkinter colored line 
Python :: venv 
Python :: count dictionary keys 
Python :: xgboosat save_model 
Python :: ComplexWarning: Casting complex values to real discards the imaginary part 
Python :: isntall packages to databricks 
Python :: save image from jupyter notebook 
Python :: cv2 imshow in colab 
Python :: save_img keras 
Python :: add new keys to a dictionary python 
Python :: df dropna 
Python :: python pad with spaces 
Python :: get context data django 
Python :: python private 
Python :: request headers in django 
Python :: django static files 
Python :: flask client ip 
Python :: install python altair 
Python :: convert pdf to csv python 
Python :: how to check current version of library in python 
Python :: selenium if statement python 
Python :: streamlit button 
Python :: matplotlib dateformatter x axis 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =