当前位置:网站首页>Three components of openpyxl
Three components of openpyxl
2022-07-05 21:29:00 【Nuoyiyou ~】
1. workbook
2. Worksheet
3. Cell
Read excel File data :
def read_excel(path):
#1. Get the workbooks
wk = openpyxl.load_workbook(path)
# 2. Get worksheet
sheets = wk.sheetnames
for sheet in sheets:
my_sheet = wk[sheet]
result = list()
# 3. Get the cell
for row in range(2,my_sheet.max_row+1):
result_row = list()
for column in range(1,my_sheet.max_column+1):
result_row.append(my_sheet.cell(row,column).value)
result.append(result_row)
print(result)Write table data :
def create_excel():
#1. Create Workbook
wk = openpyxl.Workbook()
#2. Get current worksheet
my_sheet = wk.active
#3. Write data
my_sheet.cell(1,1).value = "name"
my_sheet.cell(1,2).value = "age"
#4. Save table
wk.save("user.xlsx")Write multiple pieces of data :
def add_manyuData(path):
#1. Open workbook in total
wk = openpyxl.load_workbook(path)
#2. Create sheet
my_sheet = wk.create_sheet()
#3. Write data once
data = [1,2,3,4,5,6]
my_sheet.append(data)
#4. Save workbook
wk.save(path)
边栏推荐
- int GetMonth( ) const throw( );后面的throw( )什么意思?
- The primary key is set after the table is created, but auto increment is not set
- Display DIN 4102-1 Class B1 fire test requirements
- SYSTEMd resolved enable debug log
- 力扣------经营摩天轮的最大利润
- 思特奇加入openGauss开源社区,共同推动数据库产业生态发展
- 字典树简单入门题(居然是蓝题?)
- Get JS of the previous day (timestamp conversion)
- MySQL 千万数据量深分页优化, 拒绝线上故障!
- Deployment of Jenkins under win7
猜你喜欢

KingbaseES V8R3集群维护案例之---在线添加备库管理节点

How to prepare for the algorithm interview and answer the algorithm interview questions

leetcode:1139. The largest square bounded by 1

PVC 塑料片BS 476-6 火焰传播性能测定

面试官:并发编程实战会吗?(线程控制操作详解)

2022-07-03-cka- latest feedback from fans

Clickhouse copy paste multi line SQL statement error

力扣------经营摩天轮的最大利润

Incentive mechanism of Ethereum eth

PVC plastic sheets BS 476-6 determination of flame propagation properties
随机推荐
vant 源码解析 event.ts 事件处理 全局函数 addEventListener详解
Li Kou ----- the maximum profit of operating Ferris wheel
SQL series (basic) - Chapter 2 limiting and sorting data
Aitm 2-0003 horizontal combustion test
EasyExcel的读写操作
Introduction to TS, constructor and its this, inheritance, abstract class and interface
Modifiers of attributes of TS public, private, protect
What are the requirements of UL 2043 test for drive housing in the United States?
基于vertx-web-sstore-redis的改造实现vertx http应用的分布式session
js常用方法封装
Chapter 05_ Storage engine
Zhang Lijun: penetrating uncertainty depends on four "invariants"
办公遇到的问题--
Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)
Recursive query of multi-level menu data
Xlrd common operations
Add ICO icon to clion MinGW compiled EXE file
Determine the best implementation of horizontal and vertical screens
CLion配置visual studio(msvc)和JOM多核编译
[case] Application of element display and hiding -- element mask