[go: up one dir, main page]

CN117236307A - An excel data import method, device, equipment and storage medium - Google Patents

An excel data import method, device, equipment and storage medium Download PDF

Info

Publication number
CN117236307A
CN117236307A CN202311212572.1A CN202311212572A CN117236307A CN 117236307 A CN117236307 A CN 117236307A CN 202311212572 A CN202311212572 A CN 202311212572A CN 117236307 A CN117236307 A CN 117236307A
Authority
CN
China
Prior art keywords
attribute
data
excel
excel file
verification
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311212572.1A
Other languages
Chinese (zh)
Inventor
付梁杰
李雪兰
李栋
蒋伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Tianque Technology Co ltd
Original Assignee
Hangzhou Tianque Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Tianque Technology Co ltd filed Critical Hangzhou Tianque Technology Co ltd
Priority to CN202311212572.1A priority Critical patent/CN117236307A/en
Publication of CN117236307A publication Critical patent/CN117236307A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses an excel data importing method, device, equipment and storage medium, and relates to the technical field of data processing. The method comprises the following steps: acquiring an excel file, and analyzing the excel file to extract attribute information from an attribute worksheet of the excel file; converting the attribute information into custom object attributes to obtain attribute objects corresponding to the attribute information, and storing the attribute objects into global array variables according to the sequence number sequence; traversing each row and each column of data of each worksheet in the excel file in a circulating way, and carrying out attribute verification on the data of each cell in the excel file by combining a global array variable; after all the data are verified, each data is converted into a target format object for storage based on an excel file and according to a global array variable. The efficiency of the java developer in developing the excle data import function can be improved.

Description

一种excel数据导入方法、装置、设备及存储介质An excel data import method, device, equipment and storage medium

技术领域Technical field

本发明涉及数据处理技术领域,特别涉及一种excel数据导入方法、装置、设备及存储介质。The invention relates to the field of data processing technology, and in particular to an excel data import method, device, equipment and storage medium.

背景技术Background technique

目前,实现java导入excel数据,往往需要提前为每个模块定义固定导入模板文件以及每个模块独立的验证规则代码,造成验收代码重复度高、模块信息稍有变动就需要硬编码修改原代码适配度、扩展性不强。很难适应业务多变的应用场景。At present, to implement Java's import of excel data, it is often necessary to define a fixed import template file for each module in advance and an independent verification rule code for each module. This results in high duplication of acceptance codes, and slight changes in module information require hard-coding to modify the original code to suit. The configuration and scalability are not strong. It is difficult to adapt to changing business application scenarios.

发明内容Contents of the invention

有鉴于此,本发明的目的在于提供一种excel数据导入方法、装置、设备及介质,能够提高java开发人员开发excle数据导入功能的效率。其具体方案如下:In view of this, the purpose of the present invention is to provide an excel data import method, device, equipment and medium, which can improve the efficiency of Java developers in developing excel data import functions. The specific plan is as follows:

第一方面,本申请公开了一种excel数据导入方法,包括:In the first aspect, this application discloses a method for importing excel data, including:

获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息;Obtain an excel file, and parse the excel file to extract attribute information from the attribute worksheet of the excel file;

将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量;Convert the attribute information into custom object attributes to obtain attribute objects corresponding to the attribute information, and store the attribute objects in the global array variable in order of column numbers;

通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证;By sequentially looping through the data of each row and column of each worksheet in the excel file, and combining the global array variables to perform attribute verification on the data of each cell in the excel file;

在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。After all data is verified, each row of data is converted into a target format object for storage based on the excel file and the global array variable.

可选的,所述属性信息包括属性英文名、属性中文名、属性类型和属性验证规则。Optionally, the attribute information includes attribute English name, attribute Chinese name, attribute type and attribute verification rules.

可选的,所述属性类型包括自定义行政区域;所述自定义行政区域包含用于标识行政区划名称的字符串类型的名称属性、用于标识行政区域编码的字符串类型的编码属性、用于标识行政区域id属性的长整型的id属性中的一项或多项;Optionally, the attribute type includes a custom administrative region; the custom administrative region includes a name attribute of the string type used to identify the name of the administrative division, a coding attribute of the string type used to identify the administrative region code, and One or more items in the long integer id attribute identifying the administrative region id attribute;

所述属性类型包括自定义字典;所述自定义字典包含用于标记字典项id的长整型的id属性、用于标识字典中文值的字符串类型的显示名称属性中的一项或多项。The attribute type includes a custom dictionary; the custom dictionary includes one or more of the long integer id attribute used to mark the dictionary item id, and the display name attribute of the string type used to identify the Chinese value of the dictionary. .

可选的,所述通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证,包括:Optionally, by sequentially looping through the data of each row and column of each worksheet in the excel file, and combining the global array variables to perform attribute verification on the data of each cell in the excel file, including :

依次循环遍历所述excel文件中每个工作表的每行每列数据,并将每个单元格数据存入二维数组中;Loop through each row and column of data in each worksheet in the excel file in sequence, and store each cell data into a two-dimensional array;

循环遍历所述二维数组的每行每列数据,并在遍历过程中,根据当前遍历到的目标数据的列值从所述全局数组变量中获取具有相同列值的验证对象;Loop through the data in each row and column of the two-dimensional array, and during the traversal process, obtain a verification object with the same column value from the global array variable according to the column value of the currently traversed target data;

利用属性验证规则对所述验证对象进行验证。The verification object is verified using attribute verification rules.

可选的,所述属性验证规则,包括用于标识是否可为空的布尔类型的需求属性,用于标识属性数据类型的字符串类型的类型属性,用于标识正则表达式验证规则的字符串类型的正则表达式属性,用于标识最大值最小值的字符串类型的最大值和最小值属性,用于标识数据格式的字符串类型的格式属性,用于标识最大长度和最小长度的基本整型类型的最大长度和最小长度属性中的一项或多项。Optionally, the attribute verification rules include a requirement attribute of Boolean type used to identify whether it is nullable, a type attribute of string type used to identify the attribute data type, and a string used to identify the regular expression verification rule. The regular expression attribute of the type, the maximum and minimum value attributes of the string type used to identify the maximum and minimum values, the format attribute of the string type used to identify the data format, the basic integer used to identify the maximum length and minimum length. One or more of the maximum length and minimum length properties of the type.

可选的,所述结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证之后,还包括:Optionally, after performing attribute verification on the data of each cell in the excel file in combination with the global array variable, it also includes:

