import xlsxwriter
#创建工作簿
file_name = "新建路径"
workbook = xlsxwriter.Workbook(file_name)
#创建工作表
worksheet = workbook.add_worksheet('first_sheet')
#写单元格
worksheet.write(0,0,'Hello')
worksheet.write('A2','wold')
#写行
worksheet.write_row(2,0,[1,2,3,4,5,6])
#写列,其中列F需要大写
worksheet.write_column('F2',['a','b','c','d'])
#关闭工作簿
workbook.close()
import openpyxl
wb=openpyxl.load_workbook(file)
sheet1=wb.active
# sheet1=sheet['Sheet1'] #根据索引获取第一个sheet
number=sheet1.max_row
for j in range(1,number):
y=sheet1.cell(j,1).value
import openpyxl
wb=openpyxl.load_workbook(‘文件路径名’)
ws = wb['Data_L']#利用Sheet明获取相应的Sheet
ws.cell(i,j).value =values#将value写入相应的i行j列
wb.save(‘文件路径名’)#保存
!!!!!注意,openpyxl只能对excel读或者写,不能同时读和写!但可以读和修改
修改语句是
sheet1.cell(j,i,y),j和i是要修改的行和列,y是修改的值