实例:
# 创建excel文件
wb = xlsxwriter.Workbook("cars.xlsx")
# 在该文件下创建sheet
ws = self.wb.get_worksheet_by_name("Car") or self.wb.add_worksheet("Car")
ws.write(row,col,*arg)
wb.close()
可读可写可修改
使用:
try:
wb = load_workbook(filename)
except Exception as e:
wb = Workbook(filename)
# 获取worksheet
try:
ws = wb.get_sheet_by_name(car_brand_name)
except Exception as e:
ws = wb.create_sheet(car_brand_name)
# 写入数据
ws.append((item.get("car_name"),item.get("car_unit"),item.get("car_price"),item.get("car_price_buy")))
wb.save(filename)