若验证不通过,则基于当前单元格的数据、针对当前单元格的验证规则和所述当前单元格的数据对应的属性信息构建错误提示信息;If the verification fails, an error message is constructed based on the data of the current cell, the verification rules for the current cell, and the attribute information corresponding to the data of the current cell;

将所述错误提示信息以批注形式插入所述当前单元格,并修改所述当前单元格的底色。Insert the error message into the current cell in the form of a comment, and modify the background color of the current cell.

可选的,所述基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储,包括:Optionally, based on the excel file and the global array variable, convert each row of data into a target format object for storage, including:

循环遍历所述excel文件并根据所述全局数组变量,以每列属性名作为目标格式对象的键并以数据作为目标格式对象的值,将每行数据转换为一个目标格式对象;Loop through the excel file and convert each row of data into a target format object according to the global array variable, using the attribute name of each column as the key of the target format object and the data as the value of the target format object;

将所述目标格式对象存入数据库,并在存入成功后反馈成功提示。The target format object is stored in the database, and a success prompt is fed back after successful storage.

第二方面,本申请公开了一种excel数据导入装置,包括:In the second aspect, this application discloses an excel data importing device, including:

属性信息提取模块,用于获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息;An attribute information extraction module is used to obtain an excel file and parse the excel file to extract attribute information from the attribute worksheet of the excel file;

属性信息转换模块,用于将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量;The attribute information conversion module is used to convert the attribute information into custom object attributes to obtain the attribute objects corresponding to the attribute information, and store the attribute objects in the global array variable in order of column numbers;

验证模块,用于通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证;A verification module, configured to sequentially loop through the data of each row and column of each worksheet in the excel file, and perform attribute verification on the data of each cell in the excel file in combination with the global array variable;

存储模块,用于在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。The storage module is used to convert each row of data into a target format object for storage based on the excel file and the global array variable after all data verification.

第三方面,本申请公开了一种电子设备,包括:In a third aspect, this application discloses an electronic device, including:

存储器,用于保存计算机程序;Memory, used to hold computer programs;

处理器,用于执行所述计算机程序,以实现前述的excel数据导入方法。A processor, configured to execute the computer program to implement the aforementioned excel data import method.

第四方面,本申请公开了一种计算机可读存储介质,用于存储计算机程序;其中计算机程序被处理器执行时实现前述的excel数据导入方法。In a fourth aspect, this application discloses a computer-readable storage medium for storing a computer program; when the computer program is executed by a processor, the aforementioned excel data import method is implemented.

本申请中,获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息;将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量;通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证;在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。可见,根据excle属性工作表中定义的属性信息转换得到属性对象存储至全局数组变量,后续利用属性对象进行验证,而并非直接对java定义的javabean(JAVA语言写成的可重用组件,用于通过提供符合一致性设计模式的公共方法将内部域暴露成员属性)进行一对一转换,由此,数据验证时无需每个excle文件模块定义一个验证类进行验证,而是一套验证逻辑根据传入的验证规则即可适用所有excle文件模块的验证,能够将有效提高java开发人员开发excle数据导入功能的效率,可扩展性强,excle导入方法调度抽象、灵活,实现低代码快速构建excel数据导入功能。In this application, an excel file is obtained, and the excel file is parsed to extract attribute information from the attribute worksheet of the excel file; the attribute information is converted into custom object attributes to obtain the attribute information Corresponding attribute objects, and store the attribute objects in global array variables in order of column numbers; by sequentially looping through the data of each row and column of each worksheet in the excel file, and combining the data of the global array variables with The data of each cell in the excel file is subjected to attribute verification; after all data is verified, based on the excel file and the global array variable, each row of data is converted into a target format object for storage. It can be seen that the attribute object is converted according to the attribute information defined in the excel attribute worksheet and stored in the global array variable. The attribute object is subsequently used for verification, instead of directly using the javabean defined in java (a reusable component written in JAVA language, which is used to provide The public method that conforms to the consistent design pattern performs a one-to-one conversion of the internal domain exposed member attributes). Therefore, when validating data, there is no need to define a validation class for each excel file module for validation, but a set of validation logic based on the incoming The verification rules can be applied to the verification of all excel file modules, which can effectively improve the efficiency of java developers in developing excel data import functions. It has strong scalability, and the excel import method scheduling is abstract and flexible, realizing the rapid construction of excel data import functions with low code.

附图说明Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图。In order to explain the embodiments of the present invention or the technical solutions in the prior art more clearly, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings in the following description are only These are embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on the provided drawings without exerting creative efforts.

图1为本申请提供的一种excel数据导入方法流程图;Figure 1 is a flow chart of an excel data import method provided by this application;

图2为本申请提供的一种excel数据导入装置结构示意图;Figure 2 is a schematic structural diagram of an excel data import device provided by this application;

图3为本申请提供的一种电子设备结构图。Figure 3 is a structural diagram of an electronic device provided by this application.

具体实施方式Detailed ways

为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments These are only some embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present invention.

现有技术中,实现java导入excel数据,往往需要提前为每个模块定义固定导入模板文件以及每个模块独立的验证规则代码,造成验收代码重复度高、模块信息稍有变动就需要硬编码修改原代码适配度、扩展性不强。很难适应业务多变的应用场景。为克服上述技术问题,本申请提出一种excel数据导入方法,能够提高java开发人员开发excle数据导入功能的效率。In the existing technology, to implement Java's import of excel data, it is often necessary to define a fixed import template file for each module in advance and an independent verification rule code for each module, resulting in high duplication of the acceptance code and the need for hard-coded modifications if the module information changes slightly. The original code has poor adaptability and scalability. It is difficult to adapt to changing business application scenarios. In order to overcome the above technical problems, this application proposes an excel data import method, which can improve the efficiency of Java developers in developing excel data import functions.

本申请实施例公开了一种excel数据导入方法,参见图1所示,该方法可以包括以下步骤:The embodiment of the present application discloses a method for importing excel data, as shown in Figure 1. The method may include the following steps:

步骤S11:获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息。Step S11: Obtain an excel file, and parse the excel file to extract attribute information from the attribute worksheet of the excel file.

本实施例中,首先获取用户上传的excel文件,并创建对应的文件对象,并获取对应的文件流;文件流是一种从文件读取数据或将数据写入文件的方式,在文件流中,文件以流的形式传输,可以以字节或字符串的形式进行读写。In this embodiment, the excel file uploaded by the user is first obtained, the corresponding file object is created, and the corresponding file stream is obtained; the file stream is a way of reading data from a file or writing data to a file. In the file stream , the file is transmitted in the form of a stream and can be read and written in the form of bytes or strings.

