Package: openpyxl-grid
Openpyxl GridThis project aims to build a python module based on Openpyxl for writing datas and functions into Excel file as a grid.Getting StartedThese instructions will get you a copy of the project up and running on your local machine for development and testing purposes.The tool of pip can be used to install this project module on local machine for development.PrerequisitesThe minimal requirement to use this module is python3.7. The python3.7+ must be installed at first.InstallingThe command to install the module of this project on a Unix liked system, such as Linux or macOS:python3 -m pip install openpyxl-gridThe command to install on a Windows system as below:py -m pip install openpyxl-gridRunning the testsThere is a simple guide of how to use the module in a python file in this section.
And an example python file named example_stock.py for test purpose is list in the project directory of test.Example code for testThe example code below show you how to use the module in a python file:fromopenpyxl_gridimportGrid,OType,VType,OA,TO,CO"""Grid: The Grid object stored attrs and opers for writing into a Excel file.OType: The Definition of Operation Type for opers added to Grid.VType: The Value Type for Specified in Custom Operation.OA: params linked to attrs and opers has added into a Grid object in the function of add opers in a Grid object.TO: Sub Type Operation object for adding as params.CO: Sub Custom Operation object for adding as params."""# Init attr objects for Grida1=[1,2,3,4]a2=[4,5,6]a3=[7,8,9]a4=['abc','bcd','cde']a5=['def','efg','fgh']# Init Grid object for testg=Grid('test',a1=a1,a3=a3)# append attrs to Grid objectg.add_attrs(a2=a2,a4=a4,a5=a5)# add Type Operation to Grid objectg.add_oper('max_a',OType.max,OA('a1'),OA('a2'))g.add_oper('con',OType.plus,OA('a4'),OA('a5'))g.add_oper('sum_a',OType.plus,OA('a1'),OA('a2'),OA('a3'))g.add_oper('a1+a2+a3',OType.plus,OA('a1'),OA('a2'),OA('a3'),3)g.add_oper('a1-a2-a3',OType.minus,OA('a1'),OA('a2'),OA('a3'),3)# add Type Operation including sub operation to Grid objectg.add_oper('a1+(a2-a3)',OType.plus,OA('a1'),TO(OType.minus,OA('a2'),OA('a3')))g.add_oper('a1+(a2-(a3+a1))',OType.plus,OA('a1'),TO(OType.minus,OA('a2'),TO(OType.plus,OA('a3'),OA('a1'))))# add Type Operation with operation parameter and normal valueg.add_oper('sum_a+2',OType.plus,OA('sum_a'),2)# add Custom Operation to Grid objectg.add_custom_oper('custom','IF({0}>{1}, TRUE, FALSE)',VType.num,OA('a1'),OA('a2'))# add Type Operation with sub Type and Custom Operationsg.add_oper('a1+(a2-a3)+custom',OType.plus,OA('a1'),TO(OType.minus,OA('a2'),OA('a3')),CO('IF({0}=TRUE, 1, 10)',VType.num,OA('custom')))# add operations which will be converted to array formula when write Excel fileg.add_custom_oper('custom_max','MAX({0},{1})',VType.num,OA('a1'),OA('a2'))g.add_oper('max_if_a',OType.maxIf,OA('a1',True),1,OA('sum_a',True))# add Type Operation for string attrsg.add_oper('index_of',OType.indexOf,'c',OA('a4'))# write attrs and opers into different sheet in a Excel fileg.write_separate_xl('test.xlsx')# write attrs and opers into same sheet in a Excel fileg.write_together_xl('test_t.xlsx')The Definition of Operation Type(OType)The table below shows Operation Type(OType) for each Value Type(VType) defined in the module of this version:VTypeOType Supportnumplus, minus, divide, multipy, mod, sqrt, equal, length, replace, max, min, avg, maxIf, minIf, sumIf, avgIf, isNullstrplus, indexOf, equal, upper, lower, length, replace, isNulldateTimeaddDays, minus, equal, replace, max, min, maxIf, minIf, year, month, day, hour, minute, second, weekday, weeknum, isNullThe Definition of OType is in the file of xoper.py for detail.Example file for test purposeExample python file named example_stock.py for test purpose is list in the project directory of test. After module installation of this porject by the tool of pip, this example file can be executed successfully if the installation is correct.VersioningNavigate totags on this repositoryto see all available versions.AuthorsJianai Wang-Initial work-Openpyxl-gridSee also the list ofcontributorswho participated in this project.LicenseThis project is licensed under the MIT License - see theLICENSEfile for details