Code generation method and device based on Excel file, electronic equipment and medium

By obtaining and processing Excel files to generate database tables and data writing code, the problem of time-consuming writing code in manual construction is solved, efficient data entry and query is achieved, and the degree of intelligence and development efficiency is improved.

CN119201061APending Publication Date: 2024-12-27TIANZHI ENG CONSULTING CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411239439.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-05
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

In the field of engineering construction, manually writing front-end code, back-end code and database library scripts takes a lot of time, is inefficient, and there is repeated code writing, which is low in intelligence.

Method used

By obtaining single-item type Excel file and acquisition table Excel file, traverse the collection items item by item, generate table construction statements based on the type of the target acquisition item, create database tables, and write data to the database table, automatically generate table construction statements and data Automatic classification writing.

Benefits of technology

It improves development efficiency, reduces the need for manual code writing, and realizes high-intelligent data entry and query functions, saving time and cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201061A_ABST
    Figure CN119201061A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method and device based on an Excel file, electronic equipment and a medium, and the method comprises the steps: obtaining a single-item type Excel file and a collection table Excel file, and recording a collection item corresponding to a single-item type by the single-item type Excel file; all collection items in the single-item type Excel file are traversed item by item, and a current traversed target collection item is determined; based on the type of the target collection item, calling a Type subclass corresponding to the type of the target collection item to generate a table establishment statement corresponding to the target collection item; creating a database table for storing type related data of the target collection item in the collection table Excel file based on the table creation statement; and reading data related to the type of the target collection item in the collection table Excel file, and writing the read data into the database table based on a pre-packaged database table operation statement. By adopting the method, automatic classified writing of the data is realized, the intelligent degree is high, and the development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a code generation method, device, electronic device and medium based on Excel files. Background Art

[0002] In the field of engineering construction, there are many individual categories in a project. For example, houses, roads, bridges, etc. can all be considered a building. Each building can have multiple categories, and each category has many attributes, so a lot of data will be generated. These data usually need to be written into a database table for subsequent query use.

[0003] However, if the front-end code, back-end code and database creation script are manually written to enter the engineering data into the database table and implement the query function, it will take a lot of time and cost, be inefficient, and there will be repeated code writing, and the degree of intelligence is low. Summary of the invention

[0004] In response to the above technical problems, the present disclosure provides a code generation method, device, electronic device and medium based on Excel files.

[0005] In a first aspect, the present disclosure provides a code generation method based on an Excel file, the method comprising:

[0006] Obtain a single item type Excel file and a collection table Excel file, wherein the single item type Excel file records the collection items corresponding to the single item type;

[0007] Traverse each collection item in the single-item type Excel file one by one to determine the target collection item currently being traversed;

[0008] Based on the type of the target collection item, calling the Type subclass corresponding to the type of the target collection item to generate a table creation statement corresponding to the type of the target collection item;

[0009] Creating a database table for storing type-related data of the target collection items in the collection table Excel file based on the table creation statement;

[0010] The data related to the type of the target acquisition item in the acquisition table Excel file is read, and the read data is written into the database table based on the pre-packaged database table operation statement.

[0011] In a second aspect, the present disclosure provides a code generation device based on an Excel file, the device comprising:

[0012] A file acquisition module, used to acquire a single item type Excel file and a collection table Excel file, wherein the single item type Excel file records the collection items corresponding to the single item type;

[0013] A collection item reading module is used to traverse each collection item in the single item type Excel file one by one to determine the target collection item currently traversed;

[0014] A statement generation module, used for calling a Type subclass corresponding to the type of the target collection item to generate a table creation statement corresponding to the type of the target collection item based on the type of the target collection item;

[0015] A table creation module, used for creating a database table for storing type-related data of the target collection items in the collection table Excel file based on the table creation statement;

[0016] The data operation module is used to read the data related to the type of the target acquisition item in the acquisition table Excel file, and write the read data into the database table based on the pre-packaged database table operation statement.

[0017] In a third aspect, the present disclosure provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the code generation method based on the Excel file as described in the first aspect is implemented.

[0018] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the code generation method based on an Excel file as described in the first aspect is implemented.

[0019] In a fifth aspect, the present disclosure provides a computer program product, which is used to implement the code generation method based on Excel file as described in the first aspect.

[0020] Compared with the prior art, the technical solution provided by the present invention has at least the following advantages:

[0021] In the scheme disclosed in the present invention, a single-item type Excel file and a collection table Excel file are obtained, and the single-item type Excel file records the collection items corresponding to the single-item type; each collection item in the single-item type Excel file is traversed item by item, and the target collection item currently traversed is determined, and based on the type of the target collection item, the Type subclass corresponding to the type of the target collection item is called to generate a table creation statement corresponding to the type of the target collection item, and then a database table for storing type-related data of the target collection item in the collection table Excel file is created based on the table creation statement, and the data related to the type of the target collection item in the collection table Excel file is read, and the read data is written into the database table based on the pre-packaged database table operation statement. The scheme disclosed in the present invention realizes automatic generation of table creation statements and establishment of database tables, and stores the data related to the type of the collection item read into the database table of the corresponding type, realizes automatic classification and writing of data, has a high degree of intelligence, and does not require manual code writing to write data, saves time and cost, and improves development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 A flowchart of a code generation method based on an Excel file provided in one embodiment of the present disclosure;

[0023] Figure 2 A schematic diagram showing a Type class and its seven subclasses of an exemplary embodiment of the present disclosure is shown;

[0024] Figure 3 A schematic diagram of an implementation architecture of a code generation method based on an Excel file according to an exemplary embodiment of the present disclosure is shown;

[0025] Figure 4 A schematic diagram of the structure of a code generation device based on an Excel file provided in one embodiment of the present disclosure;

[0026] Figure 5 An internal structure diagram of an electronic device provided by an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solution and advantages of the present disclosure more clear, the present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present disclosure and are not used to limit the present disclosure.

[0028] Figure 1A flow chart of a code generation method based on an Excel file provided in an embodiment of the present disclosure is provided. The method can be executed by a code generation device based on an Excel file provided in an embodiment of the present disclosure. The code generation device based on an Excel file can be implemented by software and / or hardware and can be integrated in an electronic device, which can be a computer or other device.

[0029] like Figure 1 As shown, the code generation method based on the Excel file may include the following steps:

[0030] Step 101, obtaining a single item type Excel file and a collection table Excel file, wherein the single item type Excel file records the collection items corresponding to the single item type.

[0031] Among them, the Excel file is organized by the business department. There are three types of Excel files: one is a single-item type Excel file, which is a tree structure for easy query. The single-item type Excel file records the collection items corresponding to the single-item type; one is the collection table Excel file corresponding to each single-item type, which is used to record the collection data corresponding to the single-item type; and one is a query file, which is used to record the query conditions. Each Excel file has a certain format.

[0032] It is understandable that a single item can have multiple types. For example, if a single item is a building, the corresponding single item types can include multiple types such as houses, roads, bridges, etc. Houses are a single item type, and a single item type can have multiple collection items. For example, for a house, the corresponding collection items can include house area, house location, house orientation, whether there are windows, window size, etc. For each collection item, the attributes of the collection item may include but are not limited to name, description, classification information, whether it is required, type, options (single choice and multiple choice), value range (maximum value, minimum value); the types of collection items may include but are not limited to single choice, multiple choice, integer, long integer, decimal, date, and string.

[0033] As an example, in the embodiment of the present disclosure, when obtaining a single item type Excel file and a collection table Excel file, the single item type Excel file organized by the business department and the Excel file of the collection table corresponding to the single item type can be imported through the code generation entry, so that the electronic device can obtain the imported single item type Excel file and collection table Excel file. In addition, the imported Excel file can also be displayed on the page and edited again to facilitate updating and verifying the data.

[0034] As another example, in the embodiment of the present disclosure, when obtaining a single item type Excel file and a collection table Excel file, the file data of different file types input by the user through the operation page can be obtained, and the Excel file corresponding to the file type can be generated based on the file data. It can be understood that different file types refer to one or more of the single item type and the collection table, and the file data corresponding to different file types are different. For example, the file data corresponding to the single item type is all the collection items contained in the single item type, and the file data corresponding to the collection table is the engineering data of the collected single item type. Accordingly, the Excel file generated based on the file data corresponding to the single item type is the single item type Excel file, and the Excel file generated based on the file data corresponding to the collection table is the collection table Excel file.

[0035] As another example, a single item type Excel file and a collection table Excel file can be obtained by combining code generation entry import and operation page input. For example, the collection table Excel file can be obtained by a user importing the collection table Excel file through the code generation entry, and the single item type Excel file can be obtained by generating a single item type Excel file based on the collection items of the single item type input by the user through the operation page.

[0036] In the embodiments of the present disclosure, by providing a code generation entry to import Excel file functions and an operation page to input data to generate Excel file functions, a flexible file entry method is provided for users, and users can flexibly choose according to their needs, which is highly practical.

[0037] Step 102, traverse each collection item in the single-item type Excel file one by one to determine the target collection item currently traversed.

[0038] In the disclosed embodiment, the electronic device may traverse each collection item in the single-item type Excel file one by one, and determine the target collection item currently being traversed.

[0039] It can be understood that a program for implementing the present solution is deployed in the electronic device, and the program reads the obtained single-item type Excel file and can find each collection item corresponding to the single-item type.

[0040] Step 103: Based on the type of the target collection item, call the Type subclass corresponding to the type of the target collection item to generate a table creation statement corresponding to the type of the target collection item.

[0041] As mentioned above, the types of collection items can be divided into seven types: single choice, multiple choice, integer, long integer, decimal, date, and string, and each collection item corresponds to a type. In the embodiment of the present disclosure, for the target collection item currently traversed, the type of the target collection item can be determined, and then according to the type of the target collection item, the Type subclass corresponding to the type of the target collection item can be called to generate a table creation statement corresponding to the type of the target collection item.

[0042] In this embodiment, the method of generating table creation statements and JAVA Bean class codes is encapsulated in the Type class and its seven subclasses. Among them, the Type class implements most of the code logic, and the different parts of each type are implemented by the subclasses. For example, Figure 2 A schematic diagram of the Type class and its seven subclasses of an exemplary embodiment of the present disclosure is shown. Figure 2 As shown, the Type class implements most of the code logic, including the ImportSheet function, ImportSheet$Row function, ImportSheet$Kind function, and ImportSheet$Key function; the Type class also implements seven subclasses, one subclass corresponding to a type of collection item, including the subclass DecimalType corresponding to the decimal type of the collection item, the subclass IntType corresponding to the integer type of the collection item, the subclass LongType corresponding to the long integer type of the collection item, the subclass DataType corresponding to the date type of the collection item, the subclass StringType corresponding to the string type of the collection item, the subclass ShortType corresponding to the single-select type of the collection item, and the subclass ShortArrayType corresponding to the multiple-select type of the collection item. Process each collection item one by one, through the pre-packaged Type class and its subclasses, for any type of collection item, you can select the corresponding Type subclass to generate the complete table creation statement of the SQL database table and the JAVA Bean class code.

[0043] It can be understood that in the embodiments of the present disclosure, when generating a table creation statement corresponding to the type of the target collection item, it is also possible to first detect whether a database table corresponding to the type has been established. If it has been established, it is possible not to generate a table creation statement corresponding to the type of the target collection item, thereby no longer generating a database table for storing related data of this type, and directly traversing the next collection item to avoid establishing a duplicate database table corresponding to the collection item type.

[0044] Step 104: Create a database table for storing type-related data of the target collection items in the collection table Excel file based on the table creation statement.

[0045] In the embodiment of the present disclosure, after generating a table creation statement corresponding to the type of the target collection item, a database table can be created based on the table creation statement, and the database table is used to store data related to the type of the target collection item in the collection table Excel file. For example, assuming that the type of the target collection item is a string, the database table corresponding to the string type is created to store all data of the collection item type in the collection table Excel file.

[0046] Step 105 , reading data related to the type of the target collection item in the collection table Excel file, and writing the read data into the database table based on a pre-packaged database table operation statement.

[0047] In the disclosed embodiment, after creating a database table corresponding to the type of the target collection item, all data related to the type of the target collection item in the collection table Excel file can be read, and based on the pre-packaged database table operation statement, the read data can be written into the database table, thereby realizing that all data of the same collection item type can be written into the same database table.

[0048] For the operation of database tables, a unified Repository class is pre-written, which encapsulates methods such as get, save, update, and delete. When the program starts, it automatically creates a database connection, reads the definition of each table, generates SQL scripts corresponding to these methods, and obtains database table operation statements for reading, writing, updating, deleting, and other operations on the database table.

[0049] The code generation method based on Excel file of the embodiment of the present disclosure obtains a single-item type Excel file and a collection table Excel file, wherein the single-item type Excel file records the collection items corresponding to the single-item type; each collection item in the single-item type Excel file is traversed item by item, the target collection item currently traversed is determined, and based on the type of the target collection item, the Type subclass corresponding to the type of the target collection item is called to generate a table creation statement corresponding to the type of the target collection item, and then a database table for storing type-related data of the target collection item in the collection table Excel file is created based on the table creation statement, and the data related to the type of the target collection item in the collection table Excel file is read, and the read data is written into the database table based on the pre-packaged database table operation statement. The scheme of the present disclosure is adopted to realize automatic generation of table creation statements and establishment of database tables, and store the data related to the type of the collection item read into the database table of the corresponding type, realize automatic classification and writing of data, with a high degree of intelligence, and no need to manually write code to write data, saving time and cost, and improving development efficiency.

[0050] The disclosed solution also supports a data query function, and can generate VUE scripts and JAVA request Bean class codes in advance according to the query condition Excel file, and then deploy and generate a query request page, which can be presented in the form of a browser page. When a user needs to query data, the target query condition can be entered through the query request page. After the electronic device receives the target query condition entered by the user, it can query the database table based on the target query condition to obtain the target data that meets the query condition, and then display the target data in the query request page. As a result, the user can query the required data without manually writing a database table query statement, which improves the efficiency of data query and the convenience of querying data.

[0051] Exemplarily, the user enters the target query condition in the query request page, and after the input is completed, clicks the query button provided in the page, and then the electronic device generates a corresponding HTTP query request in response to the click operation of the query button, and then calls the server API interface based on the HTTP query request to query data, realizes the function of querying the relevant data that meets the target query condition from the database table, and returns the query result to be presented in the query request page, so that the user can see the queried data. For example, if the query condition entered by the user is data of house area between 70 square meters and 120 square meters, all data of house area between 70 square meters and 120 square meters recorded in the database table are returned to the user.

[0052] In an optional implementation of the present disclosure, the query request page can be deployed by a VUE script and a JAVA request Bean class code generated in advance according to a query condition Excel file generated by a business department. Specifically, based on the type of each collection item, the Type subclass corresponding to the type of each collection item can be called to generate the JAVA Bean class code, and the query condition Excel file can be obtained, and then each query condition in the query condition Excel file can be read item by item, and the corresponding VUE script and JAVA request Bean class code can be generated based on the JAVA Bean class code, and then the query request page can be generated based on the VUE script and the JAVA request Bean class code.

[0053] Among them, the collection items can be provided by a single-item type Excel file generated by the business department, and the query condition Excel file is also generated by the business department and provided to developers for use. Developers can import the single-item type Excel file and the query condition Excel file into the code generation entry, and generate corresponding JAVA Bean class code for each type of collection item in the single-item type Excel file. Then, based on the generated JAVA Bean class code, process each query condition one by one, generate corresponding JAVA request Bean class code and VUE script, and then deploy the query request page for users to implement data query operations.

[0054] In this embodiment, the method of generating JAVA Bean class code is also encapsulated in the Type class and its seven subclasses. For each collection item, the corresponding Type subclass can be obtained according to its type to generate the JAVA Bean class code.

[0055] In this embodiment, by generating JAVA request Bean class code and VUE script, the back-end JAVA code and front-end VUE code are automatically generated. The back-end JAVA code can implement entity classes, dictionary classes, query request parameter classes, etc., and the front-end VUE code can implement editing pages and query request pages, which greatly reduces the workload of writing code. Therefore, only a few codes need to be written to realize the related functions of single information collection and query, and the degree of intelligence and efficiency are significantly improved.

[0056] Further, in an optional implementation of the present disclosure, when generating a VUE script and a JAVA request Bean class code, the attribute type and data table name of the query condition currently read can be obtained, and according to the attribute type, the target JAVA Bean class code corresponding to the attribute type is determined from the JAVA Bean class code, and then based on the target JAVA Bean class code and the data table name, a VUE script and a JAVA request Bean class code for querying the data in the database table corresponding to the data table name that conforms to the attribute type are generated. Among them, the query conditions include but are not limited to the following: a multiple-select drop-down box, a date range, and a numerical range. The multiple-select drop-down box provides multiple options for query, and the option selected by the user is the query condition entered by the user. It can be understood that for different single item types, the units of the corresponding numerical ranges are different. For example, if the single item type is a house, the unit of the numerical range is square meters, and if the single item type is a road, the unit of the numerical range is meters, kilometers / kilometers, etc.

[0057] In this embodiment, when processing the query condition Excel file, each row is traversed, where one row is a query condition, and the corresponding JAVA Bean class attribute is found according to the attribute type and name of the query condition currently traversed, the query condition type is judged, and the corresponding VUE script and JAVA request Bean class code are generated. For the VUE editing script, not only each FORM item is generated, but also all the verification rules are implemented-non-empty verification and value range verification. As mentioned above, the types of collection items can include single choice, multiple choice, integer, long integer, decimal, date, and string. In an optional implementation of the present disclosure, in the generated JAVA Bean class code, corresponding annotations can be added to the target attributes of the target collection item, and the target attribute is at least one of the name, whether it is required, and the value range.

[0058] In this embodiment, by generating corresponding annotations on the field in the generated JAVA code regarding whether it is required, the Chinese name, and the value range, convenience is provided for implementing the verification operation.

[0059] Figure 3 A schematic diagram of an implementation architecture of a code generation method based on an Excel file according to an exemplary embodiment of the present disclosure is shown. Figure 3 As shown, the architecture includes a code generation entry Creator and an entry ImportProc for importing collected data, wherein Creator is open to external calls to generate VUE scripts and JAVA classes respectively, for example, Figure 3 As shown, Creator can generate ProcContext class for dictionary-related functions, QueryProc class for query functions, AProc class for building construction, BProc class for municipal administration, and EProc class for civil aviation. AProc class, BProc class and EProc class are subclasses of the base class BaseProc; ImportProc reuses part of the code of the class in Creator, parses the Excel collection file uploaded by the user, and assembles it into a JAVA Bean class. After the data verification is successful, it can be saved into the database.

[0060] In order to implement the above embodiments, the present disclosure further provides a code generation device based on an Excel file. The code generation device based on an Excel file can be implemented by software and / or hardware and can be integrated in an electronic device.

[0061] Figure 4 A schematic diagram of a code generation device based on an Excel file provided in an embodiment of the present disclosure is shown in FIG. Figure 4As shown, the Excel file-based code generation device 20 may include: a file acquisition module 210 , a collection item reading module 220 , a statement generation module 230 , a table creation module 240 and a data operation module 250 .

[0062] The file acquisition module 210 is used to acquire a single item type Excel file and a collection table Excel file, wherein the single item type Excel file records the collection items corresponding to the single item type;

[0063] The collection item reading module 220 is used to traverse each collection item in the single item type Excel file one by one to determine the target collection item currently traversed;

[0064] A statement generation module 230 is used to call the Type subclass corresponding to the type of the target collection item to generate a table creation statement corresponding to the type of the target collection item based on the type of the target collection item;

[0065] A table creation module 240, configured to create a database table for storing type-related data of the target collection item in the collection table Excel file based on the table creation statement;

[0066] The data operation module 250 is used to read the data related to the type of the target acquisition item in the acquisition table Excel file, and write the read data into the database table based on the pre-packaged database table operation statement.

[0067] In one embodiment, the Excel file-based code generation device 20 further includes:

[0068] A condition receiving module, used to receive a target query condition input by a user through a query request page;

[0069] A data query module, used to query a database table based on the target query condition to obtain target data that meets the query condition;

[0070] A result feedback module is used to display the target data in the query request page.

[0071] In one embodiment, the Excel file-based code generation device 20 further includes:

[0072] A first generating module, configured to generate a JAVABean class code by calling a Type subclass corresponding to the type of the target collection item based on the type of the target collection item;

[0073] The query condition acquisition module is used to obtain the query condition Excel file;

[0074] The second generating module is used to read each query condition in the query condition Excel file item by item, and generate a corresponding VUE script and JAVA request Bean class code based on the JAVA Bean class code;

[0075] The third generating module is used to generate a query request page based on the VUE script and the JAVA request Bean class code.

[0076] In one embodiment, the second generating module is further used for:

[0077] Get the attribute type and data table name of the query condition currently being read;

[0078] According to the attribute type, determining a target JAVABean class code corresponding to the attribute type from the JAVABean class code;

[0079] Based on the target JAVA Bean class code and the data table name, a VUE script and a JAVA request Bean class code are generated for querying the data in the database table corresponding to the data table name that conforms to the attribute type.

[0080] In one embodiment, the query conditions include the following:

[0081] Multiple selection drop-down box;

[0082] Date range;

[0083] Numeric range.

[0084] In one embodiment, the attributes of the collection item include: name, description, classification information, whether it is required, type, options, and value range;

[0085] The types of the collection items include: single choice, multiple choice, integer, long integer, decimal, date, and character string.

[0086] In one embodiment, the Excel file-based code generation device 20 further includes:

[0087] An annotation module, used for adding corresponding annotations to the target attributes of the target collection item in the generated JAVA Bean class code;

[0088] The target attribute is at least one of a name, whether it is required, and a value range.

[0089] In one embodiment, the single item type Excel file and the collection table Excel file are obtained in the following manner:

[0090] Get the single item type Excel file and collection table Excel file imported by the user through the code generation portal;

[0091] and / or

[0092] The file data of different file types input by the user through the operation page is obtained, and an Excel file corresponding to the file type is generated based on the file data, wherein the different file types are single item types or collection tables.

[0093] The code generation device based on Excel file provided by the embodiment of the present disclosure obtains a single-item type Excel file and a collection table Excel file, wherein the single-item type Excel file records the collection items corresponding to the single-item type; traverses each collection item in the single-item type Excel file item by item, determines the target collection item currently traversed, and based on the type of the target collection item, calls the Type subclass corresponding to the type of the target collection item to generate a table creation statement corresponding to the type of the target collection item, and then creates a database table for storing type-related data of the target collection item in the collection table Excel file based on the table creation statement, reads the data related to the type of the target collection item in the collection table Excel file, and writes the read data into the database table based on the pre-packaged database table operation statement. The scheme of the present disclosure is adopted to realize automatic generation of table creation statements and establishment of database tables, and store the data related to the type of the collection item read into the database table of the corresponding type, realize automatic classification and writing of data, with a high degree of intelligence, and no need to manually write code to write data, saving time and cost, and improving development efficiency.

[0094] For the specific definition of the code generation device based on Excel file, please refer to the definition of the code generation method based on Excel file in the above text, which will not be repeated here. Each module in the above-mentioned code generation device based on Excel file can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0095] In one embodiment, an electronic device is provided, the internal structure diagram of the electronic device can be as follows: Figure 5As shown. The electronic device includes a processor, a memory and a network interface connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the electronic device is used to store database tables. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the code generation method based on the Excel file described in any of the above embodiments is implemented.

[0096] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the scheme of the present disclosure, and does not constitute a limitation on the electronic device to which the scheme of the present disclosure is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0097] In one embodiment, the code generation device based on Excel file provided by the present disclosure can be implemented in the form of a computer program, which can be used in Figure 5 The memory of the electronic device may store various program modules constituting the code generation device based on the Excel file, for example, Figure 4 The file acquisition module, collection item reading module, statement generation module, table building module and data operation module shown in the figure. The computer program composed of each program module enables the processor to execute the steps of the code generation method based on Excel file in each embodiment of the present disclosure described in this specification.

[0098] In one embodiment, the present disclosure provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the code generation method based on the Excel file as described in any embodiment of the present disclosure is implemented.

[0099] In one embodiment, the present disclosure further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the code generation method based on an Excel file as described in any embodiment of the present disclosure.

[0100] In one embodiment, the present disclosure further provides a computer program product, which is used to implement the code generation method based on Excel file as described in any embodiment of the present disclosure.

[0101] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided by the present disclosure can include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in various forms, such as static random access memory (SRAM) and dynamic random access memory (DRAM).

[0102] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0103] The above-mentioned embodiments only express several implementation methods of the present disclosure, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present disclosure, and these all belong to the protection scope of the present disclosure. Therefore, the protection scope of the patent of the present disclosure shall be subject to the attached claims.

Claims

1. A code generation method based on Excel file, characterized in that: include: Obtain a single item type Excel file and a collection table Excel file, wherein the single item type Excel file records the collection items corresponding to the single item type; Traverse each collection item in the single-item type Excel file one by one to determine the target collection item currently being traversed; Based on the type of the target collection item, calling the Type subclass corresponding to the type of the target collection item to generate a table creation statement corresponding to the type of the target collection item; Creating a database table for storing type-related data of the target collection items in the collection table Excel file based on the table creation statement; The data related to the type of the target acquisition item in the acquisition table Excel file is read, and the read data is written into the database table based on the pre-packaged database table operation statement.

2. The method according to claim 1, characterized in that The method further comprises: Receiving target query conditions input by the user through the query request page; Querying a database table based on the target query condition to obtain target data that meets the query condition; The target data is displayed on the query request page.

3. The method according to claim 2, characterized in that The query request page is generated in the following manner: Based on the type of each collection item, call the Type subclass corresponding to the type of each collection item to generate JAVABean class code; Get the query condition Excel file; Read each query condition in the query condition Excel file item by item, and generate corresponding VUE script and JAVA request Bean class code based on the JAVA Bean class code; Generate a query request page based on the VUE script and the JAVA request Bean class code.

4. The method according to claim 3, characterized in that The step of reading each query condition in the query condition Excel file item by item, and generating a corresponding VUE script and a JAVA request Bean class code based on the JAVA Bean class code, includes: Get the attribute type and data table name of the query condition currently being read; According to the attribute type, determining a target JAVABean class code corresponding to the attribute type from the JAVABean class code; Based on the target JAVA Bean class code and the data table name, a VUE script and a JAVA request Bean class code are generated for querying the data in the database table corresponding to the data table name that conforms to the attribute type.

5. The method according to claim 3, characterized in that: The attributes of the collection item include: name, description, classification information, whether it is required, type, options, and value range; The types of the collection items include: single choice, multiple choice, integer, long integer, decimal, date, and character string.

6. The method according to claim 5, characterized in that The method further comprises: In the generated JAVA Bean class code, add corresponding annotations to the target attributes of the target collection item; The target attribute is at least one of a name, whether it is required, and a value range.

7. The method according to any one of claims 1 to 6, characterized in that: The single item type Excel file and the collection table Excel file are obtained in the following manner: Obtain the single item type Excel file and the collection table Excel file imported by the user through the code generation entry; and / or The file data of different file types input by the user through the operation page is obtained, and an Excel file corresponding to the file type is generated based on the file data, wherein the different file types are single item types or collection tables.

8. A code generation device based on Excel file, characterized in that: include: A file acquisition module, used to acquire a single item type Excel file and a collection table Excel file, wherein the single item type Excel file records the collection items corresponding to the single item type; A collection item reading module is used to traverse each collection item in the single item type Excel file one by one to determine the target collection item currently traversed; A statement generation module, used for calling a Type subclass corresponding to the type of the target collection item to generate a table creation statement corresponding to the type of the target collection item based on the type of the target collection item; A table creation module, used for creating a database table for storing type-related data of the target collection items in the collection table Excel file based on the table creation statement; The data operation module is used to read the data related to the type of the target acquisition item in the acquisition table Excel file, and write the read data into the database table based on the pre-packaged database table operation statement.

9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the code generation method based on an Excel file as described in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the code generation method based on an Excel file as described in any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Wind turbine generator control program generation method and device based on Excel file

    CN121429554A