其中,所述属性信息包括属性英文名、属性中文名、属性类型和属性验证规则。具体的,采用org.apache.poi技术(ApachePOI,Apache Poor Obfuscation Implementation,简洁版的模糊实现)对所述excel文件进行解析以从excel文件的属性工作表中提取出属性信息。org.apache.poi是用Java编写的免费开源的跨平台的Java API,Apache POI提供API给Java程序对Microsoft Office格式档案读和写的功能;解析待导入的excel数据,具体从属性工作表(即隐藏的名称为bean的sheet薄)中获取所有属性英文名、属性中文名、属性类型、属性验证规则。属性类型包括自定义行政区域(Organization)和自定义字典(PropertyDict)。Wherein, the attribute information includes attribute English name, attribute Chinese name, attribute type and attribute verification rules. Specifically, org.apache.poi technology (Apache POI, Apache Poor Obfuscation Implementation, a concise version of fuzzy implementation) is used to parse the excel file to extract attribute information from the attribute worksheet of the excel file. org.apache.poi is a free and open source cross-platform Java API written in Java. Apache POI provides APIs for Java programs to read and write Microsoft Office format files; it parses the excel data to be imported, specifically from the attribute worksheet ( That is, get all the attribute English names, attribute Chinese names, attribute types, and attribute validation rules from the hidden sheet named bean. Attribute types include custom administrative region (Organization) and custom dictionary (PropertyDict).

本实施例中,所述属性类型包括自定义行政区域;所述自定义行政区域包含用于标识行政区划名称的字符串类型(String)的名称属性、用于标识行政区域编码的字符串类型的编码属性、用于标识行政区域id属性的长整型(Long)的id属性中的一项或多项。即自定义行政区域包含String类型的name属性,用于标识行政区划名称,包含String类型的org_code,用于标识行政区域编码;包含Long类型的id属性,标识行政区域的id属性。所述属性类型包括自定义字典;所述自定义字典包含用于标记字典项id的长整型的id属性、用于标识字典中文值的字符串类型的显示名称属性中的一项或多项。即PropertyDict包含Long类型的id属性,标记字典项的id;包含String类型的displayName属性,标识字典中文值。In this embodiment, the attribute type includes a custom administrative region; the custom administrative region includes a name attribute of string type (String) used to identify the name of the administrative division, and a string type (String) used to identify the administrative region code. One or more of the encoding attributes and the long integer (Long) id attribute used to identify the administrative region id attribute. That is, the custom administrative region contains a name attribute of String type, used to identify the name of the administrative division, an org_code of String type, used to identify the administrative region code, and an id attribute of Long type, used to identify the administrative region's id attribute. The attribute type includes a custom dictionary; the custom dictionary includes one or more of the long integer id attribute used to mark the dictionary item id, and the display name attribute of the string type used to identify the Chinese value of the dictionary. . That is, PropertyDict contains the id attribute of Long type, which marks the id of the dictionary item; it contains the displayName attribute of String type, which identifies the Chinese value of the dictionary.

步骤S12:将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量。Step S12: Convert the attribute information into custom object attributes to obtain attribute objects corresponding to the attribute information, and store the attribute objects in the global array variable in order of column numbers.

本实施例中,将得到的属性信息直接转换为自定义对象属性,以得到属性信息对应的属性对象,并将属性对象按照列序号顺序存储至全局数组变量。即将属性参数转换为自定义对象属性:对象属性(AttributeObject),并按对应列序号顺序放入全局数组变量(attributeArray)中。由此,将要导入数据属性、验证规则在exel定义存入到数组,并与数据相呼应,比后端预先定义bean对象更具扩展性。且数据转换为无需提前定义bean对象的JSONObject等键值对对象来提高扩展性。In this embodiment, the obtained attribute information is directly converted into custom object attributes to obtain attribute objects corresponding to the attribute information, and the attribute objects are stored in global array variables in order of column numbers. That is, the attribute parameters are converted into custom object attributes: object attributes (AttributeObject), and put into the global array variable (attributeArray) in order of the corresponding column numbers. As a result, the data attributes and validation rules to be imported are stored in the array in the exel definition and echo the data, which is more scalable than the back-end pre-defined bean object. And the data is converted into key-value pair objects such as JSONObject without defining bean objects in advance to improve scalability.

步骤S13:通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证。Step S13: Loop through the data of each row and column of each worksheet in the excel file in sequence, and perform attribute verification on the data of each cell in the excel file in combination with the global array variable.

本实施例中,验证时通过依次遍历工作表中每行每列数据,根据全局数组变量中存放的属性信息,对excel文件中每个单元格的数据进行属性验证。可见,本实施例中,获取到excel数据后,不是根据java定义的javabean进行一对一转换,而是根据excle属性页定义的属性名、属性类型进行转换,区别于对javabean的转换,本实施例数据验证时无需每个模块定义一个验证类进行验证,一套验证逻辑根据传入的规则即可适用所有模块验证。In this embodiment, during verification, each row and column of data in the worksheet are traversed in turn, and the attributes of each cell in the excel file are verified based on the attribute information stored in the global array variable. It can be seen that in this embodiment, after the excel data is obtained, it is not converted one-to-one according to the javabean defined by java, but according to the attribute name and attribute type defined by the excel property page. Different from the conversion of javabean, this implementation When verifying example data, there is no need to define a verification class for each module for verification. A set of verification logic can be applied to all module verifications based on the incoming rules.

本实施例中,所述通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证,可以包括:依次循环遍历所述excel文件中每个工作表的每行每列数据,并将每个单元格数据存入二维数组中;循环遍历所述二维数组的每行每列数据,并在遍历过程中,根据当前遍历到的目标数据的列值从所述全局数组变量中获取具有相同列值的验证对象;利用属性验证规则对所述验证对象进行验证。即获取数据开始行的参数值,然后通过poi技术从第一个工作表(sheet)的数据开始行获取数据,循环遍历每行、每列的数据,将每个单元格数据存入到二维数组对象(String[][])中待用;循环遍历二维数组的数据每行、每列的数据;遍历到对应列值时,从全局数组变量中获取相同列值的验证对象,并根据自定义验证(CustomValidation)对象定义的验证规则来验证数据。In this embodiment, the data of each row and column of each worksheet in the excel file is looped sequentially, and the attributes of each cell data in the excel file are verified in combination with the global array variable. It may include: sequentially looping through each row and each column of data in each worksheet in the excel file, and storing each cell data in a two-dimensional array; looping through each row and each column of data in the two-dimensional array, And during the traversal process, a verification object with the same column value is obtained from the global array variable according to the column value of the currently traversed target data; the verification object is verified using attribute verification rules. That is, get the parameter value of the starting row of data, and then use POI technology to get the data from the starting row of data of the first worksheet (sheet), loop through the data of each row and column, and store each cell data into a two-dimensional For use in the array object (String[][]); loop through the data of each row and column of the two-dimensional array; when traversing to the corresponding column value, obtain the verification object of the same column value from the global array variable, and based on Use the validation rules defined by the CustomValidation object to validate the data.

上述属性验证规则,包括用于标识是否可为空的布尔类型的需求属性,用于标识属性数据类型的字符串类型的类型属性,用于标识正则表达式验证规则的字符串类型的正则表达式属性,用于标识最大值最小值的字符串类型的最大值和最小值属性,用于标识数据格式的字符串类型的格式属性,用于标识最大长度和最小长度的基本整型类型的最大长度和最小长度属性中的一项或多项。也即,上述自定义验证类型对象CustomValidation:包含boolean类型的required属性,用于标识是否可为空,默认为false,表示可为空,true表示不可为空;还包含String类型的type属性,用于标识属性数据类型,可填写java内置类型和自定义类型;还包含String类型的regex属性,用于标识正则表达式验证规则,默认为空,有值则据此来验证;还包含String类型的maxValue和minValue属性,用于标识最大值最小值,主要针对数字与日期类型;还包含String类型的format属性,用于标识数据格式,如果数字类型的00.00,日期类型的‘yyyy-mm-dd hh24:mi:ss’等,默认为空;还包含int类型的minLengh和maxLengh属性,用于标识最大长度和最小长度,为空不限制。The above attribute validation rules include a requirement attribute of Boolean type used to identify whether it is nullable, a type attribute of string type used to identify the attribute data type, and a regular expression of string type used to identify the regular expression verification rule. Attributes, the maximum and minimum value attributes of the string type used to identify the maximum and minimum values, the format attribute of the string type used to identify the data format, the maximum length of the basic integer type used to identify the maximum length and minimum length and one or more of the minimum length attributes. That is to say, the above-mentioned custom validation type object CustomValidation: contains the required attribute of boolean type, used to identify whether it can be null, the default is false, which means it can be null, and true means it cannot be null; it also contains the type attribute of String type, which is used To identify the attribute data type, you can fill in the java built-in type and custom type; it also contains the regex attribute of the String type, which is used to identify the regular expression verification rules. It is empty by default. If there is a value, it will be verified accordingly; it also contains the String type. The maxValue and minValue attributes are used to identify the maximum and minimum values, mainly for numbers and date types; they also include the format attribute of String type, which is used to identify the data format. If the number type is 00.00, the date type is 'yyyy-mm-dd hh24 :mi:ss', etc., which are empty by default; it also contains minLengh and maxLengh attributes of type int, which are used to identify the maximum length and minimum length. If they are empty, there is no limit.

步骤S14:在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。Step S14: After all data is verified, based on the excel file and the global array variable, convert each row of data into a target format object for storage.

本实施例中,若当前单元格的数据属性验证通过,则执行下一个单元格的验证,可以在所有数据验证后,或当前行内所有数据验证后,基于excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。之后具体将目标格式对象存入对应入库,并在入库成功后将成功提示返回前端。In this embodiment, if the data attribute verification of the current cell passes, the verification of the next cell can be performed. After all data is verified, or after all data in the current row is verified, based on the excel file and the global array variable, Convert each row of data into a target format object for storage. After that, the target format object is specifically stored in the corresponding database, and after the database is successfully stored, a success prompt will be returned to the front end.

本实施例中,所述结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证之后,还可以包括:若验证不通过,则基于当前单元格的数据、针对当前单元格的验证规则和所述当前单元格的数据对应的属性信息构建错误提示信息;将所述错误提示信息以批注形式插入所述当前单元格,并修改所述当前单元格的底色。具体的,若未通过数据验证则结合验证规则、验证属性中文名、验证数据对应单元格信息拼接错误提示信息,以批注信息插入到对应单元格同时将该错误单元格底色标记为红色,同时标记有错误,也即验证不通过后的信息返回,直接写入到原始数据导入文件对应的单元格,错误提示定位更加精确明显。数据验证未通过时,则跳过数据转换与存储,直接返回结果信息,并提供错误数据表格下载,具体可以在原数据单元格上标红底及加错误文字标识提示更精准、并可以直接在错误信息表上修改数据后再次导入。In this embodiment, after the attribute verification of the data of each cell in the excel file is performed in conjunction with the global array variable, it may also include: if the verification fails, based on the data of the current cell, for the current cell The verification rules of the cell and the attribute information corresponding to the data of the current cell are used to construct error prompt information; the error prompt information is inserted into the current cell in the form of annotation, and the background color of the current cell is modified. Specifically, if the data verification fails, the error prompt information is combined with the verification rules, the Chinese name of the verification attribute, and the cell information corresponding to the verification data, and the annotation information is inserted into the corresponding cell and the background color of the error cell is marked red. If an error is marked, that is, the information returned after the verification fails, it will be written directly to the corresponding cell of the original data import file, and the error prompt positioning will be more precise and obvious. When the data verification fails, the data conversion and storage will be skipped, the result information will be returned directly, and the error data table will be provided for download. Specifically, you can mark the original data cells with a red background and add error text to indicate more accurate prompts, and you can directly add errors in the Modify the data on the information table and import it again.

本实施例中,所述基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储,可以包括:循环遍历所述excel文件并根据所述全局数组变量,以每列属性名作为目标格式对象的键并以数据作为目标格式对象的值,将每行数据转换为一个目标格式对象;将所述目标格式对象存入数据库,并在存入成功后反馈成功提示。即将数据转换成键值对,由此如果是需要添加一列数据或删除一列数据时,不需要对应后端bean对象进行代码修改,只需要修改excel文件即可,节约工作量、同时也更灵活、也无需重新发布后端程序,只需要替换表态excel模板文件即可。In this embodiment, converting each row of data into a target format object for storage based on the excel file and according to the global array variable may include: looping through the excel file and according to the global array variable, Use the attribute name of each column as the key of the target format object and use the data as the value of the target format object, convert each row of data into a target format object; store the target format object in the database, and feedback success after successful storage hint. That is to say, the data is converted into key-value pairs. Therefore, if you need to add a column of data or delete a column of data, you do not need to modify the code corresponding to the back-end bean object. You only need to modify the excel file, which saves workload and is more flexible. There is no need to re-publish the back-end program, just replace the excel template file.

也就是说,若数据验证通过后,循环遍历所有数据,并结合全局数组变量(attributeArray)对应单元格属性名、属性类型,将每行数据转换为一个目标格式对象,上述目标格式可以为JSON也可以为Map,以JSON为例,将每列属性名作为JSONObject对象的key(键),数据作为JSONObject的value(值),每行数据转换为一个JSONObject数据,转换为json数据相对于定义bean对象更易扩展,增减字段无需修改代码,只需要excel字段属性和数据对应增加一列即可。That is to say, if the data verification passes, loop through all the data, and combine the global array variable (attributeArray) with the corresponding cell attribute name and attribute type to convert each row of data into a target format object. The above target format can be JSON or It can be a Map. Taking JSON as an example, the attribute name of each column is used as the key of the JSONObject object, and the data is used as the value of the JSONObject. Each row of data is converted into a JSONObject data, and the converted json data is relative to the defined bean object. Easier to expand. There is no need to modify the code to add or delete fields. You only need to add a column corresponding to the excel field attributes and data.

由上可见,本实施例中获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息;将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量;通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证;在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。可见,根据excle属性工作表中定义的属性信息转换得到属性对象存储至全局数组变量,后续利用属性对象进行验证,而并非直接对java定义的javabean(JAVA语言写成的可重用组件,用于通过提供符合一致性设计模式的公共方法将内部域暴露成员属性)进行一对一转换,由此,数据验证时无需每个excle文件模块定义一个验证类进行验证,而是一套验证逻辑根据传入的验证规则即可适用所有excle文件模块的验证,能够将有效提高java开发人员开发excle数据导入功能的效率,可扩展性强,excle导入方法调度抽象、灵活,实现低代码快速构建excel数据导入功能。As can be seen from the above, in this embodiment, an excel file is obtained, and the excel file is parsed to extract attribute information from the attribute worksheet of the excel file; the attribute information is converted into custom object attributes to obtain The attribute object corresponding to the attribute information is stored in the global array variable in order of column number; by sequentially looping through each row and column data of each worksheet in the excel file, and combining the global The array variable performs attribute verification on the data of each cell in the excel file; after all data verification, based on the excel file and the global array variable, each row of data is converted into a target format object for storage. It can be seen that the attribute object is converted according to the attribute information defined in the excel attribute worksheet and stored in the global array variable. The attribute object is subsequently used for verification, instead of directly using the javabean defined in java (a reusable component written in JAVA language, which is used to provide The public method that conforms to the consistent design pattern performs a one-to-one conversion of the internal domain exposed member attributes). Therefore, when validating data, there is no need to define a validation class for each excel file module for validation, but a set of validation logic based on the incoming The verification rules can be applied to the verification of all excel file modules, which can effectively improve the efficiency of java developers in developing excel data import functions. It has strong scalability, and the excel import method scheduling is abstract and flexible, realizing the rapid construction of excel data import functions with low code.

本申请实施例还公开了一种excel数据导入装置,参见图2所示,该装置包括:The embodiment of the present application also discloses an excel data importing device, as shown in Figure 2. The device includes:

属性信息提取模块11,用于获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息;The attribute information extraction module 11 is used to obtain an excel file and parse the excel file to extract attribute information from the attribute worksheet of the excel file;

属性信息转换模块12,用于将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量;The attribute information conversion module 12 is used to convert the attribute information into custom object attributes to obtain the attribute objects corresponding to the attribute information, and store the attribute objects in the global array variable in order of column numbers;

验证模块13,用于通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证;The verification module 13 is used to sequentially loop through the data of each row and column of each worksheet in the excel file, and perform attribute verification on the data of each cell in the excel file in combination with the global array variable;

存储模块14,用于在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。The storage module 14 is configured to convert each row of data into a target format object for storage based on the excel file and the global array variable after all data verification.

由上可见,本实施例中获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息;将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量;通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证;在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。可见,根据excle属性工作表中定义的属性信息转换得到属性对象存储至全局数组变量,后续利用属性对象进行验证,而并非直接对java定义的javabean(JAVA语言写成的可重用组件,用于通过提供符合一致性设计模式的公共方法将内部域暴露成员属性)进行一对一转换,由此,数据验证时无需每个excle文件模块定义一个验证类进行验证,而是一套验证逻辑根据传入的验证规则即可适用所有excle文件模块的验证,能够将有效提高java开发人员开发excle数据导入功能的效率,可扩展性强,excle导入方法调度抽象、灵活,实现低代码快速构建excel数据导入功能。As can be seen from the above, in this embodiment, an excel file is obtained, and the excel file is parsed to extract attribute information from the attribute worksheet of the excel file; the attribute information is converted into custom object attributes to obtain The attribute object corresponding to the attribute information is stored in the global array variable in order of column number; by sequentially looping through each row and column data of each worksheet in the excel file, and combining the global The array variable performs attribute verification on the data of each cell in the excel file; after all data verification, based on the excel file and the global array variable, each row of data is converted into a target format object for storage. It can be seen that the attribute object is converted according to the attribute information defined in the excel attribute worksheet and stored in the global array variable. The attribute object is subsequently used for verification, instead of directly using the javabean defined in java (a reusable component written in JAVA language, which is used to provide The public method that conforms to the consistent design pattern performs a one-to-one conversion of the internal domain exposed member attributes). Therefore, when validating data, there is no need to define a validation class for each excel file module for validation, but a set of validation logic based on the incoming The verification rules can be applied to the verification of all excel file modules, which can effectively improve the efficiency of java developers in developing excel data import functions. It has strong scalability, and the excel import method scheduling is abstract and flexible, realizing the rapid construction of excel data import functions with low code.

在一些具体实施例中,所述属性信息具体可以包括属性英文名、属性中文名、属性类型和属性验证规则。In some specific embodiments, the attribute information may specifically include the English name of the attribute, the Chinese name of the attribute, the attribute type, and the attribute verification rules.

在一些具体实施例中,所述属性类型具体可以包括自定义行政区域;所述自定义行政区域包含用于标识行政区划名称的字符串类型的名称属性、用于标识行政区域编码的字符串类型的编码属性、用于标识行政区域id属性的长整型的id属性中的一项或多项;所述属性类型具体可以包括自定义字典;所述自定义字典包含用于标记字典项id的长整型的id属性、用于标识字典中文值的字符串类型的显示名称属性中的一项或多项。In some specific embodiments, the attribute type may specifically include a custom administrative region; the custom administrative region includes a name attribute of a string type used to identify the administrative division name, a string type used to identify the administrative region code One or more of the encoding attributes and the long integer id attribute used to identify the administrative region id attribute; the attribute type may specifically include a custom dictionary; the custom dictionary includes a id attribute used to mark the dictionary item id One or more of the long integer id attribute and the display name attribute of the string type used to identify the Chinese value of the dictionary.

在一些具体实施例中,所述验证模块13具体可以包括:In some specific embodiments, the verification module 13 may specifically include:

二维数组构建单元,用于依次循环遍历所述excel文件中每个工作表的每行每列数据,并将每个单元格数据存入二维数组中;A two-dimensional array construction unit, used to sequentially loop through the data of each row and column of each worksheet in the excel file, and store each cell data into a two-dimensional array;

验证对象获取单元,用于循环遍历所述二维数组的每行每列数据,并在遍历过程中,根据当前遍历到的目标数据的列值从所述全局数组变量中获取具有相同列值的验证对象;The verification object acquisition unit is used to loop through the data in each row and column of the two-dimensional array, and during the traversal process, obtain the same column value from the global array variable according to the column value of the currently traversed target data. Verification object;

验证单元,用于利用属性验证规则对所述验证对象进行验证。A verification unit is used to verify the verification object using attribute verification rules.

在一些具体实施例中,所述属性验证规则,具体可以包括用于标识是否可为空的布尔类型的需求属性,用于标识属性数据类型的字符串类型的类型属性,用于标识正则表达式验证规则的字符串类型的正则表达式属性,用于标识最大值最小值的字符串类型的最大值和最小值属性,用于标识数据格式的字符串类型的格式属性,用于标识最大长度和最小长度的基本整型类型的最大长度和最小长度属性中的一项或多项。In some specific embodiments, the attribute verification rules may specifically include a requirement attribute of Boolean type used to identify whether it is nullable, a type attribute of string type used to identify the attribute data type, and a regular expression used to identify Regular expression properties of type string for the validation rule, max and min properties of type string used to identify the maximum and minimum values, format properties of type string used to identify the data format, used to identify the maximum length and One or more of the maximum-length and minimum-length properties of the minimum-length primitive integer type.

在一些具体实施例中,所述excel数据导入装置具体可以包括:In some specific embodiments, the excel data import device may include:

错误提示信息构架单元,用于在结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证之后,若验证不通过,则基于当前单元格的数据、针对当前单元格的验证规则和所述当前单元格的数据对应的属性信息构建错误提示信息;The error message framework unit is used to perform attribute verification on the data of each cell in the excel file in conjunction with the global array variable. If the verification fails, based on the data of the current cell, based on the data of the current cell, The verification rules and the attribute information corresponding to the data of the current cell construct error prompt information;

批注单元,用于将所述错误提示信息以批注形式插入所述当前单元格,并修改所述当前单元格的底色。An annotation unit is used to insert the error prompt information into the current cell in the form of annotation, and modify the background color of the current cell.

在一些具体实施例中,所述存储模块14具体可以包括:In some specific embodiments, the storage module 14 may include:

数据转换单元,用于循环遍历所述excel文件并根据所述全局数组变量,以每列属性名作为目标格式对象的键并以数据作为目标格式对象的值,将每行数据转换为一个目标格式对象;A data conversion unit configured to loop through the excel file and convert each row of data into a target format according to the global array variable, using the attribute name of each column as the key of the target format object and the data as the value of the target format object. object;

存储单元,用于将所述目标格式对象存入数据库,并在存入成功后反馈成功提示。A storage unit is used to store the target format object in the database, and feedback a success prompt after successful storage.

进一步的,本申请实施例还公开了一种电子设备,参见图3所示,图中的内容不能被认为是对本申请的使用范围的任何限制。Furthermore, the embodiment of the present application also discloses an electronic device, as shown in Figure 3. The content in the figure cannot be considered as any limitation on the scope of the present application.

图3为本申请实施例提供的一种电子设备20的结构示意图。该电子设备20,具体可以包括:至少一个处理器21、至少一个存储器22、电源23、通信接口24、输入输出接口25和通信总线26。其中,所述存储器22用于存储计算机程序,所述计算机程序由所述处理器21加载并执行,以实现前述任一实施例公开的excel数据导入方法中的相关步骤。FIG. 3 is a schematic structural diagram of an electronic device 20 provided by an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input-output interface 25 and a communication bus 26. The memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the excel data import method disclosed in any of the foregoing embodiments.

本实施例中,电源23用于为电子设备20上的各硬件设备提供工作电压;通信接口24能够为电子设备20创建与外界设备之间的数据传输通道,其所遵循的通信协议是能够适用于本申请技术方案的任意通信协议,在此不对其进行具体限定;输入输出接口25,用于获取外界输入数据或向外界输出数据,其具体的接口类型可以根据具体应用需要进行选取,在此不进行具体限定。In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be applicable Any communication protocol of the technical solution of this application is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the external world, and its specific interface type can be selected according to specific application needs. Here Not specifically limited.

另外,存储器22作为资源存储的载体,可以是只读存储器、随机存储器、磁盘或者光盘等,其上所存储的资源包括操作系统221、计算机程序222及包括属性信息在内的数据223等,存储方式可以是短暂存储或者永久存储。In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, a random access memory, a magnetic disk, an optical disk, etc. The resources stored thereon include an operating system 221, a computer program 222, and data 223 including attribute information. The method can be temporary storage or permanent storage.

其中,操作系统221用于管理与控制电子设备20上的各硬件设备以及计算机程序222,以实现处理器21对存储器22中海量数据223的运算与处理,其可以是Windows Server、Netware、Unix、Linux等。计算机程序222除了包括能够用于完成前述任一实施例公开的由电子设备20执行的excel数据导入方法的计算机程序之外,还可以进一步包括能够用于完成其他特定工作的计算机程序。Among them, the operating system 221 is used to manage and control each hardware device and the computer program 222 on the electronic device 20 to realize the calculation and processing of the massive data 223 in the memory 22 by the processor 21. It can be Windows Server, Netware, Unix, Linux etc. In addition to computer programs that can be used to complete the excel data import method executed by the electronic device 20 disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs that can be used to complete other specific tasks.

进一步的,本申请实施例还公开了一种计算机存储介质,所述计算机存储介质中存储有计算机可执行指令,所述计算机可执行指令被处理器加载并执行时,实现前述任一实施例公开的excel数据导入方法步骤。Furthermore, embodiments of the present application also disclose a computer storage medium, which stores computer-executable instructions. When the computer-executable instructions are loaded and executed by a processor, any of the foregoing embodiments disclosed Excel data import method steps.

本说明书中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其它实施例的不同之处,各个实施例之间相同或相似部分互相参见即可。对于实施例公开的装置而言,由于其与实施例公开的方法相对应,所以描述的比较简单,相关之处参见方法部分说明即可。Each embodiment in this specification is described in a progressive manner. Each embodiment focuses on its differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. As for the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple. For relevant details, please refer to the description in the method section.

结合本文中所公开的实施例描述的方法或算法的步骤可以直接用硬件、处理器执行的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly in hardware, in software modules executed by a processor, or in a combination of both. Software modules may be located in random access memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, CD-ROMs, or anywhere in the field of technology. any other known form of storage media.

最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。Finally, it should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that these entities or any such actual relationship or sequence between operations. Furthermore, the terms "comprises," "comprises," or any other variations thereof are intended to cover a non-exclusive inclusion such that a process, method, article, or apparatus that includes a list of elements includes not only those elements, but also those not expressly listed other elements, or elements inherent to the process, method, article or equipment. Without further limitation, an element defined by the statement "comprises a..." does not exclude the presence of additional identical elements in a process, method, article, or apparatus that includes the stated element.

以上对本发明所提供的一种excel数据导入方法、装置、设备及介质进行了详细介绍,本文中应用了具体个例对本发明的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本发明的方法及其核心思想;同时,对于本领域的一般技术人员,依据本发明的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本发明的限制。The above is a detailed introduction to an excel data import method, device, equipment and medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for assistance. Understand the method of the present invention and its core idea; at the same time, for those of ordinary skill in the field, there will be changes in the specific implementation and application scope based on the idea of the present invention. In summary, the content of this specification does not It should be understood as a limitation of the invention.

Claims (10)

1.一种excel数据导入方法,其特征在于,包括:1. A method for importing excel data, which is characterized by including: 获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息;Obtain an excel file, and parse the excel file to extract attribute information from the attribute worksheet of the excel file; 将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量;Convert the attribute information into custom object attributes to obtain attribute objects corresponding to the attribute information, and store the attribute objects in the global array variable in order of column numbers; 通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证;By sequentially looping through the data of each row and column of each worksheet in the excel file, and combining the global array variables to perform attribute verification on the data of each cell in the excel file; 在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。After all data is verified, each row of data is converted into a target format object for storage based on the excel file and the global array variable. 2.根据权利要求1所述的excel数据导入方法,其特征在于,所述属性信息包括属性英文名、属性中文名、属性类型和属性验证规则。2. The excel data import method according to claim 1, characterized in that the attribute information includes attribute English names, attribute Chinese names, attribute types and attribute verification rules. 3.根据权利要求2所述的excel数据导入方法,其特征在于,所述属性类型包括自定义行政区域;所述自定义行政区域包含用于标识行政区划名称的字符串类型的名称属性、用于标识行政区域编码的字符串类型的编码属性、用于标识行政区域id属性的长整型的id属性中的一项或多项;3. The excel data import method according to claim 2, characterized in that the attribute type includes a custom administrative region; the custom administrative region includes a name attribute of a string type used to identify the name of an administrative division, and a user-defined administrative region. One or more of the string type encoding attribute used to identify the administrative region code, and the long integer id attribute used to identify the administrative region id attribute; 所述属性类型包括自定义字典;所述自定义字典包含用于标记字典项id的长整型的id属性、用于标识字典中文值的字符串类型的显示名称属性中的一项或多项。The attribute type includes a custom dictionary; the custom dictionary includes one or more of the long integer id attribute used to mark the dictionary item id, and the display name attribute of the string type used to identify the Chinese value of the dictionary. . 4.根据权利要求1所述的excel数据导入方法,其特征在于,所述通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证,包括:4. The excel data import method according to claim 1, characterized in that the step is to sequentially loop through the data in each row and column of each worksheet in the excel file, and combine the global array variables to The data of each cell in the excel file is subject to attribute verification, including: 依次循环遍历所述excel文件中每个工作表的每行每列数据,并将每个单元格数据存入二维数组中;Loop through each row and column of data in each worksheet in the excel file in sequence, and store each cell data into a two-dimensional array; 循环遍历所述二维数组的每行每列数据,并在遍历过程中,根据当前遍历到的目标数据的列值从所述全局数组变量中获取具有相同列值的验证对象;Loop through the data in each row and column of the two-dimensional array, and during the traversal process, obtain a verification object with the same column value from the global array variable according to the column value of the currently traversed target data; 利用属性验证规则对所述验证对象进行验证。The verification object is verified using attribute verification rules. 5.根据权利要求4述的excel数据导入方法,其特征在于,所述属性验证规则,包括用于标识是否可为空的布尔类型的需求属性,用于标识属性数据类型的字符串类型的类型属性,用于标识正则表达式验证规则的字符串类型的正则表达式属性,用于标识最大值最小值的字符串类型的最大值和最小值属性,用于标识数据格式的字符串类型的格式属性,用于标识最大长度和最小长度的基本整型类型的最大长度和最小长度属性中的一项或多项。5. The excel data import method according to claim 4, characterized in that the attribute verification rules include a Boolean type requirement attribute used to identify whether it can be null, and a string type type used to identify the attribute data type. Attributes, a regular expression attribute of type string used to identify the regular expression validation rule, a maximum and minimum attribute of type string used to identify the maximum and minimum values, a format of type string used to identify the data format Property that identifies one or more of the maximum-length and minimum-length properties of a basic integer type. 6.根据权利要求1述的excel数据导入方法,其特征在于,所述结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证之后,还包括:6. The excel data import method according to claim 1, characterized in that, after performing attribute verification on the data of each cell in the excel file in combination with the global array variable, it further includes: 若验证不通过,则基于当前单元格的数据、针对当前单元格的验证规则和所述当前单元格的数据对应的属性信息构建错误提示信息;If the verification fails, an error message is constructed based on the data of the current cell, the verification rules for the current cell, and the attribute information corresponding to the data of the current cell; 将所述错误提示信息以批注形式插入所述当前单元格,并修改所述当前单元格的底色。Insert the error message into the current cell in the form of a comment, and modify the background color of the current cell. 7.根据权利要求1所述的excel数据导入方法,其特征在于,所述基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储,包括:7. The excel data import method according to claim 1, characterized in that, based on the excel file and according to the global array variable, each row of data is converted into a target format object for storage, including: 循环遍历所述excel文件并根据所述全局数组变量,以每列属性名作为目标格式对象的键并以数据作为目标格式对象的值,将每行数据转换为一个目标格式对象;Loop through the excel file and convert each row of data into a target format object according to the global array variable, using the attribute name of each column as the key of the target format object and the data as the value of the target format object; 将所述目标格式对象存入数据库,并在存入成功后反馈成功提示。The target format object is stored in the database, and a success prompt is fed back after successful storage. 8.一种excel数据导入装置,其特征在于,包括:8. An excel data importing device, characterized in that it includes: 属性信息提取模块,用于获取excel文件,并对所述excel文件进行解析以从所述excel文件的属性工作表中提取出属性信息;An attribute information extraction module is used to obtain an excel file and parse the excel file to extract attribute information from the attribute worksheet of the excel file; 属性信息转换模块,用于将所述属性信息转换为自定义对象属性,以得到所述属性信息对应的属性对象,并将所述属性对象按照列序号顺序存储至全局数组变量;The attribute information conversion module is used to convert the attribute information into custom object attributes to obtain the attribute objects corresponding to the attribute information, and store the attribute objects in the global array variable in order of column numbers; 验证模块,用于通过依次循环遍历所述excel文件中每个工作表的每行每列数据,并结合所述全局数组变量对所述excel文件中每个单元格的数据进行属性验证;A verification module, configured to sequentially loop through the data of each row and column of each worksheet in the excel file, and perform attribute verification on the data of each cell in the excel file in combination with the global array variable; 存储模块,用于在所有数据验证后基于所述excel文件并根据所述全局数组变量,将每行数据转换为一个目标格式对象进行存储。The storage module is used to convert each row of data into a target format object for storage based on the excel file and the global array variable after all data verification. 9.一种电子设备,其特征在于,包括:9. An electronic device, characterized in that it includes: 存储器,用于保存计算机程序;Memory, used to hold computer programs; 处理器,用于执行所述计算机程序,以实现如权利要求1至7任一项所述的excel数据导入方法。A processor, configured to execute the computer program to implement the excel data import method according to any one of claims 1 to 7. 10.一种计算机可读存储介质,其特征在于,用于存储计算机程序;其中计算机程序被处理器执行时实现如权利要求1至7任一项所述的excel数据导入方法。10. A computer-readable storage medium, characterized in that it is used to store a computer program; wherein when the computer program is executed by a processor, the excel data import method according to any one of claims 1 to 7 is implemented.
CN202311212572.1A 2023-09-19 2023-09-19 An excel data import method, device, equipment and storage medium Pending CN117236307A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311212572.1A CN117236307A (en) 2023-09-19 2023-09-19 An excel data import method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311212572.1A CN117236307A (en) 2023-09-19 2023-09-19 An excel data import method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117236307A true CN117236307A (en) 2023-12-15

Family

ID=89097957

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311212572.1A Pending CN117236307A (en) 2023-09-19 2023-09-19 An excel data import method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117236307A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060136808A1 (en) * 2004-12-20 2006-06-22 Microsoft Corporation Block properties and calculated columns in a spreadsheet application
CN110738037A (en) * 2019-10-15 2020-01-31 深圳逻辑汇科技有限公司 Method, apparatus, device and storage medium for automatically generating electronic form
WO2022267457A1 (en) * 2021-06-22 2022-12-29 平安科技(深圳)有限公司 Method, apparatus, and device for processing spreadsheet data, and storage medium
CN116166247A (en) * 2022-12-08 2023-05-26 北京理工大学重庆创新中心 Method, medium and device for data verification during excel file importing

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060136808A1 (en) * 2004-12-20 2006-06-22 Microsoft Corporation Block properties and calculated columns in a spreadsheet application
CN110738037A (en) * 2019-10-15 2020-01-31 深圳逻辑汇科技有限公司 Method, apparatus, device and storage medium for automatically generating electronic form
WO2022267457A1 (en) * 2021-06-22 2022-12-29 平安科技(深圳)有限公司 Method, apparatus, and device for processing spreadsheet data, and storage medium
CN116166247A (en) * 2022-12-08 2023-05-26 北京理工大学重庆创新中心 Method, medium and device for data verification during excel file importing

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
朱虎平等: "一种基于Java注解和反射机制的Excel文件读写操作方法", 九江职业技术学院学报, no. 01, 15 March 2020 (2020-03-15) *
汤怡洁等: "专业领域知识环境中数据摄取工具设计与实现", 图书情报工作, no. 23, 5 December 2012 (2012-12-05) *

Similar Documents

Publication Publication Date Title
US10810110B1 (en) Methods, systems, and articles of manufacture for testing web services using a behavior-driven development domain specific language framework
KR101755365B1 (en) Managing record format information
CN107015948B (en) Method and system for formatting log information
CN104461531B (en) A kind of implementation method of reporting system SQL
CN113227976A (en) Methods, systems, and computer readable media for data transformation using representational state transfer (REST) Application Programming Interfaces (APIs)
CN111460241B (en) Data query method and device, electronic equipment and storage medium
CN113238740A (en) Code generation method, code generation device, storage medium, and electronic apparatus
CN108664546B (en) XML data structure conversion method and device
WO2023103339A1 (en) Data conversion method and device
CN117370242A (en) Adapter and method for generating multilingual SDK client by parsing interface document
CN111078529B (en) Client writing module testing method and device and electronic equipment
CN117236307A (en) An excel data import method, device, equipment and storage medium
CN112799638B (en) Non-invasive rapid development method, platform, terminal and storage medium
KR100762712B1 (en) Rule based electronic document conversion method and system
CN113672233B (en) Server out-of-band management method, device and equipment based on Redfish
US11144287B2 (en) Compile time validation of programming code
CN115129309A (en) A method, system, device and storage medium for sharing front-end and back-end verification rules
CN117111933A (en) Front-end code generation method, device and computer readable storage medium
CN114661298A (en) Public method automatic generation method, system, device and medium
CN114492324A (en) Component data statistics method and device
CN115865898B (en) Method, device, equipment and medium for processing data information among multiple service systems
CN114928658B (en) Low-code platform message data processing system, method and device
US12032433B2 (en) Data structure validation using injected dynamic behavior
CN112199082B (en) A HTTP response processing method, device, electronic equipment and storage medium
CN116048356A (en) Service parameter processing method, device, equipment, medium and program product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination