1、当前文件不存在指定的子文件夹则创建 2、文件存在追加写入 3、文件不存在创建文件并写入表头
# -*- coding: utf-8 -*-import openpyxl as xlimport osdef write_excel_file(folder_path):if not os.path.exists(folder_path):os.makedirs(folder_path)result_path = os.path.join(folder_path, "my.xlsx")print('***** 开始写入excel文件 ' + result_path + ' ***** \n')# 文件存在则加载,不存在创建if os.path.exists(result_path):print('***** excel已存在,在表后添加数据 ' + result_path + ' ***** \n')workbook = xl.load_workbook(result_path)else:print('***** excel不存在,创建excel ' + result_path + ' ***** \n')workbook = xl.Workbook()workbook.create_sheet('订单信息')workbook.create_sheet('订单详情')workbook.remove(workbook['Sheet']) #删除空白页workbook.save(result_path)sheet = workbook['订单详情']headers = ["URL", "predict", "score"]sheet.append(headers)sheet = workbook['订单详情']result = [['1', 1, 1], ['2', 2, 2], ['3', 3, 3]]for data in result:sheet.append(data)workbook.save(result_path)print('***** 生成Excel文件 ' + result_path + ' ***** \n')if __name__ == '__main__':write_excel_file("2023-08-28\\")【Python进阶学习】【Excel读写】使用openpyxl写入xlsx文件,东方微点序列号
0evadmin
编程语言
12
文件名:【Python进阶学习】【Excel读写】使用openpyxl写入xlsx文件,东方微点序列号
【Python进阶学习】【Excel读写】使用openpyxl写入xlsx文件
同类推荐
-
![【Python】[02]初识Python,rv770(python rvs)](https://www.0ev.cc/zb_users/cache/thumbs/23e6181118b51d9a0b36fcaeaa9a7ece-80-80-1.jpg)
【Python】[02]初识Python,rv770(python rvs)
查看 -

【Python】urllib爬取动漫图片,推荐几个安全没封的网站2021(python爬取动态网页图片)
查看 -

【Python】【PyPi】搭建本地PyPi镜像源,索爱w610c(python镜像源下载)
查看 -

【Python】一文带你掌握数据容器之集合,字典,康佳梵高手机
查看 -

【Python】多线程,sony xperia zu
查看 -

【Python】流畅!一个非常好用的网络数据采集工具!,iphone4完美越狱(python网络数据采集这本书怎么样)
查看 -

【Python】生死簿管理系统,估值5毛,简爱7g(生死簿源码)
查看 -

【Python】进阶之 MySQL入门教程,acer5542g
查看 -

【Python位运算】——左移操作(<<)右移操作>>,vx555hd(python左移位运算符)
查看