Excel记录的分析器和架构查看和验证工具。
excelschema的Python项目详细描述
excelschema
Excel记录的分析器和架构查看和验证工具。
安装
方法1:
$ pip install excelschema
方法2:
- 从github克隆项目
poetry install
用法
>>>fromexcelschemaimportSchemaParser>>>importpyexcel>>>sp=SchemaParser(records=pyexcel.get_records(file_name='foo.xlsx',sheet_name='bar'))>>>sp.schema{'record_id':<class'int'>,'modified':<class'datetime.datetime'>,'data':<class'str'>}
验证记录并将其转换为可用记录。
>>>sp.ensure_one({'record_id':' 12','data':567}){'record_id',12,'data':'567'}
设置约束
>>>fromexcelschemaimportConstraint>>>sp.update_schema({...'user_id':Constraint(type_=int,unique=True,not_null=True)...})
也可以在没有excel的情况下创建自定义模式
>>>sp=SchemaParser(schema={...'record_id':Constraint(type_=int,unique=True,not_null=True),...'modified':datetime...})
奖励功能
清除脏的Excel记录
>>>fromexcelschemaimportparse_record>>>parse_record({'foo':' 1','bar':' - ','baz':' '}){'foo',1}