Data exporting method and device based on EasyExcel annotation and storage medium

By using predefined data export templates and annotation receiving objects, the problem of cumbersome annotation code when exporting complex data structures is solved, efficient and flexible data export is achieved, and development efficiency and accuracy of data export are improved.

CN120106037APending Publication Date: 2025-06-06GRG BANKING IT
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510173165.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-17
Publication Date
2025-06-06

AI Technical Summary

Technical Problem

When processing complex data structures, the prior art requires writing a large number of cumbersome annotation code, which is relatively inefficient. When the data structure changes, the annotation code needs to be modified a lot, further reducing development efficiency.

Method used

By obtaining a predefined data export template, the template defines the data export structure and generates a receiving object containing annotations based on the template. Developers only need to pay attention to the assembly and business logic of the data to export the data without writing a lot of redundant code.

Benefits of technology

It improves the efficiency of data export, reduces the workload of manual encoding, enhances the flexibility and accuracy of data export, and reduces the operating cost of complex template export.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120106037A_ABST
    Figure CN120106037A_ABST
Patent Text Reader

Abstract

The invention discloses a data exporting method and device based on EasyExcel annotations and a storage medium, and belongs to the technical field of computers. The method comprises the following steps: acquiring a data export template, wherein the data export template defines a data export structure; under the condition that the data export template meets a preset condition, generating a receiving object comprising the annotation according to the data export template; the receiving object comprises an object class bearing data, and the annotation is used for controlling the export behavior of the data; assembling the data to be exported into a receiving object; and exporting the to-be-exported data in the receiving object into the data exporting template based on the annotation. Through the predefined data export template, when the data export template meets the preset condition, the receiving object containing the annotation can be automatically generated, a developer only needs to pay attention to data assembly and business logic, data export can be achieved, a large number of tedious redundant codes do not need to be written, the workload of manual coding is reduced, and the data export efficiency is improved. And the data export efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of computer technology, and in particular, relates to a data export method, device and storage medium based on EasyExcel annotation. Background Art

[0002] In today's data-driven environment, importing data into Excel is a common and important task. As a widely used spreadsheet software, Excel's powerful data analysis and visualization capabilities make it the preferred tool for enterprises to analyze and report data.

[0003] In order to realize automatic import of data into Excel, the EasyExcel library provides a convenient solution. EasyExcel is a Java-based library that simplifies the process of mapping Java objects to Excel tables through annotations. Through annotations, EasyExcel can automatically recognize these annotations and generate corresponding Excel files. However, when the data structure is more complex, it may be necessary to write a lot of cumbersome annotation codes, which is inefficient. Summary of the invention

[0004] The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application proposes a data export method, device and storage medium based on EasyExcel annotation to improve the efficiency of data export.

[0005] In a first aspect, the present application provides a data export method based on EasyExcel annotation, comprising:

[0006] Obtaining a data export template, wherein the data export template defines an export structure of data;

[0007] When the data export template meets the preset conditions, a receiving object including annotations is generated according to the data export template; the receiving object includes an object class carrying data, and the annotations are used to control the export behavior of the data;

[0008] Assembling the data to be exported into the receiving object;

[0009] The data to be exported in the receiving object is exported to the data export template based on the annotation.

[0010] The data export method based on EasyExcel annotation provided in the embodiment of the present application obtains a data export template, and the data export template defines the export structure of the data; when the data export template meets the preset conditions, a receiving object including annotations is generated according to the data export template; the receiving object includes an object class that carries data, and the annotations are used to control the export behavior of the data; the data to be exported is assembled into the receiving object; based on the annotations, the data to be exported in the receiving object is exported to the data export template. The embodiment of the present application can clarify the export structure of the data through the predefined data export template. When the data export template meets the preset conditions, a receiving object including annotations will be automatically generated. Developers only need to focus on the assembly of the data and the business logic to realize the export of the data, without having to write a large amount of cumbersome redundant code, reducing the workload of manual coding and improving the efficiency of data export.

[0011] According to one embodiment of the present application, the method further includes:

[0012] When the data export template does not meet the preset conditions, a receiving object including annotations written by the user according to the data export template is obtained.

[0013] In this embodiment, when the preset data export template does not meet specific requirements, the user can write a receiving object containing annotations according to the actual data structure and business requirements, thereby improving the flexibility of data export.

[0014] According to one embodiment of the present application, generating a receiving object including annotations according to the data export template includes:

[0015] Analyze the structural information of the data export template; the structural information includes at least one of a column title, a table page, a merged row, and a calculated row in the data export template;

[0016] A receiving object including annotations is generated according to the structural information.

