[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>方法一
<>安装包
打开cmd
pip install xlrd #或者去pycharm中下也可以
<>打开文件
# 打开实验数据表格 book = xlrd.open_workbook('../景区信息.xlsx')
<>选择sheet(页数)
# 选择页数为第1页 sheet1 = book.sheets()[0]
<>获取总行数与总列数
# 数据总行数 nrows = sheet1.nrows # 数据总列数 ncols = sheet1.ncols
<>获取某一行某一列数据
# 获取表中第三行的数据 x = sheet1.row_values(2) # 获取表中第二列的数据 y = sheet1.col_values(1)
#获取第五列中的第二个数据 z = sheet1.col_values(4)[1]
<>获取某一列某一行中的切片数据
# 获取表中第二列且不要第一个值的数据 y_noone = sheet1.col_values(1)[1:] # [1:]相当于切片操作
<>获取某一列某一行的值
x_3_y_3 = sheet1.cell(2, 2).value # 当然也可以修改
<>方法二
<>安装包
pip install openpyxl
<>创建新的工作薄
wb = Workbook()
<>创建工作表
ws = wb.create_sheet('111')
<>添加
ws.append(['发布时间','文本内容','转发数量','评论数量','赞数量','收藏数量'])
<>当前工作表
ws2 = wb.active ws2.title
<>加载文件
book = openpyxl.load_workbook('../景区信息.xlsx')
<>选择页数
sheet1 = book['Sheet1']
<>获取行列长度
len_row = sheet1.max_row len_column = sheet1.max_column
<>获取某一格的内容
location = sheet1.cell(5, 5).value
<>修改内容
sheet1.cell(num, 6).value = 5 sheet1.cell(num, 7).value = 6
<>保存以及关闭文件
book.save(filename="../景区信息.xlsx") book.close()