python读取excel

简介: python读取excel
生命苦短,请用python.

领导让把系统pdm中的表都加上字段注释,由于采用jeecms开发,没有有注解,一个个手填,那么多表不累死人?

幸运的是在网上找到字段说明的文档,看上去很有规律,动手整理成excel.

下面是我整理的有规律的excel。

image.png


因此采用Python读取excel,生成创建注解的sql,再用powerdesigner逆向工程自动把注释设置到pdm上。哈哈,省事很多。

贴出代码:



import csv
from openpyxl import load_workbook
wb = load_workbook(filename='h:/jeecms数据库字段说明.xlsx', read_only=True)
sheetnames =wb.get_sheet_names() #获得表单名字
for sheet in sheetnames:
    ws = wb.get_sheet_by_name(sheet)
    count = 0
    for row in ws.rows:
        count= count+1
        if count==1:
            continue
        if row[9].value!=None:
          #  print(row[0].value+" "+str(row[9].value))
            print('comment on column '+sheet.strip()+'.'+row[0].value.strip()+' is \''+str(row[9].value)+'\';')


控制台打印出sql:

comment on column jc_acquisition.acquisition_id is '采集ID';
comment on column jc_acquisition.site_id is '位置ID';
comment on column jc_acquisition.channel_id is '栏目ID';
comment on column jc_acquisition.type_id is '内容类型ID';
comment on column jc_acquisition.user_id is '用户ID';
comment on column jc_acquisition.acq_name is '采集名称';
comment on column jc_acquisition.start_time is '开始时间';
comment on column jc_acquisition.end_time is '结束时间';

搞定,收工!


相关文章
|
3天前
|
SQL 人工智能 自然语言处理
Python 潮流周刊#52:Python 处理 Excel 的资源
探索Python精彩:文章涵盖正则、代码恢复、PEP新规范、轻量级打包、在线开发、动态生成GitHub README、自定义linting、代码转图片等。项目资源包括Excel处理、虚拟环境管理、Tensor谜题、依赖注入框架、Web应用转换、AI自动化测试、语法高亮、BI模型查询及Python监控库。在当前环境下,持续学习提升竞争力,Python Weekly提供丰富的学习资源,助力技术精进和职业发展。
|
11天前
|
Python
办公自动化-Python如何提取Word标题并保存到Excel中?
办公自动化-Python如何提取Word标题并保存到Excel中?
26 2
|
19天前
|
Python
python_读写excel、csv记录
python_读写excel、csv记录
19 0
|
6天前
|
数据采集 数据挖掘 数据处理
Python数据分析实战:使用Pandas处理Excel文件
Python数据分析实战:使用Pandas处理Excel文件
76 0
|
17天前
|
数据采集 数据挖掘 关系型数据库
Excel计算函数(计算机二级)(1),2024年最新2024Python架构面试指南
Excel计算函数(计算机二级)(1),2024年最新2024Python架构面试指南
|
19天前
|
机器学习/深度学习 人工智能 自然语言处理
Python转换Excel到Markdown
Python转换Excel到Markdown
14 0
|
19天前
|
Python
python如何读取excel文件,并修改内容?
python如何读取excel文件,并修改内容?
33 0
|
19天前
|
存储 数据采集 数据可视化
Python列表到Excel表格第一列的转换技术详解
Python列表到Excel表格第一列的转换技术详解
16 0
|
19天前
|
存储 Python Windows
轻松学会openpyxl库,Python处理Excel有如神助
轻松学会openpyxl库,Python处理Excel有如神助
|
19天前
|
NoSQL Python
在Python中,我们可以使用许多库来处理Excel文件
Python处理Excel常用pandas和openpyxl库。pandas的`read_excel`用于读取文件,`to_excel`写入;示例展示了数据框操作。openpyxl则用于处理复杂情况,如多工作表,`load_workbook`加载文件,`iter_rows`读取数据,`Workbook`创建新文件,写入单元格数据后保存。
27 1