openpyxl 打开大文件很慢_使用openpyxl python处理非常大的文件

Question: Is there a way to speed this up or use better methodology?

请尝试以下操作以查看此操作是否可以提高性能:Note: Didn't know the Values of col and max_column!

My Example uses 4 Columns and skips Column C.

Data:

['A1', 'B1', 'C1', 'D1'],

['A2', 'B2', 'C2', 'D2']from openpyxl.utils import range_boundaries

min_col, min_row, max_col, max_row = range_boundaries('A1:D2')

for row_cells in ws.iter_rows(min_col=min_col, min_row=min_row,

max_col=max_col, max_row=max_row):

# Slice Column Values up to B

data = [cell.value for cell in row_cells[:2]]

# Extend List with sliced Column Values from D up to End

data.extend([cell.value for cell in row_cells[3:]])

# Append db.get(Column A.value)

data.append(db.get(row_cells[0].value, "notfound"))

# Join all List Values delimited with \t

print('{}'.format('\t'.join(data)))

# Write to CSV

#w.write(data)Output:

A1 B1 D1 notfound

A2 B2 D2 notfound

使用Python:3.4.2-openpyxl:2.4.1进行测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值