Method for generating data from disordered excel based on Java
By dynamically obtaining and matching fields and object attributes in excel tables based on Java's reflection principle, the complexity and efficiency of data import and management in the existing technology are solved, and the flexibility and efficiency of data import are achieved.
Patent Information
- Application Number
- CN202411556036.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-04
- Publication Date
- 2025-03-07
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When importing and managing large batches of complex data at the grassroots level, developers need to manually form templates and users manually extract and fill data, resulting in a large amount of work in data sorting and extraction, and the data does not meet the requirements and needs to be modified repeatedly.
Using Java-based methods, we use the reflection principle to dynamically obtain useful fields provided by users, extract valid fields from unordered excel tables, match fields with object attributes, process object attributes, and finally save the data to the database.
It reduces the repeated modification operations of users when importing data, improves the flexibility and efficiency of data import, reduces the cumbersomeness of data editing and processing, and improves the system's legibility and maintenance costs.
Smart Images

Figure CN119576443A_ABST
Abstract
Description
Technical Field
[0001] The invention discloses a method for generating data from disordered Excel based on Java, and relates to the technical field of data management. Background Art
[0002] With the rapid development of the domestic IT industry, multi-application platforms have emerged, resulting in large-scale and diversified data analysis and information storage. Especially for grassroots data governance, large amounts of data need to be imported into the platform for management and analysis.
[0003] For the current data import method, developers mainly form fixed templates for the required fields, and users manually extract valid data based on the templates and fill the data into the Excel template. The background reads the data based on the data provided by the user and judges the validity of the data. If the data does not meet the requirements, the user needs to modify it again until it meets the requirements, and then the data is stored in the database. Because the amount of data at the grassroots level is large and complex, the collation and extraction of data adds a lot of workload to grassroots management personnel. Summary of the invention
[0004] In view of the problems of the prior art, the present invention provides a method for generating data from an unordered Excel based on Java. Based on the Java reflection principle, the method dynamically obtains useful fields provided by a user, extracts valid fields from the unordered Excel table, matches and corresponds the fields with object attributes, then processes the attributes of the object, and finally saves the data to a database.
[0005] The specific scheme proposed by the present invention is:
[0006] The present invention provides a method for generating data from unordered Excel based on Java, comprising:
[0007] Step 1: Provide the object attributes to be imported to the front end through the background, and display the fields corresponding to the object attributes to the user in the form of a page through the front end. The user fills in the fields corresponding to the object attributes on the page according to the Excel to be imported.
[0008] Step 2: Obtain the corresponding fields filled in by the user through the background and generate a corresponding relationship with the object attributes and read the Excel file, where the file header is read and the header text and column number are stored in the map.
[0009] Step 3: Traverse the data in the map, match the imported Excel header with the data in the map, obtain the corresponding relationship between the object attributes and the number of Excel columns, assign the data in the Excel column to the object attributes, process and analyze the data in the object attributes, and store the data in batches into the database.
[0010] Furthermore, in step 1 of the method for generating data from an unordered Excel based on Java, when filling in the fields corresponding to the object attributes on the page, if the imported Excel lacks fields, corresponding fields are added to the table to complete the filling of the fields corresponding to the object attributes.
[0011] Furthermore, in step 2 of the method for generating data from an unordered Excel file based on Java, the header text and the number of columns are stored in a map, including storing the header text and the number of columns in the form of key and value.
[0012] Furthermore, in step 3 of the method for generating data from unordered Excel based on Java, the data in the object attributes is processed and analyzed, including: analyzing whether the data meets the storage requirements, if the data meets the requirements, importing it into the database, if not, returning to prompt the user to improve the data.
[0013] The present invention also provides a device for generating data from disordered Excel based on Java, comprising a background management module and a front-end management module.
[0014] The backend management module provides the object attributes to be imported to the frontend management module. The frontend management module displays the fields corresponding to the object attributes to the user in the form of a page. The user fills in the fields corresponding to the object attributes on the page according to the Excel to be imported.
[0015] The background management module obtains the corresponding fields filled in by the user and generates a corresponding relationship with the object attributes and reads the Excel file, where it reads the file header and stores the header text and column number in the map.
[0016] The front-end management module traverses the data in the map, matches the imported Excel header with the data in the map, obtains the corresponding relationship between the object attributes and the number of Excel columns, assigns the data in the Excel columns to the object attributes, processes and analyzes the data in the object attributes, and stores the data in batches into the database.
[0017] Furthermore, the device for generating data from unordered Excel based on Java, when filling in the fields corresponding to the object attributes on the page, if the Excel imported by the front-end management module lacks fields, then the corresponding fields are added to the table to complete the filling of the fields corresponding to the object attributes.
[0018] Furthermore, the background management module of the device for generating data from unordered Excel based on Java stores the header text and the number of columns in a map, including storing the header text and the number of columns in the form of key and value.
[0019] Furthermore, the background management module of the device for generating data from disordered Excel based on Java processes and analyzes the data in the object attributes, including: analyzing whether the data meets the storage requirements, if the data meets the requirements, importing it into the database, if not, returning to prompt the user to improve the data.
[0020] The benefits of the present invention are:
[0021] This method is directly oriented to user use, reducing the need for project users to repeatedly modify imported information during use, and flexibly imports tables to directly respond to changes in user needs.
[0022] This method is based on objects and reflection mechanisms, and can directly handle the import of different classes and different situations, greatly reducing the repetitive work in the business processing process.
[0023] This method is based on flexible data reading implemented by objects and reflection mechanisms, and can achieve accurate copying of unordered fields to objects. It can effectively avoid repeated editing of large amounts of data in Excel and avoid tedious data editing and processing processes.
[0024] The design structure of the object library of this method increases the readability of the project background system code, reduces the difficulty of system development, and greatly reduces the cost of communication and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a schematic flow chart of the method of the present invention.
[0026] Figure 2 This is a diagram of the Excel interface that needs to be imported.
[0027] Figure 3 It is a schematic diagram of the front-end filling page. DETAILED DESCRIPTION
[0028] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0029] Example 1
[0030] The present invention provides a method for generating data from unordered Excel based on Java, comprising:
[0031] Step 1: Provide the object attributes to be imported to the front end through the background, and display the fields corresponding to the object attributes to the user in the form of a page through the front end. The user fills in the fields corresponding to the object attributes on the page according to the Excel to be imported.
[0032] When filling in the fields corresponding to the object attributes on the page, if the imported Excel is missing fields, add the corresponding fields to the table to complete the filling of the fields corresponding to the object attributes.
[0033] For example, taking the import of the Java object properties of student as an example, the reference code is as follows:
[0034]
[0035] The Excel spreadsheet that needs to be imported can be referenced Figure 2 .
[0036] Later, the background can obtain the data submitted by the user and the corresponding relationship between the object generation "username" -> "name", "age" -> "age", "sex" -> "gender" and so on.
[0037] Step 2: Obtain the corresponding fields filled in by the user through the background and generate the corresponding relationship with the object attributes and read the Excel file, in which the file header is read and the header text and column number are stored in the map in the form of key and value.
[0038] Step 3: Traverse the data in the map, match the imported Excel header with the data in the map, and obtain the corresponding relationship between the object attributes and the number of Excel columns. For example, "userName" corresponds to the second example, "age" corresponds to the third column, and classMate corresponds to the seventh column.
[0039] Assign the data in the Excel column to the object attributes, process and analyze the data in the object attributes, including analyzing whether the data meets the storage requirements. If the data meets the requirements, it will be imported into the database. If not, it will be returned to prompt the user to improve the data. The improved data that meets the requirements will be stored in batches in the database.
[0040] Example 2
[0041] The present invention also provides a device for generating data from disordered Excel based on Java, comprising a background management module and a front-end management module.
[0042] The backend management module provides the object attributes to be imported to the frontend management module. The frontend management module displays the fields corresponding to the object attributes to the user in the form of a page. The user fills in the fields corresponding to the object attributes on the page according to the Excel to be imported.
[0043] The background management module obtains the corresponding fields filled in by the user and generates a corresponding relationship with the object attributes and reads the Excel file, where it reads the file header and stores the header text and column number in the map.
[0044] The front-end management module traverses the data in the map, matches the imported Excel header with the data in the map, obtains the corresponding relationship between the object attributes and the number of Excel columns, assigns the data in the Excel columns to the object attributes, processes and analyzes the data in the object attributes, and stores the data in batches into the database.
[0045] As the information interaction and execution process between the modules in the above-mentioned device are based on the same concept as the embodiment of the method of the present invention, the specific contents can be found in the description of the embodiment of the method of the present invention and will not be repeated here.
[0046] Likewise, the device of the present invention is directly oriented to user use, which reduces the need for project users to repeatedly modify imported information during use, and allows for flexible import of tables to directly respond to changes in user needs.
[0047] This device is based on objects and reflection mechanisms, and can directly handle the import of different classes and different situations, greatly reducing the repetitive work in the business processing process.
[0048] This device realizes flexible data reading based on objects and reflection mechanisms, and achieves accurate copying of unordered fields to objects, which can effectively avoid repeated editing of large amounts of data in Excel and avoid tedious data editing and processing processes.
[0049] The design structure of the device object library increases the readability of the project background system code, reduces the difficulty of system development, and greatly reduces the cost of communication and maintenance.
[0050] It should be noted that not all steps and modules in the above-mentioned processes and device structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.
[0051] The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or changes made by those skilled in the art based on the present invention are within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.
Claims
1. A method for generating data from unordered Excel based on Java, characterized by include: Step 1: Provide the object attributes to be imported to the front end through the background, and display the fields corresponding to the object attributes to the user in the form of a page through the front end. The user fills in the fields corresponding to the object attributes on the page according to the Excel to be imported. Step 2: Obtain the corresponding fields filled in by the user through the background and generate a corresponding relationship with the object attributes and read the Excel file, where the file header is read and the header text and column number are stored in the map. Step 3: Traverse the data in the map, match the imported Excel header with the data in the map, obtain the corresponding relationship between the object attributes and the number of Excel columns, assign the data in the Excel column to the object attributes, process and analyze the data in the object attributes, and store the data in batches into the database.
2. According to claim 1, a method for generating data from unordered Excel based on Java is characterized in that when filling in the fields corresponding to the object attributes on the page in step 1, if the imported Excel lacks fields, the corresponding fields are added to the table to complete the filling of the fields corresponding to the object attributes.
3. A method for generating data from an unordered Excel file based on Java according to claim 1, characterized in that In step 2, the header text and the number of columns are stored in the map, including storing the header text and the number of columns in the form of key and value.
4. A method for generating data from an unordered Excel file based on Java according to claim 1, characterized in that In step 3, the data in the object attributes are processed and analyzed, including: analyzing whether the data meets the storage requirements, if the data meets the requirements, it is imported into the database, if not, it is returned to prompt the user to complete the data.
5. A device for generating data from unordered Excel based on Java, characterized in that Including background management module and front-end management module, The backend management module provides the object attributes to be imported to the frontend management module. The frontend management module displays the fields corresponding to the object attributes to the user in the form of a page. The user fills in the fields corresponding to the object attributes on the page according to the Excel to be imported. The background management module obtains the corresponding fields filled in by the user and generates a corresponding relationship with the object attributes and reads the Excel file, where it reads the file header and stores the header text and column number in the map. The front-end management module traverses the data in the map, matches the imported Excel header with the data in the map, obtains the corresponding relationship between the object attributes and the number of Excel columns, assigns the data in the Excel columns to the object attributes, processes and analyzes the data in the object attributes, and stores the data in batches into the database.
6. The device for generating data from unordered Excel based on Java according to claim 5, characterized in that When filling in the fields corresponding to the object attributes on the page, if the Excel imported by the front-end management module lacks fields, add the corresponding fields to the table to complete the filling of the fields corresponding to the object attributes.
7. The device for generating data from disordered Excel based on Java according to claim 5, characterized in that the backend The management module stores the header text and the number of columns in a map, including storing the header text and the number of columns in the form of key and value.
8. The device for generating data from disordered Excel based on Java according to claim 5, characterized in that the backend The management module processes and analyzes the data in the object attributes, including: analyzing whether the data meets the storage requirements. If the data meets the requirements, it is imported into the database. If it does not meet the requirements, it is returned to prompt the user to complete the data.
Citation Information
Patent Citations
Method and device for importing data in EXCEL file to database
CN103020089A
Data calling method and device, electronic equipment and storage medium
CN113760894A
Method and system for universally importing excel
CN115081411A
Table data processing method and device, electronic equipment and storage medium
CN115130443A
Excel data import and export method and device
CN115828866A