Python openpyxl Read

#! /usr/bin/env python
# coding=utf-8


from openpyxl import Workbook, load_workbook


wb = load_workbook(filename=u'周工做計劃_聯通電信支撐組.xlsx')
ws = wb.active

# wb = load_workbook(filename=u'test1.xlsx')



# for sname in wb.get_sheet_names():
# # for sname in wb.sheetnames:
# #     ws = wb.get_sheet_by_name(sname)
# #     print ws.title
#     ws = wb[sname]
#     print ws.title
     
#      
# for sheet in wb:
#     print sheet.title


# print wb.sheetnames
# for sheet in wb:
#     print(sheet.title)





# print ws.title

# # 行列數
# print ws.max_row
# print ws. max_column

# print ws.min_row
# print ws.min_column

# for row in ws.rows:
#     
#     for cell in row:
#         print cell.value,
#     print

# # cell = ws['E4']
# # cell = ws.cell('E4')
# cell = ws.cell(row=4, column=5)
# print cell
# print cell.value
# 
# cell_range = ws['D3:E16']
# 
# print cell_range
# for row in cell_range:
#     for cell in row:
#         print cell.value,
#     print


# for row in ws.iter_rows('D3:E16'):
#     for cell in row:
#         print cell.value,
#     print



'''
表頭佔兩行:

項目 類型 優先級 運營點 需求標題(對應需求文檔) 完成時間 評審計劃 UR 狀態 負責�� None None None None None 完成時間 None None None None None None None None 周工做量投入(人.h) None 成本估算(人.h) None
None None None None None None None None None 需求 外部資源 設計 提示音 開發 測試 需求 外部資源 設計 提示音 開發 內測 部署 外測 驗收 開發 測試 開發 測試

'''
#  min_col, min_row, max_col, max_row



for ws in wb:
    
    min_col = 4  # 前面三列分別是項目 、類型、 優先級,從第四列  運營點 開始選擇
    min_row = 3  # 前面兩行是表頭,從第三列開始選擇
    max_col = 15  # 勾選到 到 負責人-測試 這列 
    max_row = ws.max_row - 1  # 排查最後一行(平常事務處理)
    
    print '*' * 20, ws.title, '*' * 20
    for row in ws.get_squared_range(min_col, min_row, max_col, max_row): 
        for cell in row:
            print cell.value,
        print


# print tuple(ws.iter_rows('D3:E16'))

# print ws.rows
# print ws.columns
View Code
相關文章
相關標籤/搜索