前言
Python中常用的操作Excel的三方包有xlrd,xlwt和openpyxl等,xlrd支持读取.xls和.xlsx格式的Excel文件,只支持读取,不支持写入。xlwt只支持写入.xls格式的文件,不支持读取。
openpyxl不支持.xls格式,但是支持.xlsx格式的读取写入,并且支持写入公式等。
原始数据文件apis.xlsx内容:
name
method
url
data
json
result
get接口
get
https://httpbin.org/get"htmlcode">
import openpyxl # 打开excel excel = openpyxl.load_workbook('apis.xlsx') # 有路径应带上路径 # 使用指定工作表 sheet = excel.active # 当前激活的工作表 # sheet = excel.get_sheet_by_name('Sheet1') # 读取所有数据 print(list(sheet.values)) # sheet.values 生成器 print(sheet.max_column) # 最大列数 print(sheet.max_row) # 最大行数
显示结果:
[('name', 'method', 'url', 'headers', 'data', 'json', 'result'), ('get接口', 'get', 'https://httpbin.org/get"htmlcode">
... # 按行读取 for row in sheet.iter_rows(min_row=1, min_col=1, max_col=3, max_row=3): print(row) # 读取标题行 for row in sheet.iter_rows(max_row=1): title_row = [cell.value for cell in row] print(title_row) # 读取标题行以外数据 for row in sheet.iter_rows(min_row=2): row_data = [cell.value for cell in row] print(row_data)打印结果:
(<Cell 'Sheet1'.A1>, <Cell 'Sheet1'.B1>, <Cell 'Sheet1'.C1>)
(<Cell 'Sheet1'.A2>, <Cell 'Sheet1'.B2>, <Cell 'Sheet1'.C2>)
(<Cell 'Sheet1'.A3>, <Cell 'Sheet1'.B3>, <Cell 'Sheet1'.C3>)
['name', 'method', 'url', 'headers', 'data', 'json', 'result']
['get接口', 'get', 'https://httpbin.org/get"htmlcode">... # 读取单元格数据 print(sheet['A1'].value) print(sheet.cell(1,1).value) # 索引从1开始打印结果:
name
name写入文件
代码接上例
# 写入单元格 sheet['F2'] = 'PASS' result_col = title_row.index('result')+1 # 'result'所在的列号 sheet.cell(3, result_col).value = 'PASS' # 整行写入 new_row = ['post-xml接口', 'post', 'https://httpbin.org/post'] sheet.append(new_row) # 保存文件,也可覆盖原文件 excel.save("apis2.xlsx")写入结果:
name method url data json result get接口 get https://httpbin.org/get"external nofollow" target="_blank" href="https://openpyxl.readthedocs.io/en/stable/">https://openpyxl.readthedocs.io/en/stable/总结
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 群星《金吾卫之风起金陵 动漫原声带》[FLAC/分轨][98.08MB]
- JessicaMolaskey-SittinginLimbo--2024[wav]
- 中国音乐地图之听见江苏扬州小调扬剧经典唱段2020[WAV分轨]
- 中国音乐地图之听见国乐阮柳琴音乐集2021[WAV+分轨]
- 常石磊.2010-自己【风向乐动】【WAV+CUE】
- TWINS.2008-桐话妍语(引进版)【英皇娱乐】【WAV+CUE】
- 钮大可陈本瑜-山谷与风的对话【飞碟】【WAV+CUE】
- 群星《百听不厌-HIFI金曲王》2CD[DTS-WAV分轨]
- HIFI天碟《发烧情路》2CD\DTS-ES[WAV]
- 群星《品味感性男声》2CD[DTSWAV]
- 群星《观风月》[320K/MP3][133.98MB]
- 群星《观风月》[FLAC/分轨][321.4MB]
- 群星《奔向所有时空的你 影视原声带》[320K/MP3][47.43MB]
- 陶喆.2013-再见你好吗【伟大文化】【WAV+CUE】
- 李宗盛.1994-不舍(纸盒版)【滚石】【WAV+CUE】