CN111367976B - 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 PDFInfo
- Publication number
- CN111367976B CN111367976B CN202010126823.4A CN202010126823A CN111367976B CN 111367976 B CN111367976 B CN 111367976B CN 202010126823 A CN202010126823 A CN 202010126823A CN 111367976 B CN111367976 B CN 111367976B
- 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.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 58
- 230000007246 mechanism Effects 0.000 title claims abstract description 44
- 238000004590 computer program Methods 0.000 claims description 7
- 239000000284 extract Substances 0.000 claims 1
- 230000008878 coupling Effects 0.000 abstract description 8
- 238000010168 coupling process Methods 0.000 abstract description 8
- 238000005859 coupling reaction Methods 0.000 abstract description 8
- 238000012545 processing Methods 0.000 abstract description 3
- 230000006870 function Effects 0.000 description 16
- 230000008569 process Effects 0.000 description 5
- 238000004891 communication Methods 0.000 description 4
- 238000011161 development Methods 0.000 description 4
- 230000002776 aggregation Effects 0.000 description 1
- 238000004220 aggregation Methods 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000009795 derivation Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/25—Integrating or interfacing systems involving database management systems
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/16—File or folder operations, e.g. details of user interfaces specifically adapted to file systems
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2282—Tablespace storage structures; Management thereof
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Human Computer Interaction (AREA)
- Software Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
The application discloses a method and a device for exporting EXCEL file data based on a JAVA reflection mechanism, which relate to the technical field of computers, can conveniently export the EXCEL file data, can reduce the coupling degree of service codes and export function codes, ensures that the codes are simpler, and also avoids errors possibly generated in copying pasting codes. The method comprises the following steps: firstly, creating a custom annotation according to title information corresponding to data to be exported in a target EXCEL file; adding custom notes to entity attributes corresponding to the data to be exported; then, according to the custom 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 form data in a preset storage position. The method is suitable for exporting processing of EXCEL file data.
Description
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 (set of spreadsheets) using EXCEL and set the workbook format to analyze the data and make more informed business decisions.
Currently, the conventional derivation of EXCEL file data requires many fixed codes (corresponding codes are written for each EXCEL table separately), such as deriving the header lines in the EXCEL file, the order of the header lines, the number of columns of the header lines, and so on. However, once these properties change, the code has to be modified, adding to certain labor costs. If a similar EXCEL file is now desired to be exported, the original export function code will also need to be modified to accommodate the new EXCEL table requirements. Resulting in a lot of redundant codes generated in the encoding process and a high coupling degree of EXCEL export functions and service codes.
Disclosure of Invention
In view of this, the present application provides a method and a device for exporting EXCEL file data based on JAVA reflection mechanism, which mainly aims to solve the technical problems that the manpower cost is increased, a lot of redundant codes are generated in the encoding process, and the EXCEL exporting function and the service code coupling degree are higher in the traditional exporting mode of EXCEL file data.
According to one aspect of the present application, there is provided a method for exporting EXCEL file data based on 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 custom notes to entity attributes corresponding to the data to be exported;
according to the custom annotation, table data reading is carried out on the entity class corresponding to the data to be exported through a JAVA reflection mechanism;
and storing the read form data in a preset storage position.
According to another aspect of the present application, there is provided an EXCEL file data exporting apparatus based on 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 custom notes to the entity attributes corresponding to the data to be exported;
the reading module is used for reading 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 the storage module is used for storing the read form data in a preset storage position.
According to still another aspect of the present application, there is provided a non-volatile readable storage medium having stored thereon a computer program which, when executed by a processor, implements the above-described method for exporting EXCEL file data based on JAVA reflection mechanism.
According to still another aspect of the present application, there is provided a computer device including a nonvolatile readable storage medium, a processor, and a computer program stored on the nonvolatile readable storage medium and executable on the processor, the processor implementing the above-mentioned method for exporting EXCEL file data based on JAVA reflection mechanism when executing the program.
By means of the technical scheme, the method and the device for exporting EXCEL file data based on the JAVA reflection mechanism are provided. Firstly, creating a custom annotation according to title information corresponding to data to be exported in a 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 further exporting the read table data to a preset storage position. The method is equivalent to developing an EXCEL data export tool class, and can realize the arrangement and aggregation of the data needing to be exported in the EXCEL form by decoupling by utilizing the functional code and the service code, and then utilize the tool class to read the header line and the data of the entity class corresponding to the data needing to be exported in the set by utilizing a JAVA reflection mechanism, so as to export the EXCEL file data. Compared with the prior art, the method and the device can realize exporting of EXCEL file data by calling the tool class, reduce the coupling degree of service codes and exported function codes, enable the codes to be simpler, and avoid errors possibly generated in copying the sticky codes. The development efficiency is improved, the labor cost is reduced, and excessive redundant codes are not generated.
The foregoing description is only an overview of the present application, and is intended to be implemented in accordance with the teachings of the present application, as it is to be understood that the following detailed description of the application is intended to provide a better understanding of the present application, as it is intended to provide further understanding of the present application, as it is claimed, along with the additional objects, features and advantages of the present application.
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 specification, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute an undue limitation to the present application. In the drawings:
Fig. 1 shows a flowchart of a method for exporting EXCEL file data based on JAVA reflection mechanism according to an embodiment of the present application;
fig. 2 is a flow chart illustrating another method for exporting EXCEL file data based on JAVA reflection mechanism according to the embodiment of the present application;
fig. 3 shows a schematic structural diagram of an EXCEL file data exporting device based on a JAVA reflection mechanism according to an embodiment of the present application.
Detailed Description
The application will be described in detail hereinafter with reference to the drawings in conjunction with embodiments. It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other.
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 the EXCEL export function and the service codes is high in the traditional export mode of the EXCEL file data at present, the embodiment provides an export method of the EXCEL file data based on a JAVA reflection mechanism, as shown in fig. 1, and the method comprises the following steps:
101. And creating a custom annotation according to the title information corresponding to the data to be exported in the target EXCEL file.
The target EXCEL file may be an EXCEL file that requires export data. The title information may be title content of 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, for example, "serial number", "age", "gender", and the like. Different custom annotations may be created in advance here according to actual requirements.
The execution body of the present embodiment may be an apparatus or device for export processing of EXCEL file data, and may be configured on the client side or the server side.
102. And adding the custom annotation to the entity attribute corresponding to the data to be exported.
For example, the entity attribute corresponding to the data to be exported is added with a custom annotation, such as "serial number", "age", "gender", etc. Specifically, according to actual demands, EXCEL data in columns such as "serial number", "age", "gender", etc. need to be derived.
103. And reading the table data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism according to the added custom annotation.
The reflecting mechanism of JAVA refers to a reflecting mechanism of JAVA language, in which in a running state, for any class, all the attributes and methods of the class can be obtained, and for any object, any method and attribute (including private methods and attributes) thereof can be called, and the dynamically obtained information and the function of the method for dynamically calling the object are called JAVA language.
For example, reading the title row and corresponding column data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism. Specifically, the content of the title lines of "serial number", "age", "gender" in the target EXCEL file is read, and then the column data of the columns in which the title lines are located is read.
104. And storing the read form data in a preset storage position.
The preset storage position may be a position to which data to be exported needs to be exported in the target EXCEL file, and specifically may be preset according to actual requirements, for example, a certain database, a certain form, or a certain designated 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, and can be used for realizing the arrangement and summarization of data needing exporting in an EXCEL form by decoupling functional codes and business codes, then reading the title line and the data of the entity class corresponding to the data needing exporting in the set by using the tool class through a JAVA reflection mechanism, and further exporting the EXCEL file data. Compared with the prior art, the method and the device can realize exporting of EXCEL file data by calling the tool class, reduce the coupling degree of service codes and exported function codes, enable the codes to be simpler, and avoid errors possibly generated in copying the sticky codes. The development efficiency is improved, the labor cost is reduced, and excessive redundant codes are not generated.
Further, as a refinement and extension of the foregoing embodiment, in order to fully describe the implementation procedure in this embodiment, another method for exporting EXCEL file data based on JAVA reflection mechanism is provided, as shown in fig. 2, where the method includes:
201. and creating a custom annotation according to the title information corresponding to the data to be exported in the target EXCEL file.
202. And adding the custom annotation to the entity attribute corresponding to the data to be exported in the target EXCEL file.
203. And acquiring the JAVA class object corresponding to the data to be exported in the target EXCEL file.
For example, JAVA class objects that are desired to be operated on are dynamically acquired. The specific user can preset according to the actual EXCEL data export requirement, for example, select part of EXCEL data for export or select all EXCEL data for export.
204. The Field member variables of the JAVA class object are obtained.
As an alternative, step 204 may specifically include: firstly, collecting identifiers of cells where JAVA class objects respectively correspond in a target EXCEL file; then, defining a regional range in the target EXCEL file through the collected identifiers of the cells; and finally, inquiring member variables contained in the region range, and summarizing to obtain the Field member variables of the JAVA class object.
When JAVA class object data is stored in an EXCEL file, the identification of the row and column in which the data is located is recorded correspondingly. In this optional manner, the identifiers of the rows and columns where the cells corresponding to the JAVA class objects in the target EXCEL are located may be traversed one by one, then summarized based on the identifiers, and finally frame-selected according to the summarized identifiers, so as to determine the region Field of the JAVA class object. For example, the user selects to export data for both the "serial number" and "age" columns, and in this manner, the fields in which the columns are located can be automatically framed.
In the above alternative embodiment, the location information of the data in EXCEL exists in the form of an array, and the array may include an identifier of a row where a cell of the data is located and an identifier of a column where the cell is located; and determining the position of the JAVA class object data by inquiring the corresponding array, and finally defining the area range according to the positions.
For example, taking the example of the user selecting to export the data in the row of serial numbers in EXCEL, firstly, the target cell where the serial number is located is queried; then inquiring the array corresponding to the target cell, and inquiring the identification F of the column where the sequence number is located and the identification 1 of the row where the sequence number is located; then, starting from row identification 2 (row identification 1 is added with 1) and traversing other data in the F columns in sequence, and the identifications of the rows and the columns of the cells corresponding to the data respectively; and summarizing based on the identifiers, and finally, demarcating the area of the serial number column of data through the summarized identifiers.
Through the optional mode, the Field member variables of the JAVA class object can be accurately acquired, and the accuracy of subsequent EXCEL file data export is ensured.
205. And judging whether the entity attribute corresponding to the acquired Field member variable has a custom annotation.
Based on the optional manner in step 204, by the identifier of the cell where each JAVA class object corresponds to in the target EXCEL file, after the region is defined in the target EXCEL file, step 205 may specifically include: firstly, parameterizing variable types of member variables contained in a regional range defined in a target EXCEL file by adopting generalized type so as to acquire attribute identifiers of respective corresponding entity attributes of the member variables contained in the regional range; then judging whether the obtained attribute identification has a specific attribute identification corresponding to the custom annotation; if the acquired attribute identifier has a specific attribute identifier, determining that the entity attribute corresponding to the Field member variable has a custom annotation.
Wherein generic nature refers to type parameterization. By definition, the method and the system are characterized in that the type parameters are allowed to be used when classes, interfaces and methods are defined, specific types are designated when the types are used, all places where the generic parameters are used are unified, and the consistency of the types is ensured. If a specific type is not specified, the default is an Object (parent of all classes in JAVA) type.
For example, through the identification of the corresponding cell of the JAVA class object in the target EXCEL file, after the region range is defined in the target EXCEL file, firstly, all the attributes of the region entity class are obtained by adopting the generic technology, specifically, the entity class attributes corresponding to each cell included in the region can be obtained, and then the summary is performed. Traversing the attributes to obtain the identifications of the attributes; then detecting whether specific identifiers of the custom notes exist in the identifiers of the attributes, and if the specific identifiers exist, indicating that the region contains the custom notes; otherwise, if the specific identifier does not exist, the region is indicated to not contain a custom annotation.
By the optional mode, whether the custom annotation exists in the entity attribute corresponding to the acquired Field member variable can be accurately judged, the reading and exporting operation is executed when the custom annotation exists, and the invalidation operation is stopped in time when the custom annotation does not exist, so that the system resource waste is reduced, the endless loop of infinite calling is avoided, and the downtime phenomenon is reduced.
206. If the user-defined annotation exists in the entity attribute corresponding to the Field member variable, acquiring the Name attribute of the existing user-defined annotation, and calling a preset Get function to extract the Value corresponding to the Name attribute of the user-defined annotation in the target EXCEL file, wherein the Value is used as the read form data.
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 may be as follows:
Based on the manner provided by the above code example, object value=t.getclass (). GetMethod (key). Invoke (t), and further, the value of the name attribute in Excel is obtained through the existing underlying code getClass (), and so on.
The Value of the Name attribute of the custom annotation in EXCEL may specifically refer to: and acquiring a header row corresponding to the Name attribute, and then acquiring a data value of a column corresponding to the header row. The method of the embodiment mainly adopts a JAVA reflection mechanism to acquire the data needing to be exported, so the method is adopted for acquiring.
For example, the Name attribute of the custom annotation for the Field member variable, that is, the column of the header line of the data to be exported (the header line consists of the names of all the attributes to which the custom annotation is added, in the same order as the order in which the attributes are arranged). Specifically, firstly, the entity attribute corresponding to the Field member variable is queried, then, the custom annotation is obtained from the entity attribute, and then, the Name attribute of the custom annotation is obtained. The Name attribute of the custom annotation is "sequence number", "age", etc.
As an optional manner, the extracting the Value corresponding to the Name attribute of the custom annotation in the target EXCEL file by calling the preset Get function may specifically include: acquiring a title line corresponding to a Name attribute of a custom annotation in a target EXCEL file and a data value of a column corresponding to the title line; and then, creating key Value data according to the acquired data Value and the identification of the cell where the key Value data are located, and taking the key Value data as a Value corresponding to the Name attribute in the target EXCEL file.
For example, calling the Get method of the Name attribute in the method of this embodiment obtains the Value of the Name attribute in EXCEL. If the Name attribute corresponds to the 'serial number' and 'age' of the title line, then obtaining the Value of the Name attribute in the target EXCEL by a Get method, namely, data of two columns of 'serial number' and 'age'.
By the method, the data to be exported in the target EXCEL file can be accurately read, and the accuracy of the data export of the subsequent EXCEL file is further ensured.
207. And saving the read form data in a specified EXCEL file.
The specified EXCEL file may be an empty EXCEL file or an EXCEL file in which the user specifies the export data store, or the like.
As an alternative, step 207 may specifically include: acquiring a target storage area for storing form data in a specified EXCEL file; if a target header line corresponding to the Name attribute of the custom annotation exists in the target storage area, sequentially filling data values corresponding to the cell identifications into corresponding cells in the target storage area and in a column under the target header line according to the key Value pair data in the Value; if the target storage area does not contain the target title line corresponding to the Name attribute of the custom annotation, the target title line is created in the target storage area, and the data corresponding to each cell identifier are sequentially filled into the corresponding cells in the target storage area and the column under the target title line according to the key Value pair data in the Value.
For example, the obtained Value exists in the form of a key Value pair of a cell identifier and a corresponding data Value, such as a cell a: data 1, cell b: data 2, cell c: data 3 …. In the embodiment of the present embodiment, a location where the export data is stored in an empty EXCEL (the specified EXCEL file is an empty EXCEL file) may be specified in advance according to actual demands, such as recording row data from the second row, recording column data from the first column, and so on. Or also default storage locations by the system, etc.
After the Value is obtained, the data of each cell is sequentially filled into the columns corresponding to the empty EXCEL according to the relation of each key Value pair in the Value. For example, in the designated storage location, the first row generates the header (such as the serial number, the age, etc.) of each column according to the Name attribute corresponding to the Value, and then, starting in the next row, the data corresponding to each cell in the Value is sequentially filled into each cell in the column under the corresponding header (i.e., corresponding to the Name attribute).
In this embodiment, the custom annotations of the entity from which the data is to be derived may correspond to the header rows of the export table, with the corresponding data (data to be read) below. The identification annotation of the custom annotation is obtained through a reflection mechanism in JAVA, a header row of an export table is automatically generated, then the data is automatically filled in through the corresponding data, and finally an EXCEL file (appointed EXCEL file) is generated.
For example, by executing the above steps, the Value of the Name attribute, that is, the data corresponding to the lower column of the header line, such as the data of two columns of serial numbers and ages, is obtained, and then the data is filled into the specified area (specifically, may be preset by the user, or may be set by default in the system, etc.) in a certain EXCEL file.
For the embodiment, the table data in EXCEL is read through a reflection mechanism, and is generated to correspond to the entity to be processed, and then some calculation operations or some warehouse-in operations are performed on the data in EXCEL. The operation of reading the form, recording the form data and generating the form is simplified.
In order to facilitate understanding the specific code implementation process of reading the table data of the entity class corresponding to the data to be exported through the JAVA reflection mechanism, the following pseudo code example is given:
based on the pseudo code content, the following processing flow is specifically realized:
Step 1, firstly, generating an empty EXCEL file, wherein the EXCEL file does not contain any content.
And step 2, dynamically acquiring the JAVA class object to be operated.
And step 3, acquiring field member variables of the JAVA class object, and judging whether the JAVA class object contains the custom annotation. If there is a custom annotation, we want the property.
And 4, acquiring a 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, a data Value of a 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 acquired is set in the column corresponding to the empty EXCEL generated in step 1. And the purpose of exporting the data needing exporting in the target EXCEL to the appointed EXCEL is achieved.
208. And writing the specified EXCEL file stored with the table data to the front end in a stream form for display.
For example, after an EXCEL file is generated by a JAVA reflection mechanism, the EXCEL file is written out to the front end in the form of a stream and then downloaded, thereby realizing export of the EXCEL.
The method for exporting EXCEL file data in this embodiment corresponds to developing an EXCEL export tool class. And decoupling the functional codes and the service codes, sorting and summarizing the data to be exported in the EXCEL form into a set, and reading the header row and the data of the entity class corresponding to the data to be exported in the set mainly through a JAVA reflection mechanism by using tool classes, and writing the header row and the data out to the front end in a stream form for downloading and displaying. Compared with the traditional code specially written for an Excel table, the implementation of export functions in the embodiment does not need to be concerned when a developer writes the code. Only the tool class is required to be called to generate the corresponding Excel file. 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 the sticky code are avoided. The development efficiency is improved, and excessive redundant codes are not 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 JAVA reflection mechanism, as shown in fig. 3, where the apparatus includes: a creation module 31, an addition module 32, a reading module 33, a saving module 34.
The creating module 31 is configured to create a custom annotation according to header information corresponding to data to be exported in the target EXCEL file;
an adding module 32, configured to add a custom annotation to an entity attribute corresponding to the data to be exported;
the reading module 33 is configured to read, according to the custom annotation, table data of an entity class corresponding to the data to be exported through a JAVA reflection mechanism;
the saving module 34 is 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 a Field member variable of the JAVA class object; judging whether the custom annotation exists in the entity attribute corresponding to the Field member variable; and 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 corresponding to the Name attribute in the target EXCEL file as the read form data.
In a specific application scenario, the reading module 33 is specifically further configured to collect identifiers of cells where the JAVA class objects are respectively corresponding to in the target EXCEL file; defining a regional range in the target EXCEL file through the collected identification of the unit cell; and querying the member variables contained in the regional range to collect the member variables to obtain the Field member variables.
In a specific application scenario, the reading module 33 is specifically further configured to parameterize, by adopting a generic model, variable types of member variables included in the area range, so as to obtain attribute identifiers of entity attributes corresponding to the member variables included in the area range; judging whether the obtained attribute identifiers have specific attribute identifiers corresponding to the custom annotations or not; 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 specifically further configured to obtain a header row corresponding to the Name attribute in the target EXCEL file, and a data value of a column corresponding to the header row; and creating key Value data according to the data Value and the identification of the cell where the data Value are located, and taking the key Value data as a Value corresponding to the Name attribute in the target EXCEL file.
In a specific application scenario, the storage module 34 is specifically configured to obtain a target storage area in the specified EXCEL file in which the table data is to be stored if the preset storage location is the specified EXCEL file; if the target storage area has the target title row corresponding to the Name attribute, sequentially filling the data Value corresponding to each cell identifier into the corresponding cell of the column in the target storage area under the target title row according to the key Value pair data in the Value; if the target storage area does not contain the target title row corresponding to the Name attribute, the target title row is created in the target storage area, and data corresponding to each cell identification are sequentially filled into corresponding cells in the target storage area and in a column under the target title row according to the key Value pair data in the Value.
In a specific application scenario, the device further includes: a display module;
and the display module is used for writing the specified EXCEL file stored with the table data to the front end in a stream form for display.
It should be noted that, other corresponding descriptions of each functional unit related to the EXCEL file data exporting device based on the JAVA reflection mechanism provided in this embodiment may refer to corresponding descriptions in fig. 1 to fig. 2, and are not described herein again.
Based on the above-mentioned methods shown in fig. 1 and 2, correspondingly, the present embodiment further provides a storage medium, on which a computer program is stored, which when executed by a processor, implements the above-mentioned method for exporting EXCEL file data based on JAVA reflection mechanism shown in fig. 1 and 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 (may be a CD-ROM, a U-disk, a mobile hard disk, etc.), and includes several instructions for causing a computer device (may be a personal computer, a server, or a network device, etc.) to execute the method of each implementation scenario of the present application.
Based on the methods shown in fig. 1 and fig. 2 and the virtual device embodiment shown in fig. 3, in order to achieve the above objects, the embodiment of the present application further provides a computer device, which may specifically be a personal computer, a server, a network device, etc., where the entity device includes a storage medium and a processor; a storage medium storing a computer program; a processor for executing a computer program to implement the above-described method for exporting EXCEL file data based on JAVA reflection mechanism as shown in fig. 1 and 2.
Optionally, the computer device may also include a user interface, a network interface, a camera, radio Frequency (RF) circuitry, sensors, audio circuitry, WI-FI modules, and the like. The user interface may include a Display screen (Display), an input unit such as a Keyboard (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., bluetooth interface, WI-FI interface), etc.
It will be appreciated by those skilled in the art that the computer device structure provided in this embodiment is not limited to this physical device, and may include more or fewer components, or may combine certain components, or may be arranged in different components.
The storage medium may also include an operating system, a network communication module. The operating system is a program that manages the physical device hardware and software resources described above, supporting the execution of information handling programs and other software and/or programs. The network communication module is used for realizing communication among all components in the storage medium and communication with other hardware and software in the entity equipment.
From the above description of the embodiments, it will be apparent to those skilled in the art that the present application may be implemented by means of software plus necessary general hardware platforms, or may be implemented by hardware. By applying the technical scheme of the application, the method is equivalent to developing an EXCEL export tool class. And decoupling the functional codes and the service codes, sorting and summarizing the data to be exported in the EXCEL form into a set, and reading the header row and the data of the entity class corresponding to the data to be exported in the set mainly through a JAVA reflection mechanism by using tool classes, and writing the header row and the data out to the front end in a stream form for downloading and displaying. Compared with the traditional code specially written for an Excel table, the implementation of export functions in the embodiment does not need to be concerned when a developer writes the code. Only the tool class is required to be called to generate the corresponding Excel file. 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 the sticky code are avoided. The development efficiency is improved, and excessive redundant codes are not generated.
Those skilled in the art will appreciate that the drawing is merely a schematic illustration of a preferred implementation scenario and that the modules or flows in the drawing are not necessarily required to practice the application. Those skilled in the art will appreciate that modules in an apparatus in an implementation scenario may be distributed in an apparatus in an implementation scenario according to an implementation scenario description, or that corresponding changes may be located in one or more apparatuses different from the implementation scenario. 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-mentioned inventive sequence numbers are merely for description and do not represent advantages or disadvantages of the implementation scenario. The foregoing disclosure is merely illustrative of some embodiments of the application, and the application is not limited thereto, as modifications may be made by those skilled in the art without departing from the scope of the application.
Claims (9)
1. The method for exporting EXCEL file data based on 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 custom notes to entity attributes corresponding to the data to be exported;
according to the custom annotation, table data reading is carried out on the entity class corresponding to the data to be exported through a JAVA reflection mechanism;
Storing the read form data in a preset storage position;
according to the custom annotation, reading table data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism, and specifically comprising the following steps:
acquiring a JAVA class object corresponding to the data to be exported in the target EXCEL file;
Acquiring a Field member variable of the JAVA class object;
Judging whether the custom annotation exists in the entity attribute corresponding to the Field member variable;
And 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 corresponding to the Name attribute in the target EXCEL file as the read form data.
2. The method of claim 1, wherein the obtaining the Field member variable of the JAVA class object comprises:
collecting the identification of the corresponding cell of each JAVA class object in the target EXCEL file;
Defining a regional range in the target EXCEL file through the collected identification of the unit cell;
and querying the member variables contained in the regional range to collect the member variables to obtain the Field member variables.
3. The method of claim 2, wherein the determining whether the custom annotation exists in the entity attribute corresponding to the Field member variable comprises:
parameterizing variable types of the member variables contained in the regional scope by adopting the generic model so as to acquire attribute identifiers of entity attributes corresponding to the member variables contained in the regional scope;
Judging whether the attribute identifier corresponding to the custom annotation exists in the acquired attribute identifiers;
if the attribute identifier corresponding to the custom annotation exists in the acquired attribute identifier, determining that the custom annotation exists in the entity attribute corresponding to the Field member variable.
4. The method of claim 3, wherein the calling a preset Get function extracts a Value corresponding to the Name attribute in the target EXCEL file, and specifically comprises:
Acquiring a header row corresponding to the Name attribute in the target EXCEL file and a data value of a column corresponding to the header row;
and creating key Value data according to the data Value and the identification of the cell where the data Value are located, and taking the key Value data as a Value corresponding to the Name attribute in the target EXCEL file.
5. The method of claim 4, wherein if the predetermined storage location is a specified EXCEL file, the storing the read form data in the predetermined storage location specifically comprises:
Acquiring a target storage area in the appointed EXCEL file, wherein the target storage area is used for storing the form data;
If the target storage area has the target title row corresponding to the Name attribute, sequentially filling the data Value corresponding to each cell identifier into the corresponding cell of the column in the target storage area under the target title row according to the key Value pair data in the Value;
If the target storage area does not contain the target title row corresponding to the Name attribute, the target title row is created in the target storage area, and data corresponding to each cell identification are sequentially filled into corresponding cells in the target storage area and in a column under the target title row according to the key Value pair data in the Value.
6. The method of claim 5, wherein the method further comprises:
And writing the specified EXCEL file stored with the table data to the front end in a stream form for display.
7. An EXCEL file data exporting device based on 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 custom notes to the entity attributes corresponding to the data to be exported;
the reading module is used for reading the table data of the entity class corresponding to the data to be exported through a JAVA reflection mechanism according to the custom annotation;
the storage module is used for storing the read form data in a preset storage position;
the reading module is specifically configured to obtain a JAVA class object corresponding to the data to be exported in the target EXCEL file; acquiring a Field member variable of the JAVA class object; judging whether the custom annotation exists in the entity attribute corresponding to the Field member variable; and 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 corresponding to the Name attribute in the target EXCEL file as the read form data.
8. A non-transitory readable storage medium having stored thereon a computer program, wherein the program when executed by a processor implements the method of exporting EXCEL file data based on JAVA reflection mechanism of any of claims 1 to 6.
9. A 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 of exporting EXCEL file data based on JAVA reflection mechanism according to any of claims 1 to 6 when executing the program.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010126823.4A CN111367976B (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 CN111367976B (en) | 2020-02-28 | 2020-02-28 | Method and device for exporting EXCEL file data based on JAVA reflection mechanism |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111367976A CN111367976A (en) | 2020-07-03 |
CN111367976B true CN111367976B (en) | 2024-07-05 |
Family
ID=71208215
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010126823.4A Active CN111367976B (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) | CN111367976B (en) |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111651221B (en) * | 2020-07-14 | 2022-09-20 | 迈普通信技术股份有限公司 | 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 |
CN112767013A (en) * | 2021-01-05 | 2021-05-07 | 北京锐安科技有限公司 | Business report splitting method, device, server and storage medium |
CN113239106B (en) * | 2021-06-04 | 2023-12-19 | 平安科技(深圳)有限公司 | Excel file export method and device, electronic equipment and storage medium |
CN114528338B (en) * | 2022-01-19 | 2024-05-10 | 浪潮卓数大数据产业发展有限公司 | Method, device, equipment and medium for dynamically exporting field |
CN116776843A (en) * | 2023-06-19 | 2023-09-19 | 北京水脉科技有限公司 | Information form data renewing and merging method |
CN117331960B (en) * | 2023-09-21 | 2024-06-07 | 深圳高灯云科技有限公司 | Method, device, computer equipment and storage medium for generating table file |
Family Cites Families (7)
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 |
CN108415834A (en) * | 2018-02-12 | 2018-08-17 | 平安科技(深圳)有限公司 | Explain rear end method of calibration, device, computer equipment and storage medium |
CN109062883B (en) * | 2018-07-18 | 2022-07-26 | 平安科技(深圳)有限公司 | Data table dynamic derivation method and device, computer equipment and storage medium |
CN109375901A (en) * | 2018-09-03 | 2019-02-22 | 平安普惠企业管理有限公司 | Interface message management method, device, computer equipment and storage medium |
CN109800264B (en) * | 2018-12-27 | 2024-05-31 | 平安科技(深圳)有限公司 | Diversified reporting form export 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 |
-
2020
- 2020-02-28 CN CN202010126823.4A patent/CN111367976B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN111367976A (en) | 2020-07-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111367976B (en) | Method and device for exporting EXCEL file data based on JAVA reflection mechanism | |
US8601438B2 (en) | Data transformation based on a technical design document | |
US20120159312A1 (en) | Representation of an interactive document as a graph of entities | |
CN106354483B (en) | Data processing method and device and electronic equipment | |
CN111126019B (en) | Report generation method and device based on mode customization and electronic equipment | |
CN110580189A (en) | method and device for generating front-end page, computer equipment and storage medium | |
CN110990274A (en) | Data processing method, device and system for generating test case | |
CN111476013A (en) | Information collection method, information collection device, information collection medium, and electronic device | |
US10417234B2 (en) | Data flow modeling and execution | |
CN110969000B (en) | Data merging processing method and device | |
CN105867886B (en) | Method and device for writing table | |
CN117493309A (en) | Standard model generation method, device, equipment and storage medium | |
CN110795464B (en) | Method, device, terminal and storage medium for checking field of object marker data | |
CN111881660A (en) | Report generation method and device, computer equipment and storage medium | |
CN107977459B (en) | Report generation method and device | |
CN116414689A (en) | Interface parameter verification method and system based on reflection mechanism | |
CN113867700B (en) | Model construction method, display platform, server and storage medium | |
CN115617338A (en) | Method and device for quickly generating service page and readable storage medium | |
CN111916164B (en) | Method and device for realizing center-started investigation system in clinical research | |
CN114816408A (en) | Information processing method and device | |
CN115686506A (en) | Data display method and device, electronic equipment and storage medium | |
CN116755684B (en) | OAS Schema generation method, device, equipment and medium | |
US11947563B1 (en) | Systems and methods for collecting and distributing digital experience information | |
CN115545008B (en) | Spectrogram file analyzing method, device, equipment and storage medium | |
CN111090436B (en) | Jenkins compiling result summarizing method, device and equipment |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |