CodeMan

Each of us must find a way to love the world. You have found yours.

0%

Python处理Excel文件之Day1遍历Cell

一、环境安装见前篇Python virtualenv使用

二、包安装

考虑到要处理xlsx文件这里使用包openpyxl

1
2
3

pip --proxy 127.0.0.1:1087 install openpyxl

三、遍历所有Cell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# coding=utf-8

from openpyxl import load_workbook


def read_and_iterate_cell(file_path=''):
wb = load_workbook(file_path)
ws = wb['Latest']
column = ws.max_column
for row in ws.rows:
for colIndex in range(0, column, 1):
cell = row[colIndex]
print(str(cell.value) + "\t"),
print()


read_and_iterate_cell('SMS_KS_tracking_report_20191123.xlsx')