[0017] In this embodiment, through in-depth analysis of the data export template, key structural information such as column headers, table pages, merged rows and calculation rows in the template are identified, and a receiving object containing annotations is automatically generated based on this structural information. The annotations correspond to the structural features in the template, thereby realizing the mapping of data and Excel columns, simplifying the encoding process, reducing the operating cost of exporting complex templates, and further improving the efficiency of data export.

[0018] According to an embodiment of the present application, analyzing the structural information of the data export template includes:

[0019] Adding simulation data to the data export template;

[0020] The structural information of the data export template is obtained based on the simulation data analysis.

[0021] In this embodiment, by adding simulation data to the data export template and analyzing and acquiring the structural information of the template based on the simulation data, a real data processing scenario is simulated, thereby more intuitively understanding and identifying key structural elements such as column headers, table pages, merged rows, and calculation rows in the template, thereby improving the accuracy of structural information analysis.

[0022] According to one embodiment of the present application, assembling the to-be-exported data into the receiving object includes:

[0023] In response to a download instruction from a user, querying and obtaining the data to be exported from a database;

[0024] Assemble the data to be exported into the receiving object.

[0025] In this embodiment, by responding to the user's download instruction, querying the data to be exported from the database and assembling it into a predefined receiving object, the speed of data processing and the real-time response to the user are improved.

[0026] According to an embodiment of the present application, querying the to-be-exported data from the database in response to a download instruction from the user includes:

[0027] In response to a download instruction from a user, checking the authority of the user;

[0028] Determine the columns in the data export template for which the user has download permissions;

[0029] The data to be exported is obtained by querying from the database according to the columns for which the user has download authority.

[0030] In this embodiment, by introducing a mechanism of permission verification and permission management in the data export template, the columns in the data export template for which the user has download permissions are determined, so that the user can access the data within his or her permission range, and the exported data can be dynamically adjusted according to different users, which not only improves the targetedness of data export, but also improves the security of data export.

[0031] According to an embodiment of the present application, exporting the to-be-exported data in the received object to the data export template based on the annotation includes:

[0032] Splitting the data to be exported in the receiving object into multiple data blocks, and marking a starting writing position for each data block;

[0033] A corresponding thread is allocated to each data block, so that each thread writes each data block into the data export template according to the annotation and the starting writing position.

[0034] In this embodiment, by splitting the data to be exported into multiple data blocks and assigning a corresponding thread to each data block, each thread can independently write the data block into the data export template. Through this multi-threaded parallel writing operation, the overall writing time is reduced and the efficiency of data export is improved.

[0035] In a second aspect, the present application provides a data export device based on EasyExcel annotation, the device comprising:

[0036] An acquisition module, used to acquire a data export template, wherein the data export template defines an export structure of data;

[0037] A generating module, configured to generate a receiving object including annotations according to the data export template when the data export template meets preset conditions; the receiving object includes an object class carrying data, and the annotations are used to control the export behavior of the data;

[0038] An assembling module, used for assembling the data to be exported into the receiving object;

[0039] An export module is used to export the to-be-exported data in the receiving object into the data export template based on the annotation.

[0040] The data export device based on EasyExcel annotation provided in the embodiment of the present application obtains a data export template, and the data export template defines the export structure of data; when the data export template meets the preset conditions, a receiving object including annotations is generated according to the data export template; the receiving object includes an object class that carries data, and the annotations are used to control the export behavior of data; the data to be exported is assembled into the receiving object; based on the annotations, the data to be exported in the receiving object is exported to the data export template. The embodiment of the present application can clarify the export structure of data through the predefined data export template. When the data export template meets the preset conditions, a receiving object including annotations will be automatically generated. Developers only need to focus on the assembly of data and business logic to realize data export, without writing a large amount of cumbersome redundant code, reducing the workload of manual coding and improving the efficiency of data export.

[0041] In a third aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the data export method based on EasyExcel annotation as described in the first aspect above is implemented.

[0042] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the data export method based on EasyExcel annotation as described in the first aspect above is implemented.

[0043] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the data export method based on EasyExcel annotation as described in the first aspect above.

[0044] The above one or more technical solutions in the embodiments of the present application have at least one of the following technical effects:

[0045] The data export method based on EasyExcel annotation provided in the embodiment of the present application obtains a data export template, and the data export template defines the export structure of the data; when the data export template meets the preset conditions, a receiving object including annotations is generated according to the data export template; the receiving object includes an object class that carries data, and the annotations are used to control the export behavior of the data; the data to be exported is assembled into the receiving object; based on the annotations, the data to be exported in the receiving object is exported to the data export template. The embodiment of the present application can clarify the export structure of the data through the predefined data export template. When the data export template meets the preset conditions, a receiving object including annotations will be automatically generated. Developers only need to focus on the assembly of the data and the business logic to realize the export of the data, without having to write a large amount of cumbersome redundant code, reducing the workload of manual coding and improving the efficiency of data export.

[0046] Furthermore, when the preset data export template does not meet specific requirements, users can write their own receiving objects containing annotations based on actual data structures and business needs, thereby improving the flexibility of data export.

[0047] Furthermore, through in-depth analysis of the data export template, key structural information such as column headers, table pages, merged rows and calculation rows in the template are identified, and receiving objects containing annotations are automatically generated based on this structural information. The annotations correspond to the structural features in the template, thereby realizing the mapping of data and Excel columns, simplifying the encoding process, reducing the operating cost of exporting complex templates, and further improving the efficiency of data export.

[0048] Furthermore, by adding simulated data to the data export template and analyzing and obtaining the structural information of the template based on the simulated data, the real data processing scenario is simulated, so that the key structural elements such as column headers, table pages, merged rows and calculation rows in the template can be more intuitively understood and identified, thereby improving the accuracy of structural information analysis.

[0049] Furthermore, by responding to the user's download instruction, querying the data to be exported from the database and assembling it into a predefined receiving object, the speed of data processing and the real-time response to the user are improved.

[0050] Furthermore, by introducing the mechanism of permission verification and permission management in the data export template, the columns in the data export template that users have download permissions for are determined, allowing users to access data within their permission range, and dynamically adjusting the exported data according to different users, which not only improves the targetedness of data export, but also improves the security of data export.

[0051] Furthermore, by splitting the data to be exported into multiple data blocks and assigning a corresponding thread to each data block, each thread can independently write the data block into the data export template. Through this multi-threaded parallel writing operation, the overall writing time is reduced and the efficiency of data export is improved.

[0052] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:

[0054] Figure 1 It is a flowchart of a data export method based on EasyExcel annotation provided in an embodiment of the present application;

[0055] Figure 2 It is a schematic diagram of the processing process for different data export templates provided in an embodiment of the present application;

[0056] Figure 3 It is a schematic diagram of the data processing process of a thread provided in an embodiment of the present application;

[0057] Figure 4 is a schematic diagram of a scenario example provided in an embodiment of the present application;

[0058] Figure 5 It is a structural schematic diagram of a data export device based on EasyExcel annotation provided in an embodiment of the present application;

[0059] Figure 6 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0060] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.

[0061] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0062] The EasyExcel library provides a convenient solution. EasyExcel is a Java-based library that simplifies the process of mapping Java objects to Excel tables through annotations. Through annotations, EasyExcel can automatically recognize these annotations and generate corresponding Excel files.

[0063] However, when the data structure is complex, it may be necessary to write a lot of cumbersome annotation codes, which is inefficient. In particular, in today's digital age, big data has become an important basis for enterprise decision-making and analysis. Big data usually refers to a collection of data with huge data volume, diverse types, and fast processing speed. The data structure of big data is usually complex and contains many different types of data, such as structured data, semi-structured data, and unstructured data. For example, the order data of an e-commerce company may contain basic order information (such as order number, order time, total amount, etc.), user information (such as user ID, name, contact information, etc.), product information (such as product name, specifications, price, etc.) and logistics information (such as logistics company, waybill number, delivery status, etc.). These data may be distributed in different database tables, and there is a many-to-many relationship, which requires complex association queries to be integrated together.

[0064] For complex big data structures, if you want to automatically import big data into Excel, you usually need to write a lot of cumbersome annotation code. Taking the EasyExcel library as an example, although the mapping process between Java objects and Excel tables is simplified by annotations, when dealing with complex data structures, you still need to write corresponding annotations for each field. For example, for nested objects or collection type fields, you need to use the @ExcelProperty annotation to specify their column names and positions in Excel, and you may even need a custom converter to handle special data formats, which greatly increases the workload of development and is inefficient. In addition, when the data structure changes, such as adding new fields or modifying field types, the corresponding annotation code also needs to be modified a lot, further reducing development efficiency.

[0065] In order to improve the efficiency of data export, the embodiment of the present application provides a data export method, device and storage medium based on EasyExcel annotation. The following is a detailed description of the data export method, device and storage medium based on EasyExcel annotation provided by the embodiment of the present application through specific embodiments and application scenarios in conjunction with the accompanying drawings.

[0066] Among them, the data export method based on EasyExcel annotation can be applied to the terminal, and can be specifically executed by hardware or software in the terminal.

[0067] The terminal includes, but is not limited to, a portable communication device such as a mobile phone or tablet computer with a touch-sensitive surface (e.g., a touch screen display and / or a touch pad). It should also be understood that in some embodiments, the terminal may not be a portable communication device, but a desktop computer with a touch-sensitive surface (e.g., a touch screen display and / or a touch pad).

[0068] In the following various embodiments, a terminal including a display and a touch-sensitive surface is described. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, a mouse and a joystick.

[0069] The data export method based on EasyExcel annotation provided in the embodiment of the present application may be executed by an electronic device or a functional module or functional entity in the electronic device that can implement the method. The electronic devices mentioned in the embodiment of the present application include but are not limited to mobile phones, tablet computers, computers, cameras, and wearable devices. The data export method based on EasyExcel annotation provided in the embodiment of the present application is described below by taking the electronic device as the execution subject as an example.

[0070] like Figure 1As shown, the data export method based on EasyExcel annotation includes: step 110, step 120, step 130 and step 140.

[0071] Step 110: Obtain a data export template, which defines the data export structure.

[0072] In an embodiment of the present application, the data export template can be a pre-designed Excel file, which defines the export structure of the data, including which columns need to be exported, and the order and format of these columns. For example, the data export template can include a title row, column names, and possible static data, such as fonts, colors, borders, etc., which will not be changed when exporting. The data export template can also include some special expressions or placeholders for dynamically filling in data when exporting.

[0073] The data export template provides a framework so that the exported data can be arranged according to a preset format and layout, making the exported data file consistent and readable.

[0074] In some embodiments, the template can be pre-created by the user or generated by a program. When manually created, the user needs to define the columns and formats in Excel and then save it as a template file. When the template is generated by a program, the EasyExcel API can be used to define the attributes and formats of the columns and then generate a template file. For example, annotations can be used to define the correspondence between the attributes of a Java object and an Excel column.

[0075] Step 120: When the data export template meets the preset conditions, a receiving object including annotations is generated according to the data export template; the receiving object includes an object class that carries data, and the annotations are used to control the export behavior of the data.

[0076] In some embodiments, the role of the preset condition can be to determine whether the data export template is a complex template. For example, the preset condition can be that the data export template includes multiple worksheets, includes nested data structures (such as lists or arrays), needs to merge cells to display data, contains multiple data types (such as strings, numbers, dates, etc.), and needs to perform special processing on specific data types (such as currency formatting or percentage calculation). The preset condition can be one or more of the above. When the data export template meets the preset conditions, it can be determined that the data export template is a complex template.

[0077] When the data export template meets the preset conditions, a receiving object including annotations can be generated according to the data export template. The receiving object includes an object class that carries data, for example, the receiving object can include a Java object class, which corresponds to a table structure in a database or an entity in a business logic. According to the structure of the data export template, a Java object class can be defined, and attributes corresponding to Excel columns can be created in the Java object class.

[0078] In some embodiments, EasyExcel provides a series of annotations for controlling the export behavior of data, that is, for controlling how data is mapped from Java objects to Excel files. Common annotations may include @ExcelProperty: used to specify the correspondence between the properties of Java objects and Excel columns; @ExcelIgnore: used to ignore a certain property and not export it to Excel files; @ExcelCollection: used to process collection type properties, such as lists or arrays. These annotations can be defined on the properties of Java objects to guide EasyExcel on how to write data to Excel files.

[0079] In an example, suppose you need to export order data to Excel. The order data includes basic order information and order details. You can analyze the data export template to determine whether the data export template contains columns for orders and products, and generate a receiving object including annotations. For example, you can define two Java object classes: Order and OrderDetail. The receiving object is represented as:

[0080] public class Order{

[0081] @ExcelProperty("Order Number")

[0082] private String orderId;

[0083] @ExcelProperty("Customer Name")

[0084] private String customerName;

[0085] }

[0086] public class OrderDetail{

[0087] @ExcelProperty("Product Number")

[0088] private String productId;

[0089] @ExcelProperty("Product Name")

[0090] private String productName;

[0091] }

[0092] In the Order class, you can use the @ExcelProperty annotation to specify which column in the data export template each property corresponds to. For dates and numbers, you can use the @DateTimeFormat and @NumberFormat annotations to specify the format, etc.

[0093] In some embodiments, the method further comprises:

[0094] When the data export template does not meet the preset conditions, a receiving object including annotations written by the user according to the data export template is obtained.

[0095] In this embodiment, if it is identified that the data export template does not meet the preset conditions, the user can be notified in the user interface that the user needs to intervene to write a receiving object containing annotations according to the data export template. The user can write or modify the receiving object according to the structure and requirements of the data export template, and use annotations in the object classes of these receiving objects to define the data export behavior.

[0096] In this embodiment, when the preset data export template does not meet specific requirements, the user can write a receiving object containing annotations according to the actual data structure and business requirements, thereby improving the flexibility of data export.

[0097] Step 130: Assemble the data to be exported into the receiving object.

[0098] In an embodiment of the present application, the data to be exported may be data obtained from any data source, for example, a database query may be executed or the data to be exported may be obtained from an API (Application Programming Interface).

[0099] In an embodiment of the present application, since the data to be exported obtained from the data source may be data in the original format, it is first necessary to convert the format of the data to be exported into a Java object, and then assemble the data to be exported into the receiving object. In one example, the export data received from the API is in JSON format, and the JSON data can be converted into a Java object, and the data can be assembled into the receiving object. For example, the JSON data may contain an order number, a customer name, and an order date, and this information can be extracted and set to the corresponding attributes of the Order object.

[0100] Step 140: Export the data to be exported in the receiving object into a data export template based on the annotation.

[0101] In an embodiment of the present application, the data export template can be read to understand the layout and format of the data defined in the data export template. Using the EasyExcel library, the data to be exported is filled into the corresponding position in the data export template according to the annotation in the receiving object. For example, the annotation @ExcelProperty specifies the correspondence between the object property of the receiving object and the Excel column. After the data to be exported is filled, an Excel file can be generated and sent to the user.

[0102] The data export method based on EasyExcel annotation provided in the embodiment of the present application obtains a data export template, and the data export template defines the export structure of the data; when the data export template meets the preset conditions, a receiving object including annotations is generated according to the data export template; the receiving object includes an object class that carries data, and the annotations are used to control the export behavior of the data; the data to be exported is assembled into the receiving object; based on the annotations, the data to be exported in the receiving object is exported to the data export template. The embodiment of the present application can clarify the export structure of the data through the predefined data export template. When the data export template meets the preset conditions, a receiving object including annotations will be automatically generated. Developers only need to focus on the assembly of the data and the business logic to realize the export of the data, without having to write a large amount of cumbersome redundant code, reducing the workload of manual coding and improving the efficiency of data export.

[0103] In practical applications, although the data structure of big data is complex and diverse, involving multiple related tables and nested relationships. For example, an e-commerce system may contain multiple tables such as orders, users, goods and logistics, and there are complex associations between these tables. Traditional methods require developers to manually write a lot of code to handle these complex relationships. In the embodiment of the present application, developers only need to pay attention to the assembly and business logic of the data, and clarify the export structure of the data through the predefined data export template. When the data export template meets the preset conditions, a receiving object containing annotations will be automatically generated. Developers no longer need to pay attention to the data structure of big data, so there is no need to manually write a large amount of cumbersome annotation code, and when the data structure of big data changes, there is no need to modify the annotation code in large quantities, thereby reducing the workload of manual coding and improving the efficiency of data export.

[0104] In some embodiments, generating a receiving object including annotations according to a data export template includes:

[0105] Analyze the structural information of the data export template; the structural information includes at least one of a column title, a table page, a merged row, and a calculated row in the data export template;

[0106] Generates a receiving object including annotations based on the structural information.

[0107] In this embodiment, the title of each column in the data export template can be checked, and these titles can be mapped to attributes in the receiving object when generating the receiving object. For example, if there is a column titled "Customer Name" in the data export template, a corresponding attribute is generated in the receiving object.

[0108] In this embodiment, table pages can also be identified, for example, the number of worksheets (Sheets) included in the data export template can be determined, and each worksheet may correspond to a different data set or data view. Merged rows can also be identified, for example, to check whether there are merged cells in the data export template; calculation rows can also be identified to check whether there are rows used for calculations in the data export template, such as summation, average, etc.

[0109] After determining the structure information, a receiving object including annotations can be generated according to the structure information. Specifically, the properties of the Java object class can be defined according to the column headers of the data export template, and each property can correspond to a column in the data export template. Use the annotations provided by EasyExcel, such as @ExcelProperty, to map the properties of the Java object class to the column headers of the data export template.

[0110] Processing table pages: If the data export template contains multiple worksheets, you can create different Java object classes for each worksheet, or use different annotations in the same class to distinguish them. Processing merged rows: For merged rows, you can define special attributes in the Java object class or use annotations to mark these attributes so that they can be processed correctly during export. Processing calculated rows: For calculated rows, you can define methods in the Java object class to perform calculations, or use annotations to specify which attributes need to be calculated.

[0111] In this embodiment, through in-depth analysis of the data export template, key structural information such as column headers, table pages, merged rows and calculation rows in the template are identified, and a receiving object containing annotations is automatically generated based on this structural information. The annotations correspond to the structural features in the template, thereby realizing the mapping of data and Excel columns, simplifying the encoding process, reducing the operating cost of exporting complex templates, and further improving the efficiency of data export.

[0112] In some embodiments, the structural information of the analysis data export template includes:

[0113] Add simulated data to the data export template;

[0114] The structural information of the data export template is obtained based on the simulation data analysis.

[0115] In this embodiment, if Figure 2 As shown, several rows of simulation data can be added to the data export template. These simulation data can be representative data that can cover the data type structure of the data export template, such as text, numbers, dates, etc. Furthermore, considering the diversity of data, the simulation data can also include some special cases, such as null values, error values, long texts, etc., so that the characteristics of the data export template can be identified during analysis.

[0116] In this embodiment, a programming language or tool, such as EasyExcel, can be used to read the data export template containing the simulation data, and the structural information of the data export template can be analyzed in combination with the simulation data. After determining the structural information, a receiving object including annotations can be generated according to the structural information.

[0117] In this embodiment, by adding simulation data to the data export template and analyzing and acquiring the structural information of the template based on the simulation data, a real data processing scenario is simulated, thereby more intuitively understanding and identifying key structural elements such as column headers, table pages, merged rows, and calculation rows in the template, thereby improving the accuracy of structural information analysis.

[0118] In some embodiments, assembling the data to be exported into a receiving object includes:

[0119] In response to a download instruction from a user, querying and obtaining the data to be exported from a database;

[0120] Assemble the data to be exported into the receiving object.

[0121] In this embodiment, the user can issue an instruction to download data through a user interface, such as a Web interface or a desktop application, and this instruction will trigger the download process of the backend service.

[0122] After the download process is triggered, a corresponding database query statement can be constructed according to the data type and range requested by the user. For example, a SQL query can be constructed, the database query is executed to obtain the data to be exported, and the data to be exported is assembled into a receiving object.

[0123] In this embodiment, by responding to the user's download instruction, querying the data to be exported from the database and assembling it into a predefined receiving object, the speed of data processing and the real-time response to the user are improved.

[0124] In some embodiments, in response to a download instruction from a user, querying the database for data to be exported includes:

[0125] In response to a download instruction from a user, checking the user's authority;

[0126] Determine the columns in the data export template that users have download permissions for;

[0127] The data to be exported is obtained from the database based on the columns for which the user has download permissions.

[0128] In this embodiment, after the user triggers the download instruction, the user can be authenticated. For example, the user's identity can be verified by a username and password or a more advanced identity authentication mechanism, and the user's role and permissions can be checked to determine whether the user has the right to initiate a download request, and which columns of data in the data export template can be requested. For example, a permission database is pre-defined, and the user's roles and corresponding permissions are stored in the permission database. The user's permissions are queried through the permission database. In one example, a user requests to download employee information. If the user's role is the R&D department, then the user has the right to access the names of employees in this department. If the user's role is the human resources department, then the user has the right to access the names of employees in various departments.

[0129] In this embodiment, the columns of data in the data export template that the user can download can be determined based on the user's permissions, and the data to be exported can be queried from the database based on the columns that the user has the download permission for. Alternatively, the columns in the data export template that the user does not have the download permission for can be marked in the receiving object through annotations, so as to prevent the marked data from being exported in the subsequent data export process.

[0130] In this embodiment, by introducing a mechanism of permission verification and permission management in the data export template, the columns in the data export template for which the user has download permissions are determined, so that the user can access the data within his or her permission range, and the exported data can be dynamically adjusted according to different users, which not only improves the targetedness of data export, but also improves the security of data export.

[0131] In some embodiments, exporting the to-be-exported data in the received object into a data export template based on the annotation includes:

[0132] Split the data to be exported in the receiving object into multiple data blocks, and mark the starting writing position for each data block;

[0133] A corresponding thread is assigned to each data block so that each thread writes each data block into the data export template according to the annotation and the starting writing position.

[0134] In this embodiment, the data to be exported can be divided into multiple data blocks with the same or different data volumes according to the data volume. For each data block, the starting writing position of the data block in the data export template can be marked.

[0135] In this embodiment, a thread pool can be created according to the needs of system resources and export tasks, and the thread pool can include multiple threads. Each data block can be assigned to a thread. Of course, when there are a large number of data blocks, a data block can be assigned to a thread first. When a thread completes data writing and releases it, if there are still unwritten data blocks, the remaining unwritten data blocks can be assigned to the thread for continued writing. Figure 3 As shown, each thread can perform data writing operations according to the allocated data block and the starting writing position. For example, the thread can use the EasyExcel API to write data into the data export template according to the annotation.

[0136] In this embodiment, by splitting the data to be exported into multiple data blocks and assigning a corresponding thread to each data block, each thread can independently write the data block into the data export template. Through this multi-threaded parallel writing operation, the overall writing time is reduced and the efficiency of data export is improved.

[0137] The following is an example of a scenario to introduce the data export method based on EasyExcel annotation provided by the embodiment of the present application. Figure 4 As shown, this scenario example includes the following steps.

[0138] The user can trigger a download operation in the user interface and request to export data. For example, the user can select a data export template, i.e., an Excel file, in the user interface and then click to confirm the download. When the user triggers a download operation, the user's permissions can be checked to determine which columns in the Excel file the user has the permission to download. The data to be exported is then obtained through a MySQL database query and assembled into a receiving object. The data is then split. Assuming there are m pieces of data, they can be split into n data blocks to improve processing efficiency. For each data block, the starting write position of the data block in the data export template can be marked. For example, for data block 1, the starting position of the data is marked as the write start position. For data block 2, the starting position is the end of data block 1, and so on.

[0139] In this scenario example, a thread pool can be created according to the needs of system resources and export tasks. The thread pool can include multiple threads. Each data block can be assigned a thread. Of course, when there are a large number of data blocks, a data block can be assigned to a thread first. When a thread completes data writing and releases it, if there are still unwritten data blocks, the remaining unwritten data blocks can be assigned to the thread to continue writing. During the thread working process, the data of the data block can be written into an Excel file, and the data is filled according to the annotations and the writing start position. After each thread completes data writing, it will check whether there are any remaining data blocks to be processed. If so, it will continue to process one of the remaining databases. After the thread completes all data writing, the data export process ends, and the generated Excel file is provided to the user for download.

[0140] The data export method based on EasyExcel annotation provided in the embodiment of the present application can be executed by a data export device based on EasyExcel annotation. In the embodiment of the present application, the data export method based on EasyExcel annotation is executed by a data export device based on EasyExcel annotation as an example to illustrate the data export device based on EasyExcel annotation provided in the embodiment of the present application.

[0141] The embodiment of the present application also provides a data export device based on EasyExcel annotation.

[0142] like Figure 5 As shown, the data export device based on EasyExcel annotation includes:

[0143] An acquisition module 510 is used to acquire a data export template, where the data export template defines a data export structure;

[0144] A generating module 520, configured to generate a receiving object including annotations according to the data export template when the data export template meets the preset conditions; the receiving object includes an object class carrying data, and the annotations are used to control the export behavior of the data;

[0145] An assembling module 530, used for assembling the data to be exported into a receiving object;

[0146] The export module 540 is used to export the data to be exported in the received object into a data export template based on the annotation.

[0147] The data export device based on EasyExcel annotation provided in the embodiment of the present application obtains a data export template, which defines the export structure of data; when the data export template meets the preset conditions, a receiving object including annotations is generated according to the data export template; the receiving object includes an object class that carries data, and the annotations are used to control the export behavior of the data; the data to be exported is assembled into the receiving object; and the data to be exported in the receiving object is exported into the data export template based on the annotations. The embodiment of the present application can clarify the export structure of data through the predefined data export template. When the data export template meets the preset conditions, a receiving object including annotations will be automatically generated. Developers only need to focus on the assembly of data and business logic to realize data export, without writing a large amount of cumbersome redundant code, reducing the workload of manual coding and improving the efficiency of data export.

[0148] In some embodiments, the generating module 520 is further configured to:

[0149] When the data export template does not meet the preset conditions, a receiving object including annotations written by the user according to the data export template is obtained.

[0150] In this embodiment, when the preset data export template does not meet specific requirements, the user can write a receiving object containing annotations according to the actual data structure and business requirements, thereby improving the flexibility of data export.

[0151] In some embodiments, the generating module 520 is further configured to:

[0152] Analyze the structural information of the data export template; the structural information includes at least one of a column title, a table page, a merged row, and a calculated row in the data export template;

[0153] Generates a receiving object including annotations based on the structural information.

[0154] In this embodiment, through in-depth analysis of the data export template, key structural information such as column headers, table pages, merged rows and calculation rows in the template are identified, and a receiving object containing annotations is automatically generated based on this structural information. The annotations correspond to the structural features in the template, thereby realizing the mapping of data and Excel columns, simplifying the encoding process, reducing the operating cost of exporting complex templates, and further improving the efficiency of data export.

[0155] In some embodiments, the generating module 520 is further configured to:

[0156] Add simulated data to the data export template;

[0157] The structural information of the data export template is obtained based on the simulation data analysis.

[0158] In this embodiment, by adding simulation data to the data export template and analyzing and acquiring the structural information of the template based on the simulation data, a real data processing scenario is simulated, thereby more intuitively understanding and identifying key structural elements such as column headers, table pages, merged rows, and calculation rows in the template, thereby improving the accuracy of structural information analysis.

[0159] In some embodiments, the assembly module 530 is further configured to:

[0160] In response to a download instruction from a user, querying and obtaining the data to be exported from a database;

[0161] Assemble the data to be exported into the receiving object.

[0162] In this embodiment, by responding to the user's download instruction, querying the data to be exported from the database and assembling it into a predefined receiving object, the speed of data processing and the real-time response to the user are improved.

[0163] In some embodiments, the assembly module 530 is further configured to:

[0164] In response to a download instruction from a user, checking the user's authority;

[0165] Determine the columns in the data export template that users have download permissions for;

[0166] The data to be exported is obtained from the database based on the columns for which the user has download permissions.

[0167] In this embodiment, by introducing a mechanism of permission verification and permission management in the data export template, the columns in the data export template for which the user has download permissions are determined, so that the user can access the data within his or her permission range, and the exported data can be dynamically adjusted according to different users, which not only improves the targetedness of data export, but also improves the security of data export.

[0168] In some embodiments, the export module 540 is further configured to:

[0169] Split the data to be exported in the receiving object into multiple data blocks, and mark the starting writing position for each data block;

[0170] A corresponding thread is assigned to each data block so that each thread writes each data block into the data export template according to the annotation and the starting writing position.

[0171] In this embodiment, by splitting the data to be exported into multiple data blocks and assigning a corresponding thread to each data block, each thread can independently write the data block into the data export template. Through this multi-threaded parallel writing operation, the overall writing time is reduced and the efficiency of data export is improved.

[0172] The data export device based on EasyExcel annotation in the embodiment of the present application can be an electronic device, or a component in an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a palmtop computer, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., and the embodiment of the present application is not specifically limited.

[0173] The data export device based on EasyExcel annotation in the embodiment of the present application can be a device with an operating system. The operating system can be a Microsoft (Windows) operating system, an Android (Android) operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0174] In some embodiments, Figure 6As shown, the embodiment of the present application also provides an electronic device 600, including a processor 601, a memory 602, and a computer program stored in the memory 602 and executable on the processor 601. When the program is executed by the processor 601, the various processes of the above-mentioned data export method embodiment based on EasyExcel annotation are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0175] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.

[0176] The embodiment of the present application also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned data export method embodiment based on EasyExcel annotation are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0177] The processor is the processor in the electronic device in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.

[0178] An embodiment of the present application also provides a computer program product, including a computer program, which implements the above-mentioned data export method based on EasyExcel annotation when executed by a processor.

[0179] The processor is the processor in the electronic device in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.

[0180] The embodiment of the present application further provides a chip, which includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned data export method embodiment based on EasyExcel annotations, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0181] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.

[0182] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0183] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0184] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

[0185] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0186] Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present application, and that the scope of the present application is defined by the claims and their equivalents.

Claims

1. A data export method based on EasyExcel annotation, characterized in that: include: Obtaining a data export template, wherein the data export template defines an export structure of data; If the data export template meets the preset conditions, generating a receiving object including annotations according to the data export template; The receiving object includes an object class that carries data, and the annotation is used to control the export behavior of the data; Assembling the data to be exported into the receiving object; The data to be exported in the receiving object is exported to the data export template based on the annotation.

2. The method according to claim 1, characterized in that The method further comprises: When the data export template does not meet the preset conditions, a receiving object including annotations written by the user according to the data export template is obtained.

3. The method according to claim 1, characterized in that: The step of generating a receiving object including annotations according to the data export template comprises: Analyze the structural information of the data export template; the structural information includes at least one of a column title, a table page, a merged row, and a calculated row in the data export template; A receiving object including annotations is generated according to the structural information.

4. The method according to claim 3, characterized in that The analyzing the structural information of the data export template includes: Adding simulation data to the data export template; The structural information of the data export template is obtained based on the simulation data analysis.

5. The method according to claim 1, characterized in that The step of assembling the data to be exported into the receiving object comprises: In response to a download instruction from a user, querying and obtaining the data to be exported from a database; Assemble the data to be exported into the receiving object.

6. The method according to claim 5, characterized in that The step of querying the database for the data to be exported in response to the download instruction of the user includes: In response to a download instruction from a user, checking the authority of the user; Determine the columns in the data export template for which the user has download permissions; The data to be exported is obtained by querying from the database according to the columns for which the user has download authority.

7. The method according to claim 1, characterized in that The exporting the to-be-exported data in the received object to the data export template based on the annotation includes: Splitting the data to be exported in the receiving object into multiple data blocks, and marking a starting writing position for each data block; A corresponding thread is allocated to each data block, so that each thread writes each data block into the data export template according to the annotation and the starting writing position.

8. A data export device based on EasyExcel annotation, characterized in that: include: An acquisition module, used to acquire a data export template, wherein the data export template defines an export structure of data; A generating module, configured to generate a receiving object including annotations according to the data export template when the data export template meets a preset condition; The receiving object includes an object class that carries data, and the annotation is used to control the export behavior of the data; An assembling module, used for assembling the data to be exported into the receiving object; An export module is used to export the to-be-exported data in the receiving object into the data export template based on the annotation.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 7 is implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Metadata-based general data table dynamic exporting method and system

    CN121117085A

  • Data dynamic exporting method and system based on templated configuration

    CN121597682A