Data export method, device and storage medium
By setting cell commands and annotation commands in the table template, parsing and traversing the data, the problem of non-universality and low efficiency of data export templates is solved, and efficient and convenient data export is achieved.
Patent Information
- Application Number
- CN202011117519.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-19
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2040-10-19
AI Technical Summary
The data export templates in the prior art are not universal and have low export efficiency, especially in scenarios where data export in a specified format is required.
By pre-setting cell commands and comment commands in the table template, the data to be exported is parsed and traversed, and cell styles are automatically applied to achieve efficient data export.
It improves the convenience and efficiency of data export, simplifies the export logic, and realizes the universality of data format and the ability to export with one line of code.
Smart Images

Figure CN113822030B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, and storage medium for exporting data. Background Art
[0002] With the development of the internet, user needs for various systems are becoming increasingly complex and diverse. Simply retrieving data from the system is no longer sufficient. When users need to reconcile accounts, they can export data for a specific time period to an Excel file, where they can easily perform reconciliation operations using filters or Excel formulas. Furthermore, existing data export methods typically involve manually creating objects such as Workbook, Sheet, Row, and Cell in code, writing data to each cell one by one, then specifying an Excel directory to generate the data, and finally creating an Excel file for users to download and save locally. In even more complex scenarios, users have more demanding requirements for exported data, such as requiring a specific font and size, row height and column width, fixed headers, and a specific background color. Manually setting the row height, column width, font, size, and color of the Excel file containing the exported data is not universally applicable and results in inefficient export. Summary of the Invention
[0003] The embodiment of the present application provides a method for exporting data, which overcomes the problem that templates are not universal and the export efficiency is low when exporting data.
[0004] The method includes:
[0005] Obtain the data to be exported and the pre-stored table template;
[0006] Parsing the cell content and cell range of the table template based on the cell commands and annotation commands marked in the table template;
[0007] The data to be exported is traversed, and the data to be exported is added to the table template according to the cell content and the cell range, and the table template after traversal is returned to the interface as an exported table for the user to call.
[0008] Optionally, the table template is created and stored, wherein the step of creating the table template includes:
[0009] Determining that the cell command of the table template is first syntax information, wherein the first syntax information is used to obtain an attribute value of at least one variable;
[0010] The annotation command of the table template is determined to be second grammatical information, wherein the second grammatical information is used to traverse the data to be exported and determine a valid range during the traversal.
[0011] Optionally, personalized information of the table template is set, wherein the personalized information includes row height information, column width information, text information and background color information of the cell.
[0012] Optionally, based on the annotation command, traverse the data to be exported, determine the cell range based on the data to be exported, and name at least one variable in the data to be exported;
[0013] Based on the cell command, obtaining the attribute value of at least one of the variables and adding it to the corresponding cell;
[0014] The current cell style after marking the annotation command, the cell command and setting the personalized information is saved, and based on the current cell style, the data to be exported is traversed to add the data to be exported to the table template.
[0015] In another embodiment of the present invention, a data export device is provided, the device comprising:
[0016] An acquisition module is used to obtain the data to be exported and the pre-stored table template;
[0017] A parsing module, configured to parse the cell content and cell range of the table template based on the cell commands and annotation commands marked in the table template;
[0018] A generation module is used to traverse the data to be exported, add the data to be exported to the table template according to the cell content and the cell range, and return the table template after traversal as an exported table to the interface for user calling.
[0019] Optionally, the device further includes a creation module, wherein the creation module is configured to:
[0020] Determining that the cell command of the table template is first syntax information, wherein the first syntax information is used to obtain an attribute value of at least one variable;
[0021] The annotation command of the table template is determined to be second grammatical information, wherein the second grammatical information is used to traverse the data to be exported and determine a valid range during the traversal.
[0022] Optionally, the creation module is further configured to:
[0023] The personalized information of the table template is set, wherein the personalized information includes the row height information, column width information, text information and background color information of the cell.
[0024] Optionally, the generating module is further configured to:
[0025] Based on the annotation command, traverse the data to be exported, determine the cell range based on the data to be exported, and name at least one variable in the data to be exported;
[0026] Based on the cell command, obtaining the attribute value of at least one of the variables and adding it to the corresponding cell;
[0027] The current cell style after marking the annotation command, the cell command and setting the personalized information is saved, and based on the current cell style, the data to be exported is traversed to add the data to be exported to the table template.
[0028] In another embodiment of the present invention, a non-transitory computer-readable storage medium is provided, wherein the non-transitory computer-readable storage medium stores instructions, which, when executed by a processor, cause the processor to perform the steps in the above-mentioned data export method.
[0029] In another embodiment of the present invention, a terminal device is provided, including a processor, wherein the processor is configured to execute each step in the above-mentioned data export method.
[0030] Based on the above embodiment, first, the data to be exported and the pre-stored table template are obtained. Secondly, based on the cell commands and annotation commands marked in the table template, the cell content and cell range of the table template are parsed. Finally, the data to be exported is traversed and added to the table template according to the cell content and cell range. The table template after traversal is returned to the interface as an exported table for the user to call. The embodiment of the present application improves the convenience and efficiency of exporting data by setting a table template with marked cell commands and annotation commands, traversing the data to be exported and adding it to the table template. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0032] Figure 1A schematic flow chart of a data export method provided in embodiment 100 of the present application is shown;
[0033] Figure 2 A schematic diagram showing a specific process of a data export method provided in embodiment 200 of the present application;
[0034] Figure 3 A schematic diagram showing an apparatus for exporting data is further provided in embodiment 300 of the present application;
[0035] Figure 4 A schematic diagram of a terminal device provided in embodiment 400 of the present application is shown. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0037] The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the implementation of the invention described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or apparatus that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or are inherent to these processes, methods, products or apparatus.
[0038] Based on the problems in the prior art, an embodiment of the present application provides a method for data export, which is mainly applicable to the field of computer technology. By directly filling in variable placeholders in cells, describing the syntax of the annotation function of the table template according to the syntax convention, and using this table template as the export template, the code reads this table template file, parses the syntax commands in the annotation, and automatically reuses the style of each cell, thereby simplifying the complex export operation to realize a method for data export. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. Figure 1, which is a flow chart of a method for exporting data provided by embodiment 100 of the present application. The scenario of the embodiment of the present application is mainly an indoor scenario where voice control of smart devices is possible. The detailed steps are as follows:
[0039] Step S11: obtaining the data to be exported and the pre-stored table template.
[0040] In this step, the data to be exported is multiple data sets that users need to visualize or manipulate, such as order data from an e-commerce website. The pre-stored table templates are personalized, with cell and comment commands marked. The table templates are saved in the configuration center, where a download path is provided.
[0041] Step S12: parsing the cell content and cell range of the table template based on the cell commands and annotation commands marked in the table template.
[0042] In this step, the cell commands and annotation commands are pre-marked in the table template obtained through the download path. Based on the obtained data to be exported and cell commands, the cell contents of each cell in the table template are parsed, and based on the annotation commands, the cell range of the data to be exported involved in the table template is parsed.
[0043] Step S13, traverse the data to be exported, add the data to be exported to the table template according to the cell content and cell range, and return the table template after traversal as an exported table to the interface for the user to call.
[0044] In this step, the data to be exported is traversed using the cell content and cell range of the table template that has been parsed above, and the specific values of the content of the data to be exported are obtained within the cell range that matches the exported data, thereby generating an exported table. Furthermore, the generated exported table is uploaded to a server or cloud storage, and the file download address is returned to the interface as an output parameter, so that the interface caller can call the exported table.
[0045] As described above, based on the above embodiment, first, the data to be exported and the pre-stored table template are obtained. Secondly, based on the cell commands and annotation commands marked in the table template, the cell content and cell range of the table template are parsed. Finally, the data to be exported is traversed, and the data to be exported is added to the table template according to the cell content and cell range. The table template after traversal is returned to the interface as an exported table for the user to call. The embodiment of the present application improves the convenience and efficiency of exporting data by setting a table template for marking cell commands and annotation commands, traversing the data to be exported and adding it to the table template.
[0046] like Figure 2FIG. 2 is a schematic diagram of a specific process of a data export method provided in Example 200 of the present application. The detailed process of the specific process is as follows:
[0047] S201, determining syntax information of cell commands and comment commands of a table template.
[0048] Here, the cell command of the table template is determined to be the first syntax information, wherein the first syntax information is used to obtain the property value of at least one variable; the annotation command of the table template is determined to be the second syntax information, wherein the second syntax information is used to traverse the data to be exported and determine the effective range during the traversal. Specifically, the first syntax information of the cell command carried by the table template is determined to be ${variable.property}, and the first syntax information means to obtain the property attribute value of the variable variable. In addition, the second syntax information of the annotation command carried by the table template is determined to be ex:for(variable incollection),last:A2, which means to traverse each data in the data set collection of the data to be exported, and name the variable in each data item as variable, and the cells traversed are the range from the current cell to the A2 cell.
[0049] S202: Create a table template based on the determined cell command and comment command.
[0050] Here, create a blank table template. Based on the cell commands and the data to be exported, enter a cell command in the first blank cell to retrieve at least one attribute value of the data to be exported. For example, if the data to be exported includes two attributes, the cell command ${item.orderId} to retrieve the order number attribute value is entered in the first cell, and the cell command ${item.price} to retrieve the order amount is entered in the second cell. Furthermore, add a comment command to the first cell, annotating it in the table template according to the agreed-upon second syntax information (e.g., for(item in list),last:A2).
[0051] S203: Set personalized information of the table template.
[0052] In this step, personalized information of the table template is set, wherein the personalized information includes row height information, column width information, text information and background color information of the cell.
[0053] S204, saving the table template and generating a file download address for the table template.
[0054] Here, the set table template is saved and the file is uploaded to the server or cloud storage to generate the download address of the file corresponding to the table template. Further, the download address of the table template is configured in the configuration center.
[0055] S205: Obtain the data to be exported.
[0056] Here, the user-selected data to be exported is retrieved and its attribute values are queried. For example, if the user selects 300 order records, the query reveals that each order record contains two attribute values: the order ID (orderId) and the order amount (price). Furthermore, the retrieved data to be exported is aggregated into a collection (listA).
[0057] S206: Acquire a pre-stored template table.
[0058] Here, the template table download address is obtained from the configuration center, the template table is downloaded from the download address, and the cells are parsed one by one. If the cell content is empty, the parsing stops.
[0059] S207: parsing the cell content and cell range of the table template based on the cell commands and comment commands marked in the table template, and adding the data to be exported to the table template according to the cell commands and comment commands.
[0060] In this step, based on the annotation command, the data to be exported is traversed, and the cell range is determined based on the data to be exported, and at least one variable in the data to be exported is named; based on the cell command, the attribute value of at least one variable is obtained and added to the corresponding cell; the current cell style after marking the annotation command, cell command and setting the personalized information is saved, and based on the current cell style, the data to be exported is traversed to add the data to be exported to the table template.
[0061] Specifically, the annotation command for the first cell is first parsed as ex:for(item in list),last:A2, which means that the order collection listA, the data to be exported, is traversed as the item to be traversed, and each order record object is named item. Next, the cell command from the current cell to cell A2 is parsed, and the variables obtained are ${item.orderId} and ${item.price}, respectively. Then, through the Java reflection mechanism, the get methods of the orderId and price properties in the data to be exported are retrieved to obtain their values. Furthermore, cells are automatically generated, and according to the for traversal command, new cells are automatically generated in the same style as the current cell and inserted as new rows below the current row. This process is repeated until the collection is traversed.
[0062] S208: After traversing the data to be exported, the table template is returned to the interface as an exported table for the user to call.
[0063] Here, the generated file is uploaded to the cloud storage through the cloud storage interface, and the file download address is returned to the interface caller as an output parameter, thus completing the export task.
[0064] A data export method shown in an embodiment of the present application pre-stores a set table template, agrees on variable names, and uploads the table template to cloud storage. The core logic of the export is encapsulated in an interface, which only accepts two external input parameters: a collection object to be traversed, and the path to obtain the table template on the cloud storage. In addition, through the interface call, the data can be parsed into the table template, and the download path of the new table template is returned to the caller as an output parameter. This greatly simplifies the logic of data export, realizes the ability to export data with one line of code, and avoids the accumulation of a large amount of export logic code. At the same time, the table template can be generalized and packaged as a jar package for use by other application systems. In addition, the style of the table template is intuitive. Each time the style is adjusted, the table template is directly operated. Therefore, the style of the data file ultimately exported is the same as the style of the table template. When exporting, Excel export can be implemented by calling a single line of code, without manually setting fonts, colors, column widths, row heights, and other styles through code. Style configuration can be achieved by directly dragging the row height and column width on the table template. Furthermore, the download address of the table template is placed in the configuration center. Each time the table template is modified, you only need to replace the file on the cloud storage. When exporting, the download address will be obtained through the configuration center to download the latest template file, saving development costs.
[0065] Based on the same inventive concept, the embodiment 300 of the present application further provides a data export device, wherein, Figure 3 As shown, the device includes:
[0066] An acquisition module 31 is used to acquire data to be exported and a pre-stored table template;
[0067] The parsing module 32 is used to parse the cell content and cell range of the table template based on the cell commands and annotation commands marked in the table template;
[0068] The generation module 33 is used to traverse the data to be exported, add the data to be exported to the table template according to the cell content and cell range, and return the table template after traversal as an exported table to the interface for the user to call.
[0069] In this embodiment, the specific functions and interaction modes of the acquisition module 31, the analysis module 32 and the generation module 33 can be found in Figure 1 The description of the corresponding embodiments will not be repeated here.
[0070] Optionally, the apparatus further includes a creation module 34, the creation module 34 being configured to:
[0071] Determining that a cell command of the table template is first syntax information, wherein the first syntax information is used to obtain an attribute value of at least one variable;
[0072] The annotation command of the table template is determined to be the second syntax information, wherein the second syntax information is used to traverse the data to be exported and determine the valid range during the traversal.
[0073] Optionally, the creation module 34 is further configured to:
[0074] The personalized information of the table template is set, wherein the personalized information includes the row height information, column width information, text information and background color information of the cell.
[0075] Optionally, the generating module 33 is further configured to:
[0076] Based on the annotation command, traverse the data to be exported, determine the cell range based on the data to be exported, and name at least one variable in the data to be exported;
[0077] Based on a cell command, obtaining the attribute value of at least one variable and adding it to the corresponding cell;
[0078] The current cell style after saving the annotation command, cell command and setting personalized information is saved, and based on the current cell style, the data to be exported is traversed to add the data to be exported to the table template.
[0079] like Figure 4 As shown, another embodiment 400 of the present application further provides a terminal device, including a processor 401, wherein the processor 401 is configured to execute the steps of the above-mentioned data export method. Figure 4 As can be seen, the terminal device provided in the above embodiment also includes a non-transitory computer-readable storage medium 402, on which a computer program is stored. When the computer program is executed by the processor 401, the computer program executes the steps of the above-mentioned data export method. In actual applications, the terminal device can be one or more computers, as long as it includes the above-mentioned computer-readable medium and processor.
[0080] Specifically, the storage medium can be a general storage medium, such as a mobile disk, a hard disk, and FLASH. When the computer program on the storage medium is run, each step in the above-mentioned method of exporting data can be executed. In practical applications, the computer-readable medium can be included in the device / apparatus / system described in the above embodiments, or it can exist independently without being assembled into the device / apparatus / system. The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed, each step in the above-mentioned method of exporting data can be executed.
[0081] According to the embodiments disclosed in the present application, the computer-readable storage medium may be a non-volatile computer-readable storage medium, such as, but not limited to, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof, but is not intended to limit the scope of protection of the present application. In the embodiments disclosed in the present application, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0082] The flowcharts and block diagrams in the accompanying drawings of the present application illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to the various embodiments disclosed in the present application. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in the order marked in different figures. For example, the boxes represented by two connections can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of the boxes in the block diagram or flowchart, can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0083] Those skilled in the art will appreciate that the features described in the various embodiments and / or claims of this disclosure may be combined and / or coupled in various ways, even if such combinations and / or couplings are not explicitly described in this application. In particular, without departing from the spirit and teachings of this application, the features described in the various embodiments and / or claims of this application may be combined and / or coupled in various ways, and all such combinations and / or couplings fall within the scope of this application.
[0084] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The scope of protection of the present application is not limited thereto. Although the present application has been described in detail with reference to the above-described embodiments, those skilled in the art should understand that any person skilled in the art can still make changes to the technical solutions described in the above-described embodiments within the technical scope disclosed in the present application, or make equivalent replacements for some of the technical features thereof. However, these changes, modifications, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the scope of protection of the claims.
Claims
1. A method for exporting data, characterized in that: include: Creating and storing a table template, wherein the step of creating the table template includes: Determining that a cell command of the table template is first syntax information, wherein the first syntax information is used to obtain an attribute value of at least one variable; Determining that the annotation command of the table template is second syntax information, wherein the second syntax information is used to traverse the data to be exported and determine a valid range during the traversal; Create a blank table template, and based on the cell command and the data to be exported, fill in the first cell of the blank cells with a cell command indicating obtaining the attribute value of at least one variable of the data to be exported; add a comment command to the first cell and mark it in the table template according to the second syntax information; Obtain the data to be exported and the pre-stored table template; Parsing the cell content and cell range of the table template based on the cell commands and comment commands marked in the table template; wherein, based on the comment commands, traversing the data to be exported, determining the cell range based on the data to be exported, and naming at least one of the variables in the data to be exported; and based on the cell commands, obtaining the attribute value of at least one of the variables and adding it to the corresponding cell; The data to be exported is traversed, and the data to be exported is added to the table template according to the cell content and the cell range, and the table template after traversal is returned to the interface as an exported table for the user to call.
2. The method according to claim 1, characterized in that The step of creating the table template further comprises: The personalized information of the table template is set, wherein the personalized information includes the row height information, column width information, text information and background color information of the cell.
3. The method according to claim 2, characterized in that The step of adding the data to be exported to the table template according to the cell content and the cell range includes: The current cell style after marking the annotation command, the cell command and setting the personalized information is saved, and based on the current cell style, the data to be exported is traversed to add the data to be exported to the table template.
4. A data export device, characterized in that: include: Create modules for: Determining that a cell command of the table template is first syntax information, wherein the first syntax information is used to obtain an attribute value of at least one variable; Determining that the annotation command of the table template is second syntax information, wherein the second syntax information is used to traverse the data to be exported and determine a valid range during the traversal; Create a blank table template, and based on the cell command and the data to be exported, fill in the first cell of the blank cells with a cell command indicating obtaining the attribute value of at least one variable of the data to be exported; add a comment command to the first cell and mark it in the table template according to the second syntax information; An acquisition module is used to obtain the data to be exported and the pre-stored table template; a parsing module, configured to parse the cell content and cell range of the table template based on the cell commands and annotation commands marked in the table template; wherein, based on the annotation commands, the data to be exported is traversed, the cell range is determined based on the data to be exported, and at least one variable in the data to be exported is named; and based on the cell commands, the attribute value of at least one variable is obtained and added to the corresponding cell; A generation module is used to traverse the data to be exported, add the data to be exported to the table template according to the cell content and the cell range, and return the table template after traversal as an exported table to the interface for user calling.
5. The device according to claim 4, characterized in that The creation module is further configured to: The personalized information of the table template is set, wherein the personalized information includes the row height information, column width information, text information and background color information of the cell.
6. The device according to claim 5, characterized in that The generating module is further configured to: The current cell style after marking the annotation command, the cell command and setting the personalized information is saved, and based on the current cell style, the data to be exported is traversed to add the data to be exported to the table template.
7. A non-transitory computer-readable storage medium, characterized in that The non-transitory computer-readable storage medium stores instructions, which, when executed by a processor, enable the processor to perform the steps of the data deriving method according to any one of claims 1 to 3.
8. A terminal device, characterized in that: The method comprises a processor configured to execute each step in a data export method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Template and tag implementation based excel display and export method and system
CN103914438A
Form generation method and device, electronic equipment and computer readable storage medium
CN110941614A
Report generation method and device, terminal equipment and storage medium
CN111611784A