可能大家會用到,通過使用后感覺openpyxl比xlrd,xlwt好用多了.
import numpy as np
from pathlib import Path
import openpyxl
fp=Path.cwd()/"xlsDemo"
xlfilename="test.xlsx"
tbname="test"
if not fp.exists():
fp.mkdir(parents=True)
fp=fp/xlfilename
if fp.exists():
wb=openpyxl.open(fp)
if tbname not in wb.sheetnames:
wsh=wb.create_sheet(title=tbname)
else:
wsh=wb[tbname]
else:
wb=openpyxl.Workbook()
wsh=wb.create_sheet(title=tbname)
bb=np.array([2,3,5,6,8,7,9,10])
k=0
for i in range(1,5):
for j in range(1,3):
wsh.cell(i,j).value=https://bbs.csdn.net/topics/bb[k];k+=1
wb.save(fp)
wb.close()
uj5u.com熱心網友回復:
美中不足,不能用陣列對區域一次性賦值,也可能是沒有發現,誰可提供一下方法?轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/18238.html
