最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

python3讀寫excel之openxlpy

2022-12-02 17:59 作者:限量版范兒  | 我要投稿

pip install openpyxl

?openpyxl 讀寫 xlsx 文件,不處理 xls 文件

import openpyxlimport localeimport datetimeimport timeimport os# 讀xlsx文件excel = openpyxl.load_workbook('./source-files/info.xlsx') sheet = excel.active sheet = excel.get_sheet_by_name('test')print(list(sheet.values)) ?# sheet.values 生成器print(sheet.max_column) ?# 最大列數(shù)print(sheet.max_row) ?# 最大行數(shù)print(sheet['A1'].value)print(sheet.cell(1, 1).value)for row in sheet.iter_rows(max_row=1): title_row = [cell.value for cell in row]print(title_row)for row in sheet.iter_rows(min_row=2, max_row=5): row_data = [cell.value for cell in row]print(row_data)# 寫xlsx文件locale.setlocale(locale.LC_CTYPE, 'chinese') excel = openpyxl.Workbook() sheet = excel.active sheet.title = "info"sheet.append(['name', 'age', 'class', 'datetime'])for i in range(5)[1:]:for j in range(4)[1:]: sheet.cell(row=i+1, column=j).value = i+j sheet.cell(row=i+1, column=4).value = datetime.datetime.now() sheet.cell( row=i+1, column=5).value = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) sheet = excel.create_sheet('sheet', 0) ?# 新建一個(gè)sheetsheet.title = 'test'sheet.sheet_properties.tabColor = '0d6efd'sheet.merge_cells('A2:D4')# sheet.unmerge_cells('A2:D4')sheet.merge_cells(start_row=2, start_column=1, end_row=2, end_column=4)# sheet.unmerge_cells(start_row=2, start_column=1, end_row=2, end_column=4)img = openpyxl.drawing.image.Image('./source-files/img1.png') sheet.add_image(img, 'D4') sheet.row_dimensions[1].height = 22sheet.column_dimensions['A'].width = 25sheet.cell(row=1, column=1).alignment = openpyxl.styles.Alignment(horizontal='center', vertical='center') copy = excel.copy_worksheet(excel['info']) copy.title = 'backup'for cell in copy['A']:print(cell.value)for cols in copy['A:C']:for cell in cols:print(cell.value)for row in copy['1:3']:for cell in row:print(cell.value)for row in copy.iter_rows():for cell in row:print(cell.value)for row in copy.iter_cols():for cell in row:print(cell.value)for row in copy.iter_rows(min_row=1, min_col=1, max_col=3, max_row=3):for cell in row:print(cell.value)for row in copy.rows:for cell in row:print(cell.value)for col in copy.columns:for cell in col:print(cell.value)print(copy.max_row, copy.max_column, copy.min_row, copy.min_column)print(excel.sheetnames)for sheet in excel:print(sheet.title)if os.path.exists('./gen-files/test.xlsx'): os.remove('./gen-files/test.xlsx') excel.save('./gen-files/test.xlsx')

鏈接:https://www.dianjilingqu.com/626855.html

python3讀寫excel之openxlpy的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
威海市| 内黄县| 舟曲县| 仪陇县| 建水县| 涪陵区| 丰城市| 郑州市| 天长市| 家居| 沈丘县| 吉首市| 镇远县| 皮山县| 嘉义市| 临洮县| 织金县| 眉山市| 淮南市| 元氏县| 高碑店市| 崇礼县| 皮山县| 唐河县| 略阳县| 罗江县| 通城县| 淳安县| 巴南区| 郧西县| 拉孜县| 武城县| 颍上县| 沁阳市| 介休市| 马龙县| 吴江市| 阿城市| 根河市| 巫山县| 务川|