Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

openpyxl

# 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

openpyxl

from openpyxl import Workbook
wb = Workbook()

# grab the active worksheet
ws = wb.active

# Data can be assigned directly to cells
ws['A1'] = 42

# Rows can also be appended
ws.append([1, 2, 3])

# Python types will automatically be converted
import datetime
ws['A2'] = datetime.datetime.now()

# Save the file
wb.save("sample.xlsx")
Comment

openpyxl

from openpyxl import *
Comment

PREVIOUS NEXT
Code Example
Python :: how to count the number of guesses in python 
Python :: python format new 
Python :: newsapi 
Python :: python if string has spaces 
Python :: get resolution of image python 
Python :: python keyerror 
Python :: Maximize Difference codechef solution 
Python :: sqlite3 python parameterized query insert into 
Python :: python run things at certain datetimes 
Python :: defining function in python 
Python :: run multiprocesses on flask 
Python :: python collections to dictionary 
Python :: how to exit a loop in python 
Python :: display pil image on kivy canvas 
Python :: python latest version 64 bit 
Python :: null in python 
Python :: insert function in list 
Python :: python dataframe reihe anzeigen 
Python :: how to create dictionary in python 
Python :: pandas remove multi header from dataframe 
Python :: how to use for in python 
Python :: pandas python example 
Python :: copy array along axis numpy 
Python :: filter in python 
Python :: sqlite query using string as parameter in python 
Python :: windows instalar python 
Python :: seaborn orient 
Python :: base64 python flask html 
Python :: desktop notifier in python 
Python :: how to convert string into list in python 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =