CN111367976A - Method and device for exporting EXCEL file data based on JAVA reflection mechanism - Google Patents

Method and device for exporting EXCEL file data based on JAVA reflection mechanism Download PDF

Info

Publication number
CN111367976A
CN111367976A CN202010126823.4A CN202010126823A CN111367976A CN 111367976 A CN111367976 A CN 111367976A CN 202010126823 A CN202010126823 A CN 202010126823A CN 111367976 A CN111367976 A CN 111367976A
Authority
CN
China
Prior art keywords
data
excel file
target
exported
attribute
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010126823.4A
Other languages
Chinese (zh)
Inventor
倪超然
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Ping An Medical Health Technology Service Co Ltd
Original Assignee
Ping An Medical and Healthcare Management Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Medical and Healthcare Management Co Ltd filed Critical Ping An Medical and Healthcare Management Co Ltd
Priority to CN202010126823.4A priority Critical patent/CN111367976A/en
Publication of CN111367976A publication Critical patent/CN111367976A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof

Abstract

The application discloses an EXCEL file data export method and device based on a JAVA reflection mechanism, relates to the technical field of computers, can conveniently export EXCEL file data, can reduce the coupling degree of service codes and export function codes, enables the codes to be simpler, and also avoids errors possibly generated in copying and pasting the codes. The method comprises the following steps: firstly, creating a custom annotation according to header information corresponding to data to be exported in a target EXCEL file; adding a self-defined note to the entity attribute corresponding to the data to be exported; then according to the self-defined annotation, reading table data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism; and finally, storing the read table data in a preset storage position. The method and the device are suitable for export processing of EXCEL file data.

Description

Method and device for exporting EXCEL file data based on JAVA reflection mechanism
Technical Field
The application relates to the technical field of computers, in particular to a method and a device for exporting EXCEL file data based on a JAVA reflection mechanism.
Background
EXCEL is a spreadsheet program. The user can create a workbook (a collection of spreadsheets) using EXCEL and set the workbook format in order to analyze the data and make more informed business decisions.
At present, the conventional export of EXCEL file data requires many fixed codes (the codes corresponding to each EXCEL table are written specifically), such as the title row, the sequence of the title row, the number of columns of the title row, etc. in the export of EXCEL file. However, once these properties change, the code has to be modified, adding some human cost. If a similar EXCEL file is to be exported, the original export function code also needs to be modified to meet the requirements of a new EXCEL table. Resulting in many redundant codes generated during the encoding process and a high degree of coupling between the EXCEL derivation function and the service code.
Disclosure of Invention
In view of this, the present application provides a method and an apparatus for exporting EXCEL file data based on a JAVA reflection mechanism, and mainly aims to solve the technical problems that the labor cost is increased, a lot of redundant codes are generated in the encoding process, and the EXCEL export function and the service code coupling degree are high in the conventional method for exporting EXCEL file data.
According to one aspect of the present application, there is provided a method for exporting EXCEL file data based on a JAVA reflection mechanism, the method comprising:
creating a custom annotation according to the title information corresponding to the data to be exported in the target EXCEL file;
adding a self-defined note to the entity attribute corresponding to the data to be exported;
according to the user-defined annotation, reading table data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism;
and storing the read table data in a preset storage position.
According to another aspect of the present application, there is provided an apparatus for exporting EXCEL file data based on a JAVA reflection mechanism, the apparatus comprising:
the creation module is used for creating a custom annotation according to the title information corresponding to the data to be exported in the target EXCEL file;
the adding module is used for adding a custom annotation to the entity attribute corresponding to the data to be exported;
the reading module is used for reading the form data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism according to the custom annotation;
and the storage module is used for storing the read table data in a preset storage position.
According to yet another aspect of the present application, a non-transitory readable storage medium is provided, on which a computer program is stored, which when executed by a processor, implements the above method for exporting EXCEL file data based on the JAVA reflection mechanism.
According to still another aspect of the present application, there is provided a computer device, including a non-volatile readable storage medium, a processor, and a computer program stored on the non-volatile readable storage medium and executable on the processor, where the processor implements the method for exporting EXCEL file data based on the JAVA reflection mechanism as described above when executing the program.
By means of the technical scheme, the method and the device for exporting the EXCEL file data based on the JAVA reflection mechanism are provided. According to the method and the device, the user-defined annotation is created according to the title information corresponding to the data to be exported in the target EXCEL file. And adding a custom annotation to the entity attribute corresponding to the data to be exported so as to read the table data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism according to the custom annotation, and exporting the read table data to a preset storage position. The method is equivalent to developing an EXCEL data export tool class, decoupling is carried out by utilizing functional codes and service codes, the data needing to be exported in an EXCEL form can be sorted and summarized into a set, then, by utilizing the tool class, title lines and data are read from entity classes corresponding to the data needing to be exported in the set through a JAVA reflection mechanism, and then EXCEL file data are exported. Compared with the prior art, the method and the device have the advantages that the EXCEL file data can be exported by calling the tool class, the coupling degree of the service code and the export function code is reduced, the code is simpler, and errors possibly generated in copying and pasting the code are avoided. The development efficiency is improved, the labor cost is reduced, and excessive redundant codes cannot be generated.
The above description is only an outline of the technical solution of the present application, and the present application can be implemented in accordance with the content of the description so as to make the technical means of the present application more clearly understood, and the detailed description of the present application will be given below so that the above and other objects, features, and advantages of the present application can be more clearly understood.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application to the disclosed embodiment. In the drawings:
FIG. 1 is a flow chart diagram illustrating a method for exporting EXCEL file data based on a JAVA reflection mechanism according to an embodiment of the present application;
FIG. 2 is a flow chart of another method for exporting EXCEL file data based on a JAVA reflection mechanism according to an embodiment of the present application;
fig. 3 shows a schematic structural diagram of an apparatus for exporting EXCEL file data based on a JAVA reflection mechanism according to an embodiment of the present application.
Detailed Description
The present application will be described in detail below with reference to the accompanying drawings in conjunction with embodiments. It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict.
Aiming at the technical problems that the labor cost is increased, a lot of redundant codes are generated in the encoding process and the coupling degree of an EXCEL export function and a service code is high in the existing traditional export mode of EXCEL file data, the embodiment provides an export method of EXCEL file data based on a JAVA reflection mechanism, as shown in fig. 1, the method comprises the following steps:
101. and creating a custom annotation according to the header information corresponding to the data to be exported in the target EXCEL file.
The target EXCEL file may be an EXCEL file that needs to export data. The title information may be the title content of the data to be exported in the target EXCEL file. In this embodiment, a custom annotation needs to be created first, and the Name attribute of the annotation may be the title content of the data to be exported. For example, the column Name of the data to be exported in the target EXCEL file is defined as the Name attribute of the custom annotation, and the Name attribute corresponding to the annotation is the title content of the title line, which may specifically include "serial number", "age", "gender", and the like. Different custom annotations can be created in advance according to actual requirements.
The execution subject of the present embodiment may be a device or apparatus for export processing of EXCEL file data, and may be configured on the client side or the server side.
102. And adding a self-defined note to the entity attribute corresponding to the data to be exported.
For example, custom annotations are added to the entity attributes corresponding to the data to be exported, such as "serial number", "age", "gender", etc. That is, according to actual needs, it is necessary to derive EXCEL data in the columns of "serial number", "age", "sex", and the like.
103. And reading the form data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism according to the added custom annotation.
The JAVA reflection mechanism refers to that, in a running state, for any class, all attributes and methods of the class can be acquired, and for any object, any method and attribute (including private methods and attributes) of the class can be called, and the function of the dynamically acquired information and the method for dynamically calling the object is called as the JAVA reflection mechanism.
For example, the header row and the corresponding column data are read from the entity class corresponding to the data to be exported through the JAVA reflection mechanism. Specifically, the contents of the title rows of "serial number", "age" and "gender" in the target EXCEL file are read, and then the column data of the column in which the title rows are located is read.
104. And storing the read table data in a preset storage position.
The preset storage location may be a location to which data to be exported in the target EXCEL file needs to be exported, and may be specifically preset according to an actual requirement, such as a certain database, a certain form, or a certain specified another EXCEL file.
Compared with the prior art, the method for exporting the EXCEL file data in the embodiment is equivalent to developing an EXCEL data exporting tool class, decoupling is performed by using the functional codes and the service codes, the data needing to be exported in the EXCEL table can be sorted and collected into a set, then, by using the tool class, the entity class corresponding to the data needing to be exported in the set is read by using the title line and the data through a JAVA reflection mechanism, and then the EXCEL file data is exported. Compared with the prior art, the method and the device have the advantages that the EXCEL file data can be exported by calling the tool class, the coupling degree of the service code and the export function code is reduced, the code is simpler, and errors possibly generated in copying and pasting the code are avoided. The development efficiency is improved, the labor cost is reduced, and excessive redundant codes cannot be generated.
Further, as a refinement and an extension of the specific implementation of the foregoing embodiment, in order to fully illustrate the implementation process in this embodiment, another method for exporting EXCEL file data based on the JAVA reflection mechanism is provided, as shown in fig. 2, the method includes:
201. and creating a custom annotation according to the header information corresponding to the data to be exported in the target EXCEL file.
202. And adding a custom annotation to the entity attribute corresponding to the data to be exported in the target EXCEL file.
203. And obtaining the JAVA class object corresponding to the data to be exported in the target EXCEL file.
For example, a JAVA class object desired to be operated is dynamically acquired. Specifically, the user may set in advance according to the actual EXCEL data export requirement, for example, select a part of the EXCEL data to be exported or select all the EXCEL data to be exported.
204. Acquiring Field member variables of the JAVA class object.
As an optional manner, step 204 may specifically include: firstly, collecting identifiers of cells of JAVA class objects in a target EXCEL file, wherein the corresponding identifiers of the cells are located in the target EXCEL file; then, the region range is defined in the target EXCEL file through the collected marks of the cells; and finally, inquiring member variables contained in the region range for gathering to obtain the Field member variables of the JAVA class object.
When the JAVA class object data is stored in the EXCEL file, the identification of the row and the column where the data is located is correspondingly recorded. In the optional manner, the identifiers of the rows and columns of the cells of the JAVA class objects corresponding to the JAVA class objects in the target EXCEL may be traversed one by one, then summarized based on the identifiers, and finally framed by the summarized identifiers, so as to determine the area Field of the JAVA class object. For example, the user selects the data for deriving the two columns "serial number" and "age", and the area Field where the two columns are located can be automatically selected by the above-mentioned manner.
In the above optional embodiment, the location information of the data in the EXCEL exists in the form of an array, and the array may include the identifier of the row where the cell of the data is located and the identifier of the column where the cell of the data is located; and determining the position of the JAVA class object data by querying the corresponding array, and finally defining the region range according to the positions.
For example, taking the example that the user selects the data for exporting the column of the sequence number in the EXCEL, firstly, the target cell where the sequence number is located is inquired; then, by inquiring the array corresponding to the target cell, the identifier F of the row where the serial number is located and the identifier 1 of the row where the serial number is located are inquired; then, sequentially traversing other data in the F column from the row identifier 2 (row identifier 1 is added with 1 in an accumulated way), and identifiers of rows and columns where cells corresponding to the data are located; and summarizing based on the identifications, and finally delimiting the area of the column of data with the sequence number through the summarized identifications.
By the optional mode, the Field member variables of the JAVA class objects can be accurately acquired, and the accuracy of exporting the subsequent EXCEL file data is ensured.
205. And judging whether the entity attribute corresponding to the acquired Field member variable has the custom annotation.
Based on the selectable mode in step 204, after the area range is defined in the target EXCEL file by the identifier of the cell in which the JAVA class object is respectively corresponding in the target EXCEL file, step 205 may specifically include: firstly, parameterizing variable types of member variables contained in a region range defined in a target EXCEL file by adopting a generic model so as to obtain attribute identifications of entity attributes corresponding to the member variables contained in the region range; then judging whether the obtained attribute identification has a specific attribute identification corresponding to the custom annotation; and if the specific attribute identifier exists in the acquired attribute identifiers, determining that the custom annotation exists in the entity attribute corresponding to the Field member variable.
Wherein, the generic nature refers to type parameterization. The meaning is that the type parameters are allowed to be used when defining classes, interfaces and methods, specific types are specified when the type parameters are used, and all places using the generic parameters are unified to ensure the consistency of the types. If no specific type is specified, the default is Object (parent of all classes in JAVA) type.
For example, after the region range is defined in the target EXCEL file by the identifiers of the cells where the JAVA class objects respectively correspond in the target EXCEL file, all attributes of the region entity class are first acquired by using the generic technique, and specifically, the entity class attributes corresponding to each cell included in the region can be acquired, and then summarized. Traversing the attributes to obtain the identifiers of the attributes; then detecting whether a specific identifier of the custom annotation exists in the identifiers of the attributes, and if the specific identifier exists, indicating that the area contains the custom annotation; otherwise, if the specific identifier does not exist, the area does not contain the customized annotation.
Whether the user-defined annotation exists in the entity attribute corresponding to the acquired Field member variable can be accurately judged through the optional mode, the reading and exporting operation is executed when the user-defined annotation exists, and the invalid operation is stopped in time when the user-defined annotation does not exist, so that the waste of system resources is reduced, the endless loop of infinite calling is avoided, and the downtime phenomenon is reduced.
206. If the self-defined annotation exists in the entity attribute corresponding to the Field member variable, acquiring the Name attribute of the existing self-defined annotation, and calling a preset Get function to extract the Value of the Name attribute of the self-defined annotation corresponding to the target EXCEL file as the read table data.
Wherein, the preset Get function is used for reading the Value of the variable in the class. For example, the specific code implementation process of the preset Get function can be shown as the following pseudo code:
Figure BDA0002394641760000071
based on the manner provided by the code example, Object value ═ t.getclass (). getmethod (key).
The Value of the Name attribute of the custom annotation in EXCEL may specifically refer to: and acquiring a title row corresponding to the Name attribute, and then acquiring the data value of the column corresponding to the title row. The method of the embodiment mainly adopts a JAVA reflection mechanism to obtain the data to be exported, so the data is obtained in the mode.
For example, the Name attribute of the custom annotation for the Field member variable, that is, the column where the title line of the data to be exported is located (the title line is composed of the names of all the attributes added with the custom annotation, and the sequence is the same as the arrangement sequence of the attributes). Specifically, the entity attribute corresponding to the Field member variable is firstly inquired, then the user-defined annotation is obtained from the entity attribute, and further the Name attribute of the user-defined annotation is obtained. For example, the Name attribute of the custom annotation is "number", "age", etc.
As an optional manner, the invoking of the preset Get function to extract the Value corresponding to the Name attribute of the custom annotation in the target EXCEL file may specifically include: acquiring a title line corresponding to the Name attribute of the custom annotation in the target EXCEL file and a data value of a column corresponding to the title line; and then, according to the acquired data Value and the identifier of the cell where the data Value is located, key Value pair data is created and used as a Value corresponding to the Name attribute in the target EXCEL file.
For example, in the method of this embodiment, the Get method that calls the Name attribute obtains the Value of the Name attribute in EXCEL. If the Name attribute corresponds to the "serial number" and the "age" of the title line, then the Value of the Name attribute in the target EXCEL, namely the data of two columns of the "serial number" and the "age", is obtained by the Get method.
By the method, the data to be exported in the target EXCEL file can be accurately read, and the accuracy of exporting the data of the subsequent EXCEL file is further ensured.
207. And saving the read table data in a specified EXCEL file.
Wherein the specified EXCEL file may be an empty EXCEL file or an EXCEL file of the user-specified export data store, etc.
As an alternative, step 207 may specifically include: acquiring a target storage area to be stored with table data in a specified EXCEL file; if a target title line corresponding to the user-defined annotated Name attribute exists in the target storage area, sequentially filling data values corresponding to all cell identifications into corresponding cells of a column below the target title line in the target storage area according to key Value pair data in the Value; and if the target storage area does not have the target title line corresponding to the Name attribute of the custom annotation, creating the target title line in the target storage area, and sequentially filling the data values corresponding to the cell identifications into the corresponding cells of the target storage area, which are located in the column below the target title line, according to the key Value pair data in the Value.
For example, the Value obtained exists in the form of a key-Value pair of a cell identifier and a corresponding data Value, such as cell a: data 1, cell b: data 2, cell c: data 3 …. In the embodiment of the present solution, the location where the exported data is stored in the empty EXCEL (the specified EXCEL file is an empty EXCEL file) can be specified in advance according to the actual demand, for example, the row data is recorded from the second row, and the column data is recorded from the first column. Or also by default by the system to set the storage location, etc.
After the Value is obtained, sequentially filling the data of each cell into the columns corresponding to the empty EXCEL according to each key-Value pair relation in the Value. For example, in the designated storage location, the first row generates the title (such as serial number, age, etc.) of each column according to the Name attribute corresponding to the Value, and then, starting from the next row, the data corresponding to each cell in the Value are sequentially filled into each cell in the column below the corresponding title (i.e., corresponding Name attribute).
In this embodiment, the user-defined annotation of the entity from which the data is to be derived may correspond to the header row of the derived table, and the corresponding data (the data to be read) is located below the header row. The identification annotation of the custom annotation is obtained through a reflection mechanism in JAVA, a title line of an export form is automatically generated, then corresponding data is transmitted, the data is automatically filled in, and finally an EXCEL file (a designated EXCEL file) is generated.
For example, by performing the above steps, the Value of the Name attribute, that is, the data corresponding to the column below the title line, for example, the data of two columns, that is, the serial number and the age, is obtained, and then the Value is filled into a specified area in an EXCEL file (specifically, the Value may be preset by a user, or the Value may be set by default by a system, etc.).
For the embodiment, the table data in the EXCEL is read through a reflection mechanism, the table data is generated to correspond to an entity needing to be processed, and then some calculation operations are performed on the data in the table data, or some warehousing operations are understood. The operation of reading the table, recording the table data and generating the table is simplified.
For convenience of understanding the specific code implementation process for reading the table data of the entity class corresponding to the data to be derived through the JAVA reflection mechanism, the following pseudo code examples are given:
Figure BDA0002394641760000091
based on the pseudo code content, the following processing flow is specifically realized:
step 1, firstly, an empty EXCEL file is generated, wherein the empty EXCEL file does not contain any content.
And 2, dynamically acquiring the JAVA class object to be operated.
And 3, acquiring field member variables of the JAVA class object and judging whether the JAVA class object contains custom annotations. If the user-defined notes exist, the attributes are needed.
And 4, acquiring the Name attribute of the custom annotation of the Field member variable.
And 5, calling a Get method of the attribute to acquire a Value of the Name attribute in the target EXCEL, namely the data Value of the column corresponding to the title line acquired in the step.
And 6, setting the obtained Value into a column corresponding to the empty EXCEL. The Value to be obtained is set in the column corresponding to the empty EXCEL generated in step 1. And further, the purpose of exporting the data needing to be exported in the target EXCEL to the specified EXCEL is realized.
208. And writing the specified EXCEL file with the stored form data to a front end in a streaming mode for displaying.
For example, after the EXCEL file is generated by the reflection mechanism of JAVA, it is written out to the front end in the form of stream, and then downloaded, thereby implementing the export of EXCEL.
The method for exporting the EXCEL file data in the embodiment is equivalent to developing an EXCEL export tool class. Decoupling is carried out by utilizing functional codes and service codes, data needing to be exported in the EXCEL table is sorted and summarized into a set, then header lines and data are read for entity classes corresponding to the data needing to be exported in the set mainly through a JAVA reflection mechanism by utilizing tools, and the header lines and the data are written out to a front end in a streaming mode for downloading and displaying. Compared with the traditional code written specially for an Excel form, the implementation of the export function does not need to be concerned when a developer writes the code in the embodiment. The corresponding Excel file can be generated only by calling the tool class. The coupling degree of the service code and the derived function code is reduced, so that the code is simpler, and errors possibly generated in copying and pasting the code are avoided. The development efficiency is improved, and excessive redundant codes cannot be generated.
Further, as a specific implementation of the method shown in fig. 1 to fig. 2, an embodiment of the present application provides an apparatus for exporting EXCEL file data based on a JAVA reflection mechanism, as shown in fig. 3, the apparatus includes: a creation module 31, an addition module 32, a reading module 33, and a saving module 34.
The creating module 31 is configured to create a custom annotation according to the header information corresponding to the data to be exported in the target EXCEL file;
an adding module 32, configured to add a custom annotation to the entity attribute corresponding to the data to be exported;
the reading module 33 is configured to perform table data reading on the entity class corresponding to the data to be exported through a JAVA reflection mechanism according to the custom annotation;
and a saving module 34, configured to save the read table data in a preset storage location.
In a specific application scenario, the reading module 33 is specifically configured to obtain a JAVA class object corresponding to the data to be exported in the target EXCEL file; acquiring Field member variables of the JAVA class objects; judging whether the self-defined annotation exists in the entity attribute corresponding to the Field member variable; if the custom annotation exists in the entity attribute corresponding to the Field member variable, acquiring the Name attribute of the existing custom annotation, and calling a preset Get function to extract the Value of the Name attribute corresponding to the target EXCEL file as the read table data.
In a specific application scenario, the reading module 33 is further specifically configured to collect identifiers of cells in the target EXCEL file, where the JAVA class objects respectively correspond to; demarcating an area range in the target EXCEL file through the collected identification of the cells; and querying member variables contained in the area range for gathering to obtain the Field member variables.
In a specific application scenario, the reading module 33 is further configured to parameterize the variable types of the member variables included in the region range by using a generic model, so as to obtain attribute identifiers of entity attributes corresponding to the member variables included in the region range; judging whether the obtained attribute identification has a specific attribute identification corresponding to the custom annotation; and if the specific attribute identifier exists in the acquired attribute identifiers, determining that the custom annotation exists in the entity attribute corresponding to the Field member variable.
In a specific application scenario, the reading module 33 is further specifically configured to obtain a title line corresponding to the Name attribute in the target EXCEL file, and a data value of a column corresponding to the title line; and creating key-Value pair data as a Value corresponding to the Name attribute in the target EXCEL file according to the data Value and the identifier of the cell where the data Value is located.
In a specific application scenario, the saving module 34 is specifically configured to, if the preset storage location is an appointed EXCEL file, obtain a target storage area to be stored with the table data in the appointed EXCEL file; if a target title line corresponding to the Name attribute exists in the target storage area, sequentially filling data values corresponding to all cell identifications into corresponding cells of a column, in which the target title line is located, in the target storage area according to key Value pair data in the Value; if the target storage area does not have the target title line corresponding to the Name attribute, the target title line is created in the target storage area, and the data values corresponding to the cell identifications are sequentially filled into the corresponding cells in the target storage area, where the corresponding cells are located, according to the key Value pair data in the Value.
In a specific application scenario, the apparatus further comprises: a display module;
and the display module is used for writing the specified EXCEL file in which the table data is stored out to the front end in a stream form for display.
It should be noted that other corresponding descriptions of the functional units related to the apparatus for exporting EXCEL file data based on the JAVA reflection mechanism provided in this embodiment may refer to the corresponding descriptions in fig. 1 to fig. 2, and are not repeated herein.
Based on the above-mentioned methods shown in fig. 1 and fig. 2, correspondingly, the present embodiment further provides a storage medium, on which a computer program is stored, and the program, when executed by a processor, implements the method for exporting EXCEL file data based on the JAVA reflection mechanism shown in fig. 1 and fig. 2.
Based on such understanding, the technical solution of the present application may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.), and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method of the embodiments of the present application.
Based on the foregoing methods shown in fig. 1 and fig. 2 and the virtual device embodiment shown in fig. 3, to achieve the foregoing object, an embodiment of the present application further provides a computer device, which may specifically be a personal computer, a server, a network device, and the like, where the entity device includes a storage medium and a processor; a storage medium for storing a computer program; a processor for executing a computer program to implement the method for exporting EXCEL file data based on the JAVA reflection mechanism as shown in fig. 1 and fig. 2.
Optionally, the computer device may further include a user interface, a network interface, a camera, Radio Frequency (RF) circuitry, sensors, audio circuitry, a WI-FI module, and so forth. The user interface may include a Display screen (Display), an input unit such as a keypad (Keyboard), etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (e.g., a bluetooth interface, WI-FI interface), etc.
It will be understood by those skilled in the art that the computer device structure provided in the present embodiment is not limited to the physical device, and may include more or less components, or combine some components, or arrange different components.
The storage medium may further include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the above-described physical devices, and supports the operation of the information processing program as well as other software and/or programs. The network communication module is used for realizing communication among components in the storage medium and other hardware and software in the entity device.
Through the above description of the embodiments, those skilled in the art will clearly understand that the present application can be implemented by software plus a necessary general hardware platform, and can also be implemented by hardware. By applying the technical scheme of the application, the development of the EXCEL export tool is equivalent. Decoupling is carried out by utilizing functional codes and service codes, data needing to be exported in the EXCEL table is sorted and summarized into a set, then header lines and data are read for entity classes corresponding to the data needing to be exported in the set mainly through a JAVA reflection mechanism by utilizing tools, and the header lines and the data are written out to a front end in a streaming mode for downloading and displaying. Compared with the traditional code written specially for an Excel form, the implementation of the export function does not need to be concerned when a developer writes the code in the embodiment. The corresponding Excel file can be generated only by calling the tool class. The coupling degree of the service code and the derived function code is reduced, so that the code is simpler, and errors possibly generated in copying and pasting the code are avoided. The development efficiency is improved, and excessive redundant codes cannot be generated.
Those skilled in the art will appreciate that the figures are merely schematic representations of one preferred implementation scenario and that the blocks or flow diagrams in the figures are not necessarily required to practice the present application. Those skilled in the art will appreciate that the modules in the devices in the implementation scenario may be distributed in the devices in the implementation scenario according to the description of the implementation scenario, or may be located in one or more devices different from the present implementation scenario with corresponding changes. The modules of the implementation scenario may be combined into one module, or may be further split into a plurality of sub-modules.
The above application serial numbers are for description purposes only and do not represent the superiority or inferiority of the implementation scenarios. The above disclosure is only a few specific implementation scenarios of the present application, but the present application is not limited thereto, and any variations that can be made by those skilled in the art are intended to fall within the scope of the present application.

Claims (10)

1. A method for exporting EXCEL file data based on a JAVA reflection mechanism is characterized by comprising the following steps:
creating a custom annotation according to the title information corresponding to the data to be exported in the target EXCEL file;
adding a self-defined note to the entity attribute corresponding to the data to be exported;
according to the user-defined annotation, reading table data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism;
and storing the read table data in a preset storage position.
2. The method according to claim 1, wherein the reading, according to the custom annotation, table data of the entity class corresponding to the data to be exported by using a JAVA reflection mechanism specifically comprises:
obtaining a JAVA class object corresponding to the data to be exported in the target EXCEL file;
acquiring Field member variables of the JAVA class objects;
judging whether the self-defined annotation exists in the entity attribute corresponding to the Field member variable;
if the custom annotation exists in the entity attribute corresponding to the Field member variable, acquiring the Name attribute of the existing custom annotation, and calling a preset Get function to extract the Value of the Name attribute corresponding to the target EXCEL file as the read table data.
3. The method according to claim 2, wherein the obtaining Field member variables of the JAVA class object specifically comprises:
collecting the identifiers of the cells of the JAVA class objects in the target EXCEL file corresponding to each cell;
demarcating an area range in the target EXCEL file through the collected identification of the cells;
and querying member variables contained in the area range for gathering to obtain the Field member variables.
4. The method according to claim 3, wherein the determining whether the custom annotation exists in the entity attribute corresponding to the Field member variable specifically includes:
parameterizing the variable types of the member variables contained in the region range by adopting a generic model so as to obtain attribute identifications of entity attributes corresponding to the member variables contained in the region range;
judging whether the obtained attribute identification has a specific attribute identification corresponding to the custom annotation;
and if the specific attribute identifier exists in the acquired attribute identifiers, determining that the custom annotation exists in the entity attribute corresponding to the Field member variable.
5. The method according to claim 4, wherein the calling a preset Get function to extract the Value of the Name attribute corresponding to the target EXCEL file specifically comprises:
acquiring a title line corresponding to the Name attribute in the target EXCEL file and a data value of a column corresponding to the title line;
and creating key-Value pair data as a Value corresponding to the Name attribute in the target EXCEL file according to the data Value and the identifier of the cell where the data Value is located.
6. The method according to claim 5, wherein if the preset storage location is a designated EXCEL file, the storing the read table data in the preset storage location specifically comprises:
acquiring a target storage area to be stored with the table data in the specified EXCEL file;
if a target title line corresponding to the Name attribute exists in the target storage area, sequentially filling data values corresponding to all cell identifications into corresponding cells of a column, in which the target title line is located, in the target storage area according to key Value pair data in the Value;
if the target storage area does not have the target title line corresponding to the Name attribute, the target title line is created in the target storage area, and the data values corresponding to the cell identifications are sequentially filled into the corresponding cells in the target storage area, where the corresponding cells are located, according to the key Value pair data in the Value.
7. The method of claim 6, further comprising:
and writing the specified EXCEL file in which the table data is stored out to a front end in a streaming form for displaying.
8. An apparatus for exporting EXCEL file data based on a JAVA reflection mechanism, comprising:
the creation module is used for creating a custom annotation according to the title information corresponding to the data to be exported in the target EXCEL file;
the adding module is used for adding a custom annotation to the entity attribute corresponding to the data to be exported;
the reading module is used for reading the form data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism according to the custom annotation;
and the storage module is used for storing the read table data in a preset storage position.
9. A non-transitory readable storage medium having stored thereon a computer program, wherein the program, when executed by a processor, implements the method for exporting EXCEL file data based on the JAVA reflection mechanism according to any one of claims 1 to 7.
10. Computer device comprising a non-volatile readable storage medium, a processor and a computer program stored on the non-volatile readable storage medium and executable on the processor, characterized in that the processor implements the method for exporting EXCEL file data based on the JAVA reflection mechanism according to any of claims 1 to 7 when executing the program.
CN202010126823.4A 2020-02-28 2020-02-28 Method and device for exporting EXCEL file data based on JAVA reflection mechanism Pending CN111367976A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010126823.4A CN111367976A (en) 2020-02-28 2020-02-28 Method and device for exporting EXCEL file data based on JAVA reflection mechanism

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010126823.4A CN111367976A (en) 2020-02-28 2020-02-28 Method and device for exporting EXCEL file data based on JAVA reflection mechanism

Publications (1)

Publication Number Publication Date
CN111367976A true CN111367976A (en) 2020-07-03

Family

ID=71208215

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010126823.4A Pending CN111367976A (en) 2020-02-28 2020-02-28 Method and device for exporting EXCEL file data based on JAVA reflection mechanism

Country Status (1)

Country Link
CN (1) CN111367976A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111651221A (en) * 2020-07-14 2020-09-11 迈普通信技术股份有限公司 Annotation internationalization method and device, storage medium and electronic equipment
CN112612924A (en) * 2020-12-30 2021-04-06 绿盟科技集团股份有限公司 Data reading and exporting methods and devices, electronic equipment and storage medium
CN113239106A (en) * 2021-06-04 2021-08-10 平安科技(深圳)有限公司 Excel file export method and device, electronic equipment and storage medium
CN116776843A (en) * 2023-06-19 2023-09-19 北京水脉科技有限公司 Information form data renewing and merging method

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106202283A (en) * 2016-06-30 2016-12-07 国云科技股份有限公司 A kind of custom field derives the data method to Excel
CN109062883A (en) * 2018-07-18 2018-12-21 平安科技(深圳)有限公司 Tables of data dynamic deriving method, device, computer equipment and storage medium
CN109375901A (en) * 2018-09-03 2019-02-22 平安普惠企业管理有限公司 Interface message management method, device, computer equipment and storage medium
CN109800264A (en) * 2018-12-27 2019-05-24 平安科技(深圳)有限公司 Diversified declaration form deriving method, device and storage medium
WO2019153544A1 (en) * 2018-02-12 2019-08-15 平安科技(深圳)有限公司 Annotation backend check method and apparatus, computer device and storage medium.
CN110347999A (en) * 2019-07-17 2019-10-18 政采云有限公司 A kind of method and apparatus of list data verification
CN110750553A (en) * 2019-09-02 2020-02-04 成都市知用科技有限公司 Method for self-defining export of data in service management system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106202283A (en) * 2016-06-30 2016-12-07 国云科技股份有限公司 A kind of custom field derives the data method to Excel
WO2019153544A1 (en) * 2018-02-12 2019-08-15 平安科技(深圳)有限公司 Annotation backend check method and apparatus, computer device and storage medium.
CN109062883A (en) * 2018-07-18 2018-12-21 平安科技(深圳)有限公司 Tables of data dynamic deriving method, device, computer equipment and storage medium
CN109375901A (en) * 2018-09-03 2019-02-22 平安普惠企业管理有限公司 Interface message management method, device, computer equipment and storage medium
CN109800264A (en) * 2018-12-27 2019-05-24 平安科技(深圳)有限公司 Diversified declaration form deriving method, device and storage medium
CN110347999A (en) * 2019-07-17 2019-10-18 政采云有限公司 A kind of method and apparatus of list data verification
CN110750553A (en) * 2019-09-02 2020-02-04 成都市知用科技有限公司 Method for self-defining export of data in service management system

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
DEMO大师: "Java基于注解和反射导入导出Excel", pages 1 - 7, Retrieved from the Internet <URL:http://www.demodashi.com/demo/11995.html> *
菜鸟学院: "经过java反射实现的excel数据导出", pages 1 - 3, Retrieved from the Internet <URL:http://www.noobyard.com/article/p-fbbjjgct-dg.html> *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111651221A (en) * 2020-07-14 2020-09-11 迈普通信技术股份有限公司 Annotation internationalization method and device, storage medium and electronic equipment
CN112612924A (en) * 2020-12-30 2021-04-06 绿盟科技集团股份有限公司 Data reading and exporting methods and devices, electronic equipment and storage medium
CN113239106A (en) * 2021-06-04 2021-08-10 平安科技(深圳)有限公司 Excel file export method and device, electronic equipment and storage medium
CN113239106B (en) * 2021-06-04 2023-12-19 平安科技(深圳)有限公司 Excel file export method and device, electronic equipment and storage medium
CN116776843A (en) * 2023-06-19 2023-09-19 北京水脉科技有限公司 Information form data renewing and merging method

Similar Documents

Publication Publication Date Title
CN111367976A (en) Method and device for exporting EXCEL file data based on JAVA reflection mechanism
WO2021184725A1 (en) User interface test method and apparatus, storage medium, and computer device
CN108762743B (en) Data table operation code generation method and device
CN109308254B (en) Test method, test device and test equipment
CN107305527B (en) Code file processing method and device
CN106354483B (en) Data processing method and device and electronic equipment
CN111259067B (en) Method, device and equipment for realizing DAO interface based on Spring
CN111639473A (en) Excel file analysis method and device based on java, computer equipment and storage medium
CN110580189A (en) method and device for generating front-end page, computer equipment and storage medium
CN112817866A (en) Recording playback method, device, system, computer equipment and storage medium
CN114201615B (en) Scientific research data change review method and server based on data snapshot
CN110716718A (en) Page generation method, device, equipment and storage medium
US10417234B2 (en) Data flow modeling and execution
CN110806866A (en) Generation method and device of front-end management system
CN114610286A (en) Development document generation method and device, computer equipment and storage medium
CN110704635B (en) Method and device for converting triplet data in knowledge graph
CN110222046B (en) List data processing method, device, server and storage medium
CN111476013A (en) Information collection method, information collection device, information collection medium, and electronic device
CN107977459B (en) Report generation method and device
CN115935917A (en) Data processing method, device and equipment for visual chart and storage medium
CN111651531B (en) Data importing method, device, equipment and computer storage medium
US20130262451A1 (en) Analysis support apparatus, analysis support method and analysis support program
CN112632266B (en) Data writing method and device, computer equipment and readable storage medium
JP4295288B2 (en) Form creation device, form creation method, and form creation program
CN113094367A (en) Data processing method and device and server

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right

Effective date of registration: 20220531

Address after: 518000 China Aviation Center 2901, No. 1018, Huafu Road, Huahang community, Huaqiang North Street, Futian District, Shenzhen, Guangdong Province

Applicant after: Shenzhen Ping An medical and Health Technology Service Co.,Ltd.

Address before: Room 12G, Area H, 666 Beijing East Road, Huangpu District, Shanghai 200001

Applicant before: PING AN MEDICAL AND HEALTHCARE MANAGEMENT Co.,Ltd.

TA01 Transfer of patent application right