python - 从特定行开始通过 Python 编写公式
问题描述
我正在尝试编写一个代码,该代码将插入一个从特定行开始但没有运气的公式。当前代码为整列创建公式,而我需要它从第 5 行开始,一直到数据集的末尾。如果您有解决方案,请告诉我
wb = openpyxl.load_workbook(file, keep_vba = True)
sheet = wb.get_sheet_by_name('Roster')
for I, cell in enumerate(sheet['V'], 1):
cell.value = '=Left($U{0},1)'.format(I)
wb.save(file)
解决方案
试试这个,首先加载 excel 作为数据框,然后只选择你需要的记录
from openpyxl.utils.dataframe import dataframe_to_rows
book = pd.read_excel("file.xlsx",sheet_name="Roster")
df = book.iloc[5:,:]
接下来将数据框转换为 openpyxl 对象,您可以完成剩下的工作
sheet = dataframe_to_rows(df)
//do your operations
推荐阅读
- c# - Linq 过滤/搜索逻辑
- promise - How to get rid of 'return new Promise' and not to lose data?
- kerberos - oozie-hive 直线不适用于 kerberos
- excel - 基于标准的 Excel 索引
- string - 命令行如何将字符串搜索到 %% 变量中
- python - 可以从 IDE 运行 selenium 脚本,但不能从 cmd
- database - 如何修复“数据库错误:前端与 Zabbix 数据库不匹配”。
- php - 如何通过特定数字和数据输入来制作唯一标识符
- javascript - 从多个表格的列表中选择下一个数字
- android - 如何控制谁可以从 Play 商店安装我的应用程序?