亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

python對excel表格的操作

發布時間:2020-07-25 09:16:18 來源:網絡 閱讀:1222 作者:cooperfang 欄目:編程語言
# 工作簿, 工作表,單元格
#workbook ,sheet ,cell
# 靈活擦歐總各種對象,進行修改‘
# 編輯樣式
%cd D:\python全站\office
D:\python全站\office
# pip install openpyxl
import openpyxl
wb = openpyxl.load_workbook('coop.xlsx')  
# 加載創建的表格coop.xlsx
wb.get_active_sheet()
c:\users\coop\miniconda3\envs\coop\lib\site-packages\ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated function get_active_sheet (Use the .active property).
  """Entry point for launching an IPython kernel.

<Worksheet "Sheet2">
sh2 = wb.active
cell1 = sh2['A1']
print(cell1)
cell1.value
<Cell 'Sheet2'.A1>

'學生'
sh2['A1'].value
'學生'
sh2['A2'].coordinate
'A2'
sh2['A2'] = 'zhao'  # another sh2['A2'].value = 'zhao'
sh2['A2'].value
'zhao'
###########
sh2.title
'Sheet2'
sh2.title = '成績單'
sh2.title
'成績單'
wb.save('coop-1.xlsx')  # 另存為
##########
# 取sheet1的數據,放入sheet2,成績> 65
# 打開工作簿
%cd D:\python全站\office
import openpyxl
wb = openpyxl.load_workbook('coop.xlsx')
# 打開sheet1,打開sheet2

#操作sheet1,存入sheet2
# 另存為新的文件
D:\python全站\office
# sh2 = wb.get_sheet_by_name('Sheet1')  # 首寫大寫
sh2 = wb['Sheet1']  #對Sheet1頁面操作
sh3 = wb['Sheet2']  #對Sheet2頁面操作
for row in sh2.rows:  # 循環每一行 sh2.row()
    print(row)
    print(row[0].value, row[1].value)   # 打印的是元祖
(<Cell 'Sheet1'.A1>, <Cell 'Sheet1'.B1>)
學生 成績
(<Cell 'Sheet1'.A2>, <Cell 'Sheet1'.B2>)
coop 60
(<Cell 'Sheet1'.A3>, <Cell 'Sheet1'.B3>)
murphy 61
(<Cell 'Sheet1'.A4>, <Cell 'Sheet1'.B4>)
lisi 62
(<Cell 'Sheet1'.A5>, <Cell 'Sheet1'.B5>)
zhangsan 63
(<Cell 'Sheet1'.A6>, <Cell 'Sheet1'.B6>)
lilei 64
(<Cell 'Sheet1'.A7>, <Cell 'Sheet1'.B7>)
××× 65
(<Cell 'Sheet1'.A8>, <Cell 'Sheet1'.B8>)
hao 66
for rows in sh2.rows:
    if rows[0].coordinate != 'A1':   #元祖用法
        #rows[0].coordinate去坐標,不等于A1
        print(rows[0].value, rows[1].value)
coop 60
murphy 61
lisi 62
zhangsan 63
lilei 64
××× 65
hao 66
for rows in sh2.rows:
    if rows[0].coordinate != 'A1' and rows[1].value >63: 
        #rows[0].coordinate去坐標,不等于A1
        print(rows[0].value, rows[1].value)
lilei 64
××× 65
hao 66
index = 2
for rows in sh2.rows:
    if rows[0].coordinate != 'A1' and rows[1].value >63: 
        #rows[0].coordinate去坐標,不等于A1
        print(rows[0].value, rows[1].value)
        sh3['A' + str(index)] = rows[0].value
        sh3['B' + str(index)] = rows[1].value
        print('in sh3:', sh3['A'+str(index)].value,sh3['B'+ str(index)].value)
        index += 1
wb.save('coop-2.xlsx')
lilei 64
in sh3: lilei 64
××× 65
in sh3: ××× 65
hao 66
in sh3: hao 66
# 第二種寫法,根據范圍取值
#A2 B2
# A3, B3
# index = 2
sh2 = wb['Sheet1']
sh3 = wb['Sheet3']
for rows in range(2, sh2.max_row +1):
    grade = sh2.cell(row = rows, column = 2).value
#     print(grade)
#     print(type(grade))
    if grade > 63:
        sh3['A' + str(rows)] = sh2.cell(row = rows, column = 1).value
        sh3['B' + str(rows)] = grade
        print('in sh3:', sh3['A'+str(index)].value,sh3['B'+ str(index)].value)

wb.save('coop-3.xlsx')
in sh3: None None
in sh3: None None
in sh3: None None
print(sh2.max_row)
8
# 最后一行添加平均分數
sh2.cell(row=9, column=2).value = '=average(B2:B8)'
sh2.cell(row=9, column=1).value = '平均分'
print(sh2['B10'].value)
wb.save('coop-4.xlsx')
None
print(sh2['B9'].value)
=average(B2:B8)
from openpyxl.styles import Font
# Font?
font = Font(bold =True, size = 20) # name, size, bold, italic...
sh2['B9'].font = font

wb.save('coop-5.xlsx')
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

榆林市| 海阳市| 尉犁县| 噶尔县| 屯昌县| 盐津县| 巨野县| 澳门| 交口县| 碌曲县| 乐平市| 油尖旺区| 禄丰县| 牡丹江市| 荣昌县| 连山| 抚松县| 邵东县| 合江县| 宁强县| 石渠县| 马山县| 平昌县| 罗江县| 长寿区| 亳州市| 宣化县| 永年县| 楚雄市| 安化县| 涞水县| 当雄县| 富裕县| 福海县| 无棣县| 连南| 遂川县| 丰原市| 蒙城县| 肇庆市| 大港区|