Python 读取csv,excel

# csv 只适合单个sheet 表
import csv
with open("./bb.csv","rt",encoding="utf-8-sig") as f:
    reader = csv.reader(f)
    for i  in reader:
        print(i)
import json
import xlrd
wb = xlrd.open_workbook("./student.xlsx")
sheet_names = wb.sheet_names()
print(sheet_names)
ws = wb.sheet_by_name("Sheet1")
print(ws.name,ws.nrows,ws.ncols)
row_3 = ws.row_values(0)
print(row_3)
cols_3 = ws.col_values(2)
print(ws.row(3))
 
print(type(json.loads(ws.cell_value(3,2))))
from xlutils.copy import copy
rd_book = xlrd.open_workbook("./student.xlsx")
wt_book = copy(rd_book)
ws = wt_book.get_sheet(0)
ws.write(4,0,"haha")
print(ws)
wt_book.save("./student1.xlsx")
posted @ 2022-03-22 00:19  我是小菜鸡丫丫  阅读(100)  评论(0编辑  收藏  举报