openpyxl.workbook

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
from openpyxl import Workbook

'''
- Creat workbook
'''
wb = Workbook()

'''
- Creeat a sheet
'''
ws = wb.create_sheet("Mysheet", 0)

'''
- Get a sheet
'''
ws = wb.active
ws = wb["Sheet"]
'''
- Rename a sheet
'''
ws.title = "NewTitle"
'''
- Set a sheet background color
'''
ws.sheet_properties.tabColor = "ff0000"

'''
- Get sheets list
'''
wb.sheetnames

'''
- You can create copies of worksheets within a single workbook
'''
source = wb.active
target = wb.copy_worksheet(source)

'''
- Playing with data
Accessing one cell
'''
c = ws['A4']
ws['A4'] = 4
d = ws.cell(row=4, column=2, value=10)


'''
- Save a workbook
'''
wb.save('test.xlsx')

posted @ 2017-07-27 17:33  横扫LBest  阅读(925)  评论(0编辑  收藏  举报