操屁眼的视频在线免费看,日本在线综合一区二区,久久在线观看免费视频,欧美日韩精品久久综

新聞資訊

    目錄

    背景

    導(dǎo)出數(shù)據(jù)到excel,數(shù)據(jù)中有圖片,需求是批量下載圖片的指定文件夾

    數(shù)據(jù)格式

    數(shù)據(jù)類型有直接是文本,也有顯示圖片,存在多張圖片的情況excel超鏈接到同文件夾文件,需要做的是批量獲取Json格式數(shù)據(jù)中的pic,并進(jìn)行下載

    處理步驟 1.使用xlrd讀取excel表格數(shù)據(jù)

    python">pip install xlrd

    注:高版本的xlrd目前去除了xlsx格式的支持,支持xls格式

    目前使用有兩種方式

    1.刪除高版本excel超鏈接到同文件夾文件,重裝xlrd

    xlrd.biffh.XLRDError: Excel xlsx file; not supported
    

    excel文件怎么變成dat文件_excel超鏈接到同文件夾文件_pdf文件轉(zhuǎn)換為excel文件

    pip install xlrd==1.2.0

    2.打開xlsx文件,另存為xls格式

    2.詳細(xì)代碼 ①引入相關(guān)庫(kù)

    import xlrd
    import requests
    import json

    ②實(shí)例代碼

    # 讀取excel
    read_path = r"xx\xx.xls"  # excel文件路徑
    bk = xlrd.open_workbook(read_path)
    # 獲取所有sheet,取第1個(gè)sheet頁,如果有多個(gè)sheet也可以使用sheet_by_name()方法
    

    excel超鏈接到同文件夾文件_pdf文件轉(zhuǎn)換為excel文件_excel文件怎么變成dat文件

    try: sh = bk.sheets()[0] except: print("no sheet in %s" % read_path) # 獲取表中的總行數(shù) nrows = sh.nrows print("nrows:", nrows) # 由于數(shù)據(jù)存在文本和json格式數(shù)據(jù),需要先進(jìn)行判斷 # 判斷是否是json格式數(shù)據(jù) def is_json(msg):

    excel文件怎么變成dat文件_pdf文件轉(zhuǎn)換為excel文件_excel超鏈接到同文件夾文件

    if isinstance(msg, str): # 判斷是否是字符串 try: json.loads(msg) except ValueError: return False return True else: return False # 表中第一行有標(biāo)題,需要從第2行開始 for i in range(1, nrows): # print("下載第 %d 個(gè)圖片" % i)

    excel文件怎么變成dat文件_excel超鏈接到同文件夾文件_pdf文件轉(zhuǎn)換為excel文件

    picList = [] # 定義存放圖片的list # 讀取C列數(shù)據(jù) C_name = sh.cell_value(i, 2) print('C_name: ', C_name) # 讀取D列數(shù)據(jù) excel表中存在一行有多個(gè)圖片情況,使用“;”對(duì)數(shù)據(jù)進(jìn)行分隔,分別拿到每一個(gè)json格式數(shù)據(jù) D_name = sh.cell_value(i, 3).split(";") print('D_name: ', D_name) # 循環(huán)獲取所有的json for d_value in D_name: print('d_value:', d_value)

    excel超鏈接到同文件夾文件_pdf文件轉(zhuǎn)換為excel文件_excel文件怎么變成dat文件

    if is_json(d_value):# 先對(duì)json進(jìn)行判斷 picList = json.loads(d_value)['pic'] # 如果是json數(shù)據(jù)就直接取pic里的值 if len(picList): # 為空不打印 print("picList:", picList) # 循環(huán)取出圖片地址 使用enumerate獲取每個(gè)圖片下標(biāo) for j, picUrl in enumerate(picList): # 根據(jù)URL下載到本地 f = requests.get(picUrl) # 需要先創(chuàng)建文件夾 pic_name = r"D:\xxx\Downloads\文件夾\\" + C_name + "_" + str(j + 1) + ".png" # 構(gòu)造完整文件路徑+名稱 with open(pic_name, "wb") as code: code.write(f.content)

網(wǎng)站首頁   |    關(guān)于我們   |    公司新聞   |    產(chǎn)品方案   |    用戶案例   |    售后服務(wù)   |    合作伙伴   |    人才招聘   |   

友情鏈接: 餐飲加盟

地址:北京市海淀區(qū)    電話:010-     郵箱:@126.com

備案號(hào):冀ICP備2024067069號(hào)-3 北京科技有限公司版權(quán)所有