利用python需要将数据写入excel中的指定sheet的单元格中,不知道为什么我这段一直没有写入成功
def create_sheet(sheetNum):
wb = openpyxl.load_workbook(excelName)
#读取已存在的sheet名称
sheet_names = wb.sheetnames
sheetname = '图像列表_'+str(sheetNum)
if sheetname not in sheet_names :
#创建sheet对应的sheet
#打开已经存在的表格
#wb=openpyxl.load_workbook(excelName)
#创建sheet
wb.create_sheet('图像列表_'+str(sheetNum))
sheet = wb.active
#wb.save(excelName)
return sheet
def Image_WritePictureInfo():
rownumber = 4
for i in range(MAX_SHEET):
wb = openpyxl.load_workbook(excelName)
sheet_names = wb.sheetnames
#想要新规的sheet名称
sheetname = '图像列表_'+str(i)
#print((sheetname))
#判断sheet是否已经存在
if sheetname not in sheet_names :
sheet = create_sheet(i);
for j in range(len(Sheetlist[i])):
#写入数据
sheet.cell(row = rownumber, column = 1).value = Sheetlist[i][j].csImageID
sheet.cell(row = rownumber, column = 1).value = Sheetlist[i][j].csFunctionName
sheet.cell(row = rownumber, column = 2).value = Sheetlist[i][j].csOldWidthSize
sheet.cell(row = rownumber, column = 3).value = Sheetlist[i][j].csOldHighSize
sheet.cell(row = rownumber, column = 4).value = Sheetlist[i][j].csImageFolderPath
sheet.cell(row = rownumber, column = 5).value = Sheetlist[i][j].csImageName
rownumber += 1
wb.save(excelName)
对应的excel中没有任何数据
######我尝试过在create_sheet直接ws = wb.create_sheet('图像列表_'+str(sheetNum)),ws作为返回值来作为需要操作的表格