Python怎麼獲取excle中指定行和列的值?

2022-09-02 00:15:16 字數 1070 閱讀 9893

'''

*** 學而思之、思而記之、記而習之 ***

'''f="dict_file.txt" #定義檔名

def writefile(key,value):

with open(f, "w") as file: # 只需要將之前的」w"改為「a"即可,代表追加內容,「w」是覆蓋

file.write(str(key) + "=" + str(value) +"\n")

return f

writefile("user","lalala")

#寫入結果 user=lalala

# python怎麼獲取excle中指定行和列的值?

# 引用包

import xlrd

# import sys

# print(sys.path) 檢視當前檔案說在目錄

# 開啟檔案

workbook=xlrd.open_workbook(r'f:/學習/excle/excle20200917/case20200917.xlsx')

# 獲取sheet名稱

sheet_name = workbook.sheet_names()[0] #sheet索引從0開始

# print(sheet_name)

# 根據sheet索引或者名稱獲取sheet內容

sheet = workbook.sheet_by_index(0) # sheet索引從0開始

# print(sheet)

# 4、獲取指定單元格裡面的值

i=sheet.cell_value(0,0)#sheet.cell_value(第幾行,第幾列)

# 獲取整行和整列的值(陣列)

rows = sheet.row_values(1) # 獲取第2行內容

cols = sheet.col_values(2) # 獲取第3列內容

# print(rows)

# print(cols)

# 獲取sheet的名稱,總行數,總列數

print (sheet.name,sheet.nrows,sheet.ncols)

python讀取excle檔案入庫

coding utf 8 將excle表中的資料匯入mysql資料庫中 import mysqldb import os import xlrd li 2013年 公示表 定義列表存放表檔名 for ex in li lj r c 內網通接受的檔案 28 3 2 1 xls format ex 路徑...

Python實現excle檔案讀寫

實現學生成績資料的彙總 語文成績.xlsx 英語成績.xlsx 生成 成績彙總.xlsx 實現 excle檔案讀取 file excleread.py author yize365 date 2019 12 16 function excle讀取 remarks from xlrd import o...

python怎麼獲取windows服務的PID

下面上 為了便於理解,特意在 後新增了注釋。希望有所幫助。import psutil import re import sys import os import time import logging import subprocess logging.basicconfig level loggi...