Method and system for exporting dynamic packet header excel based on xlsx, terminal and medium

By building the tree structure of the table header and automatically calculating related parameters, the efficiency and accuracy of dynamic grouping table header excel export is solved, and efficient and accurate data export and adaptability are achieved.

CN120181053APending Publication Date: 2025-06-20SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510377338.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-28
Publication Date
2025-06-20

AI Technical Summary

Technical Problem

The prior art is difficult to effectively deal with the excel export of dynamic grouped table headers, especially in the case of real-time changes in the header structure and content, resulting in data loss or error mapping.

Method used

By building the tree structure of the table header, the relevant parameters are automatically calculated, such as the maximum depth, the number of extended rows and columns, and the maximum width, and then the incoming parameters and configuration information are automatically constructed, and directly passed to the xlsx library for export.

Benefits of technology

Improves data export efficiency and accuracy, reduces template configuration and maintenance costs, adapts to changes in dynamic grouping headers, and avoids data loss or error mapping.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120181053A_ABST
    Figure CN120181053A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of data processing, and particularly relates to a method, a system, a terminal and a medium for exporting a dynamic packet header excel based on xlsx, and the method comprises the following steps: constructing a data structure of a one-dimensional node array; traversing the node array, and calculating the maximum depth of a grouping header, the number of extended rows of each node, the number of extended columns of each node and the maximum width of the node array according to node attributes; dividing the node array according to the depth hierarchy of the nodes, wherein the depth hierarchy is used for representing the hierarchical relationship of the nodes in the tree structure; according to the maximum depth of the packet header, the number of extended rows of each node, the number of extended columns of each node and the maximum width of the node array, constructing and merging cell configuration information and incoming data for transmitting parameters to an xlsx library; and the merged cell configuration information and the incoming data are transmitted into an xlsx library to export an excel file. The data export efficiency and accuracy are improved, no template needs to be configured, and the maintenance cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of Excel data processing, and particularly relates to a method, system, terminal and medium for exporting an Excel with a dynamic grouped header based on XLSX. Background Art

[0002] For the requirement of using pure front-end technology to export tabular data in the Excel file format, front-end developers usually use the xlsx library to complete it. The xlsx library needs to pass in data in the form of a two-dimensional array, including the header and the table body data. Obviously, the table body data does not involve the situation of merging cells, but for the grouped header, the operation of merging cells is required. For the xlsx library, to merge cells, corresponding configurations need to be passed in to indicate the cells to be merged, and the filled content of the merged cell group will default to the content of the first cell. For a grouped header with a known structure, the maximum depth and maximum width of the grouped header, as well as the positions of the merged cells in the two-dimensional array, can be calculated manually. At the same time, the cell groups to be merged can also be sorted out, and then the corresponding configurations can be passed in to export the tabular data with a grouped header.

[0003] However, for a dynamic grouped header, its structure and content will change in real time according to different conditions (such as user operations, data changes or business logics). For example, in a data analysis system, users can freely select different analysis dimensions, which will cause the grouping method and specific content of the header to change at any time. In this case, information such as the hierarchical depth, width of the header, and positions of the cells to be merged is difficult to predict. Therefore, it is impossible to obtain the required configuration data through manual calculation like dealing with a fixed-structure header. Related technologies map the data of the dynamic grouped header to a preset template structure and automatically generate configuration data through the rules of the template. For example, define the processing methods of different types of nodes in the template. When the dynamic header data is passed in, it is converted into the corresponding two-dimensional array and merged cell configuration according to the template rules. However, it is necessary to design a template in advance to standardize the data mapping. However, the dynamic grouped header is diverse, and when a new header structure or data type appears, the template may not be adaptable and needs to be modified and adjusted frequently. The structure and hierarchical relationship of the dynamic grouped header are complex, it is difficult to formulate perfect mapping rules, and with the development and change of the business, the rule maintenance cost is high. Moreover, during the mapping process, if the header data does not match the template, data loss or incorrect mapping may occur. Summary of the Invention

[0004] To solve the above problems, the present invention provides a method, system, terminal and medium for exporting dynamic grouped header excel based on xlsx, which can automatically calculate relevant parameters according to the tree structure of the header, and then automatically construct input parameters and configuration information according to the relevant parameters, improve the data export efficiency and accuracy, and do not require template configuration, reducing the maintenance cost.

[0005] In a first aspect, the technical solution of the present invention provides a method for exporting dynamic grouped header excel based on xlsx, including the following steps: Construct a data structure of a one-dimensional node array, where each node element in the node array is a group of headers, and each is a structure of a tree node formed according to the header level information. The tree node has a necessary header identification attribute and an optional child node attribute, and the child node attribute represents the set of child nodes of the tree node; Traverse the node array, and calculate the maximum depth of the grouped header, the extended rows of each node, the extended columns of each node, and the maximum width of the node array according to the node attributes; Divide the node array according to the depth level of the nodes, and the depth level is used to represent the hierarchical relationship of the nodes in the tree structure; Construct merged cell configuration information and input data for passing parameters to the xlsx library according to the maximum depth of the grouped header, the extended rows of each node, the extended columns of each node, and the maximum width of the node array; Pass the merged cell configuration information and input data into the xlsx library to export the excel file.

[0006] In an optional embodiment, traversing the node array and calculating the maximum depth of the grouped header according to the node attributes specifically includes: Initialize the return value of the current node element to 1; Traverse the child node attribute of the current node element. For each layer of child nodes obtained, add 1 to the depth value of the current child node layer and compare it with the current return value, and take the larger value to update the current return value. The final return value is the depth of the current node element; Compare the depths of all node elements, and take the maximum value as the maximum depth of the grouped header.

[0007] In an optional embodiment, traversing the node array and calculating the extended rows of each node according to the node attributes specifically includes: Traverse the tree node structure of each node element in the node array. For the current tree node, judge whether it is a leaf node according to its child node attribute. If it is a leaf node, calculate the extended rows of the current tree node as the maximum depth of the grouped header minus the depth of the current tree node plus 1; if it is not a leaf node, determine that the extended rows of the current tree node is 1.

[0008] In an alternative embodiment, traverse the node array and calculate the extended column count of each node and the maximum width of the node array according to the node attributes, specifically including: Traverse the tree node structure of each node element in the node array. For the current tree node, determine whether it is a leaf node according to its child node attributes. If it is a leaf node, determine that the extended column count of the current tree node is 1; if it is not a leaf node, calculate the extended column count of the current tree node as the sum of the extended column counts of all its child nodes; Calculate the maximum width of the node array as the sum of the extended column counts of all root nodes.

[0009] In an alternative embodiment, divide the node array according to the depth levels of the nodes, specifically including: Traverse the tree node structure of each node element in the node array. For the current tree node, place it in the corresponding depth level node set according to the depth level of the current tree node.

[0010] In an alternative embodiment, construct the input data for passing parameters to the xlsx library according to the maximum depth of the grouped table header, the extended row counts of each node, the extended column counts of each node, and the maximum width of the node array, specifically including: Construct a two-dimensional array and initialize each item as an empty string. The number of rows of the two-dimensional array is the maximum depth of the grouped table header, and the number of columns is the maximum width of the node array; Traverse each depth level node set. In each loop, initialize the position index variable to 0. The position index variable represents the current column in the corresponding two-dimensional array; For the current depth level node set, first use a while loop in the loop to update the position index variable, incrementing the position index variable by 1 each time until the data item at the corresponding row and column position in the two-dimensional array is not an empty string; the current row and column position is the row corresponding to the current depth level, and the column corresponding to the current position index variable; At this time, judge the extended row count and extended column count of the current node to fill the two-dimensional array, including the number of filled cells from the current row position downwards is the extended row count of the current node, and the number of filled cells from the current column position backwards is the extended column count of the current node.

[0011] In an alternative embodiment, construct the merged cell configuration information according to the maximum depth of the grouped table header, the extended row counts of each node, the extended column counts of each node, and the maximum width of the node array, specifically including: Construct an object array, where each item in the object array represents a cell block to be merged; Perform a double traversal on the depth level node set, and each item in the loop is a node; Find the first column index in the two-dimensional array to fill the header identification attribute of the current node; Detect the extended row number and extended column number of the current node; If the extended row number is greater than 1 and the extended column number is 1, the starting abscissa of the cell block of the current node is the depth level where the current node is located, the ending abscissa is the depth level where the current node is located plus the extended row number, and the ordinate is the first column index; If the extended column number is greater than 1 and the extended row number is 1, the abscissas of the cell block of the current node are all the depth levels where the current node is located, the starting ordinate is the first column index, and the ending ordinate is the first column index plus the extended column number minus 1.

[0012] In a second aspect, the technical solution of the present invention provides a system for exporting a dynamic grouped header excel based on xlsx, including: A node array construction module, which is used to construct a data structure of a one-dimensional node array. Each node element in the node array is a group of headers, and each is a tree node structure formed according to the header level information. The tree node has a necessary header identification attribute and an optional child node attribute, and the child node attribute represents the set of child nodes of the tree node; A node parameter calculation module, which is used to traverse the node array and calculate the maximum depth of the grouped header, the extended row numbers of each node, the extended column numbers of each node, and the maximum width of the node array according to the node attributes; A depth level division module, which is used to divide the node array according to the depth level of the nodes. The depth level is used to represent the hierarchical relationship of the nodes in the tree structure; An input parameter and configuration construction module, which is used to construct merged cell configuration information and input data for passing parameters to the xlsx library according to the maximum depth of the grouped header, the extended row numbers of each node, the extended column numbers of each node, and the maximum width of the node array; An excel file export module, which is used to pass the merged cell configuration information and input data into the xlsx library to export an excel file.

[0013] In a third aspect, the technical solution of the present invention provides a terminal, including: A memory, which is used to store a program for exporting a dynamic grouped header excel based on xlsx; A processor, which is used to implement the steps of the method for exporting a dynamic grouped header excel based on xlsx as described in any one of the above when executing the program for exporting a dynamic grouped header excel based on xlsx.

[0014] Fourthly, the technical solution of the present invention provides a computer-readable storage medium, on which a program for exporting an Excel with a dynamic grouped header based on XLSX is stored. When the program for exporting an Excel with a dynamic grouped header based on XLSX is executed by a processor, the steps of the method for exporting an Excel with a dynamic grouped header based on XLSX as described in any one of the above are implemented.

[0015] As can be seen from the above technical solutions, the present application has the following advantages: constructing a tree structure of the header, configuring attributes for each tree node, then automatically calculating depth, width, and extended row and column number information according to the node attributes, dividing the nodes by depth level, and on this basis constructing input parameters and configuration information, so as to export data. The present invention first constructs a specific one-dimensional node array data structure, and calculates the relevant parameters of the grouped header by traversing the node array, without manually calculating the configuration data, reducing the manual calculation cost and the probability of errors, and improving the efficiency and accuracy of data processing. At the same time, the node array is divided by depth level, and the merged cell configuration information and the incoming data are constructed in combination with the calculated parameters, which can adapt to the structural and content changes of the dynamic grouped header caused by user operations, data changes, or business logic adjustments. Compared with the related technology that relies on a preset template, this solution does not need to frequently modify the template, avoiding data loss or incorrect mapping problems caused by template mismatch, and enhancing the compatibility and adaptability to different dynamic headers. Furthermore, through the systematic calculation and construction process, the merged cell configuration information and the incoming data that meet the requirements of the XLSX library can be accurately generated, ensuring that the dynamic grouped header in the exported Excel file is displayed correctly and the data presentation meets the expectations, providing users with a high-quality data display and analysis tool. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the present application, the drawings required to be used in the description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0017] Figure 1 It is a schematic flowchart of a method for exporting an Excel with a dynamic grouped header based on XLSX provided by an embodiment of the present invention.

[0018] Figure 2 It is a schematic diagram of an Excel.

[0019] Figure 3 For Figure 2 a schematic diagram of a one-dimensional node array of the Excel table in

[0020] Figure 4A schematic block diagram of a system for exporting an Excel with a dynamic grouped header based on XLSX provided by an embodiment of the present invention.

[0021] Figure 5 A schematic structural diagram of a terminal provided by an embodiment of the present invention. Detailed implementation manners

[0022] To make the application purpose, features, and advantages of the present application more obvious and understandable, the technical solutions protected by the present application will be clearly and completely described below by using specific embodiments and the accompanying drawings. Obviously, the embodiments described below are only a part of the embodiments of the present application, rather than all embodiments. Based on the embodiments in this patent, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of this patent.

[0023] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which this invention belongs. The terms used in the description of this invention herein are only for the purpose of describing specific embodiments and are not intended to limit this invention.

[0024] Figure 1 A schematic flowchart of a method for exporting an Excel with a dynamic grouped header based on XLSX provided by an embodiment of the present invention. Among them, Figure 1 The execution subject can be a system for exporting an Excel with a dynamic grouped header based on XLSX. The method for exporting an Excel with a dynamic grouped header provided by an embodiment of the present invention is executed by a computer device. Correspondingly, the system for exporting an Excel with a dynamic grouped header runs in the computer device. According to different requirements, the order of the steps in this flowchart can be changed, and some can be omitted.

[0025] As Figure 1 shown, the method includes the following steps.

[0026] S1. Construct a data structure of a one-dimensional node array, where each node element in the node array is a group of headers, and each is a structure of a tree node formed according to the header level information.

[0027] The tree node has a necessary header identification attribute and an optional child node attribute. The child node attribute represents the set of child nodes of the tree node. It should be noted that the headers include ordinary headers and grouped headers. The ordinary header has only a root node, and the grouped header has a root node, child nodes, and even grandchild nodes. The set of child nodes includes at least two child nodes. The child nodes have a necessary identity identification attribute and an optional grandchild node attribute, and so on.

[0028] In this step, by constructing a specific data structure, the dynamic grouped table headers are organized in a tree structure to represent the hierarchical relationship of the table headers, providing a data basis for subsequent parameter calculation and data processing.

[0029] S2. Traverse the node array, and calculate the maximum depth of the grouped table headers, the extended row numbers of each node, the extended column numbers of each node, and the maximum width of the node array according to the node attributes.

[0030] In this step, traverse the node array, and calculate the maximum depth of the grouped table headers, the extended row numbers and column numbers of each node, and the maximum width of the node array according to the node attributes. The maximum depth reflects the hierarchical depth of the table headers. The extended row numbers and column numbers are used to determine the cell merging and data filling ranges. The maximum width determines the number of columns in the two-dimensional array. By automatically calculating these key parameters, the cumbersome and error-prone manual calculation is avoided, and the data processing efficiency is improved. At the same time, the calculation results of the parameters can reflect the structural characteristics of the dynamic grouped table headers, providing an accurate basis for constructing the incoming data that meets the requirements and the merged cell configuration information subsequently, ensuring the correct structure of the table headers in the exported excel file.

[0031] S3. Divide the node array according to the depth levels of the nodes, where the depth levels are used to represent the hierarchical relationship of the nodes in the tree structure.

[0032] In this step, according to the hierarchical relationship of the nodes in the tree structure (i.e., the depth levels), each node in the node array is divided into the corresponding hierarchical set. After the division, the nodes at different depth levels are classified and managed, which is convenient for subsequent processing of the nodes at different levels respectively. For example, when constructing data and configuring merged cells, targeted operations can be carried out according to the hierarchical characteristics, and the overall processing logic and orderliness are also improved.

[0033] S4. Construct the merged cell configuration information and the incoming data for passing parameters to the xlsx library according to the maximum depth of the grouped table headers, the extended row numbers of each node, the extended column numbers of each node, and the maximum width of the node array.

[0034] In this step, use the parameters such as the maximum depth of the grouped table headers, the extended row numbers and column numbers of each node, and the maximum width of the node array calculated previously to construct the merged cell configuration information and the incoming data for the xlsx library. Among them, the incoming data is presented in the form of a two-dimensional array, and the merged cell configuration information specifies the cell ranges to be merged. Generate the information adapted to the xlsx library according to the structural characteristics of the dynamic grouped table headers to ensure that the data can be correctly imported into the xlsx library. By correctly configuring the merged cells and standardizing the incoming data, ensure that the merged cell effect of the table headers in the exported excel file is correct, the data display meets the expectations, and the format requirements of the dynamic grouped table header excel file are met for users.

[0035] S5, Pass the merged cell configuration information and the incoming data into the xlsx library to export an Excel file.

[0036] In this step, the constructed merged cell configuration information and the incoming data are passed into the xlsx library to complete the export operation of the Excel file. It realizes the complete process from data processing to file export, providing the user with a directly usable Excel file. The exported file has a clear header structure and accurate data, facilitating the user's data analysis, display, and sharing, and meeting the user's requirement to export an Excel file with a dynamic grouped header using pure front-end technology.

[0037] Furthermore, as a refinement and extension of the specific implementation manner of the above embodiment, to fully illustrate the specific implementation process in this embodiment, another method for exporting an Excel with a dynamic grouped header based on xlsx is provided. This method provides a set of well-encapsulated utility functions that can be directly used in the required scenarios for exporting a dynamic grouped header. This method includes the following steps.

[0038] SS1, Construct a data structure of a one-dimensional node array.

[0039] Each node element in the node array is a group of headers, and each is a tree node structure formed according to the header level information. The tree node has a mandatory header identification attribute and an optional child node attribute, and the child node attribute represents the set of child nodes of the tree node.

[0040] Specifically, first define the parameter information of the utility function. The most intuitive data structure for grouped headers is a one-dimensional node array, where each node is a tree node structure with a mandatory attribute name (assuming name is unique here) representing the name of the header, and an optional attribute children representing the set of its child nodes. At the same time, the children attribute also identifies the type of the node: whether it is a leaf node. The above is the parameter information of the utility function.

[0041] Figure 2 For an Excel schematic diagram, Figure 3 For Figure 2 the schematic diagram of the one-dimensional node array of the Excel table in, the headers include ordinary headers and grouped headers. The ordinary header has only a root node, and the grouped header has a root node, child nodes, and even grandchild nodes. The set of child nodes includes at least two child nodes, and the child node has a mandatory identity identification attribute and an optional grandchild node attribute, and so on. In Figure 2 and Figure 3 the ordinary headers include name, ID number, and gender, and the grouped header includes work information. The work information includes three child nodes: work unit, work address, and salary. These three child nodes form the set of child nodes of the work information node.

[0042] SS2, calculate the maximum depth of the grouped table header.

[0043] The maximum depth refers to the maximum value of the depths of all nodes in the node array parameter. Specifically, it can be split into two steps: (1) Calculate the depth of each node; (2) Find the maximum value among these node depths. When processing the export of Excel data for dynamic grouped table headers, the maximum depth of the grouped table header is a key parameter. It determines the number of rows in the header part of the final generated Excel table and plays an important role in constructing a two-dimensional array data structure and determining the range of merged cells. The following steps are included.

[0044] SS2.1, Initialize the return value of the current node element to 1.

[0045] This is based on the fact that each node has at least the depth of its own layer, providing a starting value for subsequent calculations.

[0046] SS2.2, Traverse the child node attribute of the current node element. For each layer of child nodes obtained, add 1 to the depth value of the current child node layer and compare it with the current return value, and take the larger value to update the current return value. The final return value is the depth of the current node element.

[0047] For example, if a node has two layers of child nodes, during the depth calculation process, when encountering the first layer of child nodes, the depth value is incremented by 1, and when encountering the second layer of child nodes, the depth value is incremented by 1 again, finally determining the depth of the node.

[0048] SS2.3, Compare the depths of all node elements and take the maximum value as the maximum depth of the grouped table header.

[0049] After calculating the depths of all node elements, find the maximum value among these depths through comparison. This maximum value is the maximum depth of the grouped table header.

[0050] Specifically, define a utility function getTreeDepth to calculate the depth of a node. The utility function needs to pass in the node to be calculated and initialize the return value to 1 because the node has at least its own layer of depth. Traverse the children attribute of the node, and recursively call getTreeDepth for each child node to obtain the depths of these child nodes. For each depth of a child node obtained, increment it by 1 and compare it with the current return value, and take the larger value to update the current return value. When the entire tree is recursively traversed, the final return value is the depth of this node. Call the above utility function for each node in the node array to obtain its depth, and then find the maximum depth and save it as a global static variable maxDepth.

[0051] This step accurately calculates the maximum depth of the grouped header to ensure that the number of rows in the header part is set correctly when constructing a two-dimensional array for exporting Excel, avoiding data dislocation or loss. At the same time, when determining the range of merged cells, the maximum depth is an important basis to ensure that the merge operation conforms to the hierarchical structure of the header, so that the layout of the header of the final exported Excel file is reasonable and accurate. In addition, the function of calculating the node depth is encapsulated into a tool function getTreeDepth. When processing different dynamic grouped header data, only the function needs to be called, without repeatedly writing the depth calculation logic, which improves the reusability of the code. Moreover, when it is necessary to modify the depth calculation rules or handle special situations, it is only necessary to make adjustments in the getTreeDepth function, which is convenient for program maintenance and expansion. At the same time, in the dynamic grouped header scenario, the structure and content of the header may change at any time. The method of automatically calculating the maximum depth in this step can quickly adapt to these changes without manual recalculation and adjustment, improving the flexibility and response speed of the system, and meeting the user's rapid processing of different data display needs.

[0052] SS3, calculates the number of expanded rows for each node.

[0053] For grouped table headers, there are two types of merged cells: (1) a cell merges several rows; (2) a cell merges several columns. The purpose of this step is to calculate how many rows of cells each node will occupy.

[0054] When using the xlsx library to export an excel file with a group header, it is necessary to clarify the number of rows occupied by each node in the table in order to correctly set the merged cells so that the table presents a reasonable layout and hierarchical structure. By calculating the number of expanded rows for each node, the style of the table can be accurately controlled to ensure that the header information is clearly displayed. This step determines the number of expanded rows based on whether the node is a leaf node. The leaf node is the bottom-level node in the group header and represents a specific data column. The calculation of its number of expanded rows is related to the maximum depth of the group header and its own depth. Non-leaf nodes, as grouping nodes, play the role of organizing and summarizing subnodes. The number of expanded rows is fixed to 1 because it is mainly used to display the group name and does not occupy multiple lines of space.

[0055] The method comprises the following steps: traversing the tree node structure of each node element in the node array, judging whether the current tree node is a leaf node according to its child node attributes, and if it is a leaf node, calculating the number of extended rows of the current tree node as the maximum depth of the grouping table header minus the depth of the current tree node plus 1; if it is not a leaf node, judging the number of extended rows of the current tree node as 1.

[0056] Specifically, a utility function `computeRow` is defined to implement this function. The function takes a node and the depth `depth` of the current node as parameters. Inside the function, the type of the node is judged: (1) If the node is a leaf node, then its extended row count is `maxDepth` minus `depth` plus 1, where `maxDepth` is the maximum depth of the grouped table headers calculated previously; (2) If the node is a non-leaf node, obviously its extended row count is 1. For the children nodes of this non-leaf node, the `computeRow` function is called in sequence to calculate their extended row counts, and `depth` plus 1 is used as the parameter passed in. Here, the calculated extended row count of the node is defined as the `rowspan` attribute and assigned to the corresponding node. The above utility function is called for each node in the node array.

[0057] The `computeRow` function is the core for calculating the extended row count of a node. It accepts two parameters, one is the node for which the extended row count needs to be calculated currently, and the other is the depth `depth` of the current node. Inside the function, different calculation logics are executed by judging the node type: If it is a leaf node, using the previously calculated maximum depth `maxDepth` of the grouped table headers, the extended row count is obtained through the formula `maxDepth - depth + 1`; If it is a non-leaf node, its extended row count is set to 1, and the `computeRow` function is called recursively to calculate the extended row counts of its children nodes, and the depth `depth` of the children nodes plus 1 is passed in as a parameter to ensure the accurate calculation of the extended row counts of the children nodes. Finally, the calculated extended row count is assigned to the `rowspan` attribute of the node for subsequent processing.

[0058] In this step, by precisely calculating the number of expanded rows for each node, it is possible to accurately set merged cells when exporting to an Excel file, enabling the hierarchical structure of the grouped table headers to be clearly presented in the table. The distinction between the expanded row numbers of leaf nodes and non-leaf nodes is clear, avoiding the problem of chaotic cell layout in the table and improving the readability and professionalism of the table. In the scenario of a dynamic grouped table header, the header structure and content may change in real time according to user operations, data changes, or business logic. This calculation method can quickly respond to these changes and automatically recalculate the expanded row number for each node. Regardless of how the header is dynamically adjusted, it can ensure that the table layout is always reasonable without manual intervention and resetting. For example, in a data analysis system, when a user switches different analysis dimensions at any time, resulting in changes in the header grouping, this calculation method can quickly adjust the expanded row number to ensure that the exported table always meets the data display requirements. The logic for calculating the expanded row number of nodes is encapsulated in the tool function computeRow. During the project development process, if it is necessary to modify or optimize the calculation rules for the expanded row number, only adjustments need to be made within this function, without affecting other parts of the code. At the same time, this function can be reused in different scenarios, improving the code reusability and reducing the development cost and maintenance workload.

[0059] SS4, calculate the expanded column number for each node.

[0060] In the previous step, the number of cells that each node occupies in terms of rows has been calculated. In this step, the number of cells that each node occupies in terms of columns needs to be calculated.

[0061] When exporting an Excel file containing grouped table headers, it is not only necessary to determine the number of rows occupied by each node but also to clarify the number of columns it occupies. This is crucial for correctly merging cells and presenting the hierarchical relationship and layout of the table headers. Calculating the expanded column number can accurately define the horizontal range of each table header node, making the final generated Excel table structure complete and clear. In this step, the calculation of the expanded column number is distinguished according to whether the node is a leaf node. A leaf node represents a specific data column. Under normal circumstances, its expanded column number is 1, that is, it only occupies one column of space. As a grouping node, the expanded column number of a non-leaf node depends on the sum of the expanded column numbers of all its child nodes because it needs to cover the column ranges corresponding to all its child nodes.

[0062] It includes the following steps: Traverse the tree node structure of each node element in the node array. For the current tree node, judge whether it is a leaf node according to its child node attributes. If it is a leaf node, determine that the expanded column number of the current tree node is 1; if it is not a leaf node, calculate the expanded column number of the current tree node as the sum of the expanded column numbers of all its child nodes.

[0063] Specifically, a utility function `computeCol` is defined to implement this function. The function takes a node as a parameter. Inside the function, the type of the node is judged: (1) When the node is a leaf node and has no child nodes, its extended column number is obviously 1; (2) When the node is a non-leaf node, the extended column number of the node at this time is the sum of the extended column numbers of all its child nodes. The calculation method of the extended column numbers of its child nodes can be obtained by recursively calling this utility function. Here, the calculated extended column number of the node is defined as the `colspan` attribute and assigned to the corresponding node. The above utility function is called for each node in the node array.

[0064] The `computeCol` function is the key to implementing the calculation of the extended column number of the node. It takes a node as a parameter. Inside the function, it first judges the node type. If it is a leaf node, it directly returns the extended column number 1; if it is a non-leaf node, it calculates the extended column numbers of each child node by recursively calling the `computeCol` function, and adds up the extended column numbers of these child nodes to get the extended column number of this non-leaf node. Finally, the calculated extended column number is assigned to the `colspan` attribute of the node for convenient use in subsequent construction of excel data and merging cell configuration. For example, assume there is a non-leaf node "Sales Data" which contains two leaf node child nodes "Sales Amount" and "Sales Volume", and the extended column numbers of these two leaf nodes are both 1, then the extended column number of the non-leaf node "Sales Data" is 1 + 1 = 2.

[0065] By accurately calculating the number of expanded columns for each node, when exporting to an Excel file, the horizontal range of merged cells can be precisely set, enabling the grouped headers to be reasonably and hierarchically laid out horizontally. Grouped headers at different levels and specific data columns can be clearly displayed in their corresponding column positions, allowing users to intuitively understand the relationships between the data. For example, in a complex financial statement, the expanded column numbers of grouped headers such as "Assets" and "Liabilities" can accurately cover all the specific item columns subordinate to them. In the scenario of dynamic grouped headers, the structure and content of the headers will change in real time according to various conditions. This calculation method can quickly adapt to these changes. Regardless of how the number of nodes and hierarchical structure of the headers are adjusted, it can automatically recalculate the expanded column number for each node, ensuring that the exported Excel table always maintains the correct layout, improving the flexibility and stability of the system, and reducing the workload of manual intervention and adjustment. For example, in a data visualization system, when users switch different data dimensions or filtering conditions, the grouping and column display of the headers will change accordingly. Through this calculation method, the expanded column number can be quickly recalculated to ensure the accuracy of the table display. Encapsulating the calculation logic of the expanded column number in the utility function computeCol improves the maintainability of the code. When it is necessary to modify the calculation rules of the expanded column number or handle special cases, only adjustments need to be made inside the computeCol function, without affecting other parts of the code. At the same time, this function can be reused in different business scenarios and projects, reducing the duplication of code writing, improving development efficiency and code reusability.

[0066] SS5. Calculate the maximum width maxWdith of the node array.

[0067] To construct the data to be passed into xlsx subsequently, relevant variables need to be calculated in advance here. The maximum width of the node array is calculated as the sum of the expanded column numbers of each node in the array. Since the expanded column number of each node has been calculated in step SS4, a summation operation can be directly performed here.

[0068] When using the xlsx library to export an Excel file containing dynamic grouped headers, a data structure that meets the requirements of the xlsx library needs to be constructed. The maximum width of the node array is one of the key parameters for constructing this data structure, which determines the number of columns in the final generated two-dimensional array. Clearly defining the maximum width can ensure that all header information and data can be correctly arranged in the two-dimensional array, providing guarantee for accurately passing the data into the xlsx library subsequently and generating an Excel file in the correct format.

[0069] The maximum width is obtained by summing up the extended column counts of each node in the array. Since the extended column count of each node has been calculated in detail in the previous step SS4, in this step, we directly perform the accumulation operation on these existing extended column counts. For example, if there are three nodes in the node array, and their extended column counts are 2, 3, and 1 respectively, then the maximum width maxWidth of the node array is 2 + 3 + 1 = 6.

[0070] SS6. Divide the node array according to the depth levels.

[0071] The depth level of a point will determine its final level in the two-dimensional array passed into the xlsx. Therefore, in this step, all nodes need to be divided according to the depth levels. This includes traversing the tree node structure of each node element in the node array. For the current tree node, according to the depth level of the current tree node, place it into the corresponding depth level node set.

[0072] Specifically, construct a two-dimensional array. The nth item in the array is the set of nodes at the nth level. Traverse the node array, recursively traverse each node, and place it into the corresponding set according to the depth level where the node is located. Subsequently, the set array of this level can be directly processed. For example, if there is a node with a depth level of 2, add it to the array with an index of 2 in the two-dimensional array (i.e., the set storing the nodes at the 2nd level).

[0073] This step enables direct operation on the divided level set array when constructing the subsequent two-dimensional array and merging cell configuration information, reducing unnecessary search and judgment steps. For example, when filling the subsequent two-dimensional array, according to the level set where the node is located, the row position of the node in the two-dimensional array can be quickly determined, improving the efficiency of data filling. In addition, through this division method, the hierarchical relationship of the grouped headers can be clearly presented. Nodes at different depth levels are clearly distinguished. When generating the excel file, the merge cell operation of the headers can be accurately performed, making the header layout conform to the expected hierarchical structure.

[0074] SS7. Construct the input data.

[0075] After all the above steps, the calculated data includes: the maximum depth maxDepth of the node array, the extended row count rowspan of each node, the extended column count colspan of each node, the maximum width maxWidth of the node array, and the node sets divided according to the node depth levels. Based on the existing data, the data to be finally passed into the xlsx can be constructed in this step. The following are the steps.

[0076] SS7.1, construct a two-dimensional array and initialize each item to an empty string. The number of rows of the two-dimensional array is the maximum depth of the grouped table headers, and the number of columns is the maximum width of the node array.

[0077] Construct a two-dimensional array data, whose number of rows is determined by the maximum depth maxDepth of the grouped table headers, the number of columns is determined by the maximum width maxWidth of the node array, and each element is initialized to an empty string. This sets up a "framework" for filling in the header information later and determines the overall size of the table. For example, if maxDepth is 3 and maxWidth is 5, then a two-dimensional array with 3 rows and 5 columns is created.

[0078] SS7.2, traverse each set of nodes at each depth level. Initialize the position index variable to 0 within each loop. The position index variable represents the current column in the corresponding two-dimensional array.

[0079] When traversing each set of nodes at each depth level, initialize a position index variable (such as curIndex) to 0. This variable is used to mark the column position in the two-dimensional array where data is to be filled currently.

[0080] SS7.3, for the current set of nodes at the current depth level, first use a while loop to update the position index variable within the loop, incrementing the position index variable by 1 each time until the data item at the corresponding row and column position in the two-dimensional array is an empty string; the current row and column position is the row corresponding to the current depth level, and the column corresponding to the current position index variable.

[0081] Use a while loop to update curIndex until a cell in the current row corresponding to the current depth level in the two-dimensional array is found where the cell at the curIndex position is not an empty string. The purpose of this step is to find the appropriate starting column position to fill in the data of the current node and avoid overwriting existing data. Since in the grouped table headers, the positions of different nodes may have a sequence, this way can ensure that each node can be filled in the correct position.

[0082] SS7.4, at this time, judge the extended number of rows and columns of the current node to fill the two-dimensional array, including the number of cells filled downward from the current row position is the extended number of rows of the current node, and the number of cells filled backward from the current column position is the extended number of columns of the current node.

[0083] Fill a two-dimensional array according to the rowspan (number of rows to expand) and colspan (number of columns to expand) of the current node. If rowspan is greater than 1, it means that the node needs to merge cells across rows, and the name attribute of the current node should be filled into the curIndex positions of all subsequent levels in the two-dimensional array starting from the current row; then starting from curIndex, fill the name attribute of the current node backward according to the number of colspan to achieve horizontal cell merging.

[0084] Specifically, first initialize the final data data, whose initial value is a two-dimensional array with maxDepth rows and maxWidth columns, and each item is initialized to an empty string. Traverse the node set divided by levels. Each item in the loop is the node set at the same depth level. Initialize the curIndex variable to 0 in each loop, representing the current subscript in the corresponding level of data. Then traverse the node set at this depth level. In the loop, first use a while loop to update the value of curIndex, adding 1 to curIndex each time until the value at the curIndex index position in the corresponding level of data is not an empty string. At this time, first judge whether the rowspan attribute of the node is greater than 1. If it is greater than 1, it means that the node needs to expand multiple rows of cells, and the name value of the current node should be filled into all subsequent levels of curIndex positions in data. Then the name attribute of the current node can be filled starting from the curIndex subscript, and the number of backward fills is the number of colspan of the node. After the above traversal, data is the final processed data and can be used as a parameter for passing to the xlsx library.

[0085] Take Figure 2Taking the following table as an example, construct a 2 * 6 two-dimensional array, that is, 2 rows and 6 columns. Initially, each cell is configured with an empty string. The first-level node set is [Name, ID Number, Gender, Work Information], and the second-level node set is [Work Unit, Work Address, Salary]. First, loop through the first-level node set, select the first element "Name", increment curIndex by 1, so curIndex = 1. Check if the cell in the first row (corresponding to the first depth level) and the first column (corresponding to curIndex = 1) is an empty string. Currently, it is, so reset curIndex to 0. At the same time, check the extended number of rows and columns of the element "Name". Its extended number of rows is 2, and the extended number of columns is 1. Then fill the two cells in the first row and the first column and the second row and the first column with "Name". Then select the second element "ID Number", increment curIndex by 1, so curIndex = 1. Check if the cell in the first row and the first column is an empty string. Currently, it is not, so increment curIndex by 1 again, curIndex = 2. Check if the cell in the first row and the second column is an empty string. Currently, it is, so reset curIndex to 0. At the same time, check the extended number of rows and columns of the element "ID Number". Its extended number of rows is 2, and the extended number of columns is 1. Then fill the two cells in the first row and the second column and the second row and the second column with "ID Number". And so on. Finally, the two-dimensional array is filled in the following form.

[0086]

[0087] Through this construction process, the information of the grouped table headers can be accurately converted into a two-dimensional array that meets the requirements of the xlsx library. The position of each node and the range of merged cells can be accurately determined according to the previously calculated parameters, ensuring the consistency and accuracy of the headers and data in the exported Excel file. When dealing with complex grouped table headers, it can also ensure the correct display of data and avoid data misalignment or incorrect merged cell situations. Since this construction method depends on the previously calculated dynamic parameters (such as maxDepth, rowspan, colspan, maxWidth, etc.), for dynamic grouped table headers, no matter how their structures and contents change, as long as the previous parameter calculations are correct, the corresponding correct two-dimensional array data can be generated. This makes the system highly adaptable and can meet the needs of different users for exporting dynamic grouped table header data in different scenarios.

[0088] SS8, construct the merged cell configuration.

[0089] After constructing the specific data, the specific configuration of the merged cells also needs to be passed in. The required format of the configuration is an array of objects, and each item in the array represents a cell block to be merged. The following steps are included.

[0090] SS8.1, construct an array of objects, where each item in the array of objects represents a cell block to be merged.

[0091] Create an array of objects to store information about all cell blocks to be merged, preparing for subsequent configuration of merged cells. Each object represents a merged cell block, and its properties will record the range of the merged block.

[0092] SS8.2, perform a double traversal on the set of nodes at different depth levels. Each item within the loop is a node.

[0093] By performing a double traversal on the set of nodes at different depth levels, for each node traversed, its corresponding merged cell configuration needs to be determined. This is because the display of each node in the Excel table may involve merged cell operations and needs to be processed one by one. The outer loop traverses different depth levels, and the inner loop traverses each node within each depth level. This can ensure that each node is processed to determine its corresponding merged cell configuration.

[0094] SS8.3, find the first column index in the two-dimensional array to fill the header identification attribute of the current node.

[0095] In the already constructed two-dimensional array (such as data), find the first column index (colIndex) to fill the header identification attribute of the current node (such as name). This index determines the starting column position of the current node in the two-dimensional array and is the key information for determining the range of merged cells.

[0096] SS8.4, detect the extended row count and extended column count of the current node.

[0097] Check the extended row count (rowspan) and extended column count (colspan) of the current node. Based on the values of these two attributes, determine the direction and range of the cells that the node needs to merge.

[0098] SS8.5, if the extended row count is greater than 1 and the extended column count is 1, then the starting abscissa of the cell block of the current node is the depth level where the current node is located, the ending abscissa is the depth level where the current node is located plus the extended row count, and the ordinate is the first column index.

[0099] When the extended row count is greater than 1 and the extended column count is 1, it means that the current node needs to merge cells vertically. At this time, the starting abscissa of the merged cell block is the depth level where the current node is located (corresponding to the row index of the two-dimensional array), the ending abscissa is the current depth level plus the extended row count, and the ordinate is always the first column index found.

[0100] SS8.6. If the number of extended columns is greater than 1 and the number of extended rows is 1, the abscissas of the cell blocks of the current node are all at the depth level where the current node is located. The starting ordinate is the first column index, and the ending ordinate is the first column index plus the number of extended columns minus 1.

[0101] When the number of extended columns is greater than 1 and the number of extended rows is 1, it indicates that the current node needs to horizontally merge cells. At this time, the abscissa of the merged cell block is fixed at the depth level where the current node is located. The starting ordinate is the first column index, and the ending ordinate is the first column index plus the number of extended columns minus 1.

[0102] Specifically, perform a double traversal on the node set divided by levels. Each item in the loop is a node. First, find the first subscript colIndex in data to fill the name attribute of the current node. Judge the rowspan attribute and colspan attribute of the node. There will be two situations here: (1) rowspan is greater than 1, indicating that this node needs to extend a certain number of rows. At this time, the starting abscissa of the cell merge block is the current depth level, the ending abscissa is the depth level plus the number of extended rows, and the ordinates are all colIndex; (2) colspan is greater than 1, indicating that this node needs to extend a certain number of columns. At this time, the abscissas of the cell merge block are all at the current depth level, the starting ordinate is colIndex, and the ending ordinate is colIndex plus colspan minus 1.

[0103] Illustrated in Table 1 below.

[0104] Table 1: Example Table

[0105] Among them, the cell of "Province" occupies one column and four rows. For it, the cells to be merged are the cells between the cell at (abscissa 0, ordinate 0) and the cell at (abscissa 3, ordinate 0). Here, it is defined that the coordinates of the upper left corner cell of the excel are (0, 0). Starting from this cell and going down, the abscissa increases, and going to the right, the ordinate increases.

[0106] SS9. Pass in data and merged cell configuration information to export a file.

[0107] In the above text, the embodiments of a method for exporting a dynamic grouped table header excel based on xlsx are described in detail. Based on the method for exporting a dynamic grouped table header excel described in the above embodiments, the embodiments of the present invention also provide an apparatus for exporting a dynamic grouped table header excel corresponding to this method.

[0108] Figure 4The following is a schematic block diagram of a system for exporting an Excel file with a dynamically grouped header based on XLSX according to an embodiment of the present invention. In this embodiment, the system 400 for exporting an Excel file with a dynamically grouped header based on XLSX can be divided into multiple functional modules according to the functions it performs. The module referred to in the present invention means a series of computer program segments that can be executed by at least one processor and can complete fixed functions, and are stored in the memory.

[0109] The node array construction module 410 is used to construct a data structure of a one-dimensional node array. Each node element in the node array is a set of headers, and each is a tree node structure formed according to the header level information. The tree node has a necessary header identification attribute and an optional child node attribute. The child node attribute represents the set of child nodes of the tree node.

[0110] The node parameter calculation module 420 is used to traverse the node array and calculate the maximum depth of the grouped header, the extended row numbers of each node, the extended column numbers of each node, and the maximum width of the node array according to the node attributes.

[0111] The depth level division module 430 is used to divide the node array according to the depth levels of the nodes. The depth level is used to represent the hierarchical relationship of the nodes in the tree structure.

[0112] The input parameter and configuration construction module 440 is used to construct the merged cell configuration information and the input data for passing parameters to the XLSX library according to the maximum depth of the grouped header, the extended row numbers of each node, the extended column numbers of each node, and the maximum width of the node array.

[0113] The Excel file export module 450 is used to pass the merged cell configuration information and the input data into the XLSX library to export an Excel file.

[0114] The device for exporting an Excel file with a dynamically grouped header based on XLSX in this embodiment is used to implement the foregoing method for exporting an Excel file with a dynamically grouped header based on XLSX. Therefore, the specific implementation in this device can be seen in the embodiment part of the method for exporting an Excel file with a dynamically grouped header based on XLSX in the foregoing text. Therefore, its specific implementation can refer to the descriptions of the corresponding individual part embodiments and will not be elaborated here.

[0115] In addition, since the device for exporting an Excel file with a dynamically grouped header based on XLSX in this embodiment is used to implement the foregoing method for exporting an Excel file with a dynamically grouped header based on XLSX, its function corresponds to the function of the above method and will not be elaborated here.

[0116] Figure 5Schematic diagram of a structure of a terminal 500 provided by an embodiment of the present invention, including: a processor 510, a memory 520, and a communication unit 530. The processor 510 is used to implement the following steps when implementing a program for exporting a dynamic grouped table header excel based on xlsx saved in the memory 520: Construct a data structure of a one-dimensional node array, where each node element in the node array is a group of table headers, and each is a structure of a tree node formed according to table header level information. The tree node has a necessary table header identification attribute and an optional child node attribute, and the child node attribute represents the set of child nodes of the tree node; Traverse the node array, and calculate the maximum depth of the grouped table header, the extended number of rows of each node, the extended number of columns of each node, and the maximum width of the node array according to the node attributes; Divide the node array according to the depth levels of the nodes, where the depth level is used to represent the hierarchical relationship of the nodes in the tree structure; Construct merge cell configuration information and input data for passing parameters to the xlsx library according to the maximum depth of the grouped table header, the extended number of rows of each node, the extended number of columns of each node, and the maximum width of the node array; Pass the merge cell configuration information and the input data into the xlsx library to export an excel file.

[0117] The present invention also provides a computer storage medium, and the storage medium here may be a magnetic disk, an optical disk, a read-only memory (abbreviation in English: read-only memory, ROM for short), or a random access memory (abbreviation in English: random access memory, RAM for short), etc.

[0118] The computer storage medium stores a program for exporting a dynamic grouped table header excel based on xlsx. When the program for exporting a dynamic grouped table header excel based on xlsx is executed by a processor, the following steps are implemented: Construct a data structure of a one-dimensional node array, where each node element in the node array is a group of table headers, and each is a structure of a tree node formed according to table header level information. The tree node has a necessary table header identification attribute and an optional child node attribute, and the child node attribute represents the set of child nodes of the tree node; Traverse the node array, and calculate the maximum depth of the grouped table header, the extended number of rows of each node, the extended number of columns of each node, and the maximum width of the node array according to the node attributes; Divide the node array according to the depth levels of the nodes, where the depth level is used to represent the hierarchical relationship of the nodes in the tree structure; Construct the merged cell configuration information and the input data for passing parameters to the xlsx library according to the maximum depth of the grouped table header, the extended number of rows for each node, the extended number of columns for each node, and the maximum width of the node array; Pass the merged cell configuration information and the input data into the xlsx library to export an excel file.

[0119] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for exporting dynamic grouping header excel based on xlsx, characterized in that: The following steps are involved: Construct a one-dimensional node array data structure. Each node element in the node array is a set of headers, and each is a tree node structure formed according to the header hierarchical information. The tree node has a required header identification attribute and a non-required child node attribute. The child node attribute represents the child node set of the tree node. Traverse the node array and calculate the maximum depth of the group header, the number of expanded rows of each node, the number of expanded columns of each node, and the maximum width of the node array according to the node attributes; Divide the node array into nodes according to their depth levels. The depth levels are used to represent the hierarchical relationship of the nodes in the tree structure. According to the maximum depth of the group header, the number of expanded rows of each node, the number of expanded columns of each node, and the maximum width of the node array, the merged cell configuration information and the incoming data for parameter transfer to the xlsx library are constructed; Pass the merged cell configuration information and incoming data into the xlsx library to export the excel file.

2. The method for exporting dynamic grouping header excel based on xlsx according to claim 1 is characterized in that: Traverse the node array and calculate the maximum depth of the group header according to the node attributes, including: Initialize the return value of the current node element to 1; Traverse the child node attributes of the current node element. Each time a layer of child nodes is obtained, add 1 to the depth value of the current child node layer and compare it with the current return value. The larger value is used to update the current return value. The final return value is the depth of the current node element. Compare the depths of all node elements and take the maximum value as the maximum depth of the group header.

3. The method for exporting dynamic grouping header excel based on xlsx according to claim 1 is characterized in that: Traverse the node array and calculate the number of extended rows of each node according to the node attributes, including: Traverse the tree node structure of each node element in the node array. For the current tree node, determine whether it is a leaf node based on its child node attributes. If it is a leaf node, calculate the number of expanded rows of the current tree node as the maximum depth of the grouping header minus the current tree node depth plus 1; if it is not a leaf node, determine that the number of expanded rows of the current tree node is 1.

4. The method for exporting dynamic grouping header excel based on xlsx according to claim 1 is characterized in that: Traverse the node array and calculate the number of extended columns of each node and the maximum width of the node array according to the node attributes, including: Traverse the tree node structure of each node element in the node array. For the current tree node, determine whether it is a leaf node according to its child node attributes. If it is a leaf node, determine that the number of extended columns of the current tree node is 1; if it is not a leaf node, calculate the number of extended columns of the current tree node as the sum of the number of extended columns of all its child nodes; The maximum width of the computed node array is the sum of the number of expanded columns of all root nodes.

5. The method for exporting dynamic grouping header excel based on xlsx according to claim 1 is characterized in that: Divide the node array into nodes according to their depth level, including: Traverse the tree node structure of each node element in the node array, and for the current tree node, put it into the corresponding depth level node set according to the depth level of the current tree node.

6. The method for exporting dynamic grouping header excel based on xlsx according to claim 5 is characterized in that: According to the maximum depth of the group header, the number of expanded rows of each node, the number of expanded columns of each node, and the maximum width of the node array, construct the incoming data for parameter transmission to the xlsx library, including: Construct a two-dimensional array and initialize each item to an empty string. The number of rows in the two-dimensional array is the maximum depth of the group header, and the number of columns is the maximum width of the node array. Traverse each depth level node set, and initialize the position index variable to 0 in each loop. The position index variable represents the current column in the corresponding two-dimensional array; For the current depth level node set, first use a while loop within the loop to update the position index variable, adding 1 to the position index variable each time until the data item at the corresponding row and column position in the two-dimensional array is not an empty string; the current row and column position is the row corresponding to the current depth level, and the column corresponding to the current position index variable; At this time, the number of expanded rows and columns of the current node is determined to fill the two-dimensional array, including the number filled downward from the current row position as the number of expanded rows of the current node, and the number filled backward from the current column position as the number of expanded columns of the current node.

7. The method for exporting dynamic grouping header excel based on xlsx according to claim 6 is characterized in that: According to the maximum depth of the group header, the number of expanded rows of each node, the number of expanded columns of each node, and the maximum width of the node array, the merged cell configuration information is constructed, including: Construct an object array, each item in the object array represents the cell block that needs to be merged; Double traverse the depth level node collection, each item in the loop is a node; Find the first column index in the two-dimensional array that populates the current node header identification attribute; Detect the number of expanded rows and columns of the current node; If the number of expanded rows is greater than 1 and the number of expanded columns is 1, the starting horizontal coordinate of the cell block of the current node is the depth level of the current node, the ending horizontal coordinate is the depth level of the current node plus the number of expanded rows, and the vertical coordinates are all the first column index; If the number of expanded columns is greater than 1 and the number of expanded rows is 1, the horizontal coordinates of the cell block of the current node are all the depth level of the current node, the starting vertical coordinate is the first column index, and the ending vertical coordinate is the first column index plus the number of expanded columns minus 1.

8. A system for exporting dynamic grouping headers to Excel based on xlsx, characterized in that: include: The node array construction module is used to construct a one-dimensional node array data structure. Each node element in the node array is a set of headers, and each is a tree node structure formed according to the header hierarchical information. The tree node has a required header identification attribute and a non-required child node attribute. The child node attribute represents the child node set of the tree node. The node parameter calculation module is used to traverse the node array and calculate the maximum depth of the group header, the number of extended rows of each node, the number of extended columns of each node, and the maximum width of the node array according to the node attributes; The depth level division module is used to divide the node array according to the depth level of the node. The depth level is used to represent the hierarchical relationship in the tree structure where the node is located; The parameter input and configuration construction module is used to construct the merged cell configuration information and the input data for parameter transmission to the xlsx library according to the maximum depth of the group header, the number of expanded rows of each node, the number of expanded columns of each node, and the maximum width of the node array; The excel file export module is used to pass the merged cell configuration information and the incoming data into the xlsx library to export the excel file.

9. A terminal, characterized in that: include: Memory, used to store the program for exporting dynamic grouping headers to Excel based on xlsx; A processor is used to implement the steps of the method for exporting dynamic grouping headers to Excel based on xlsx as described in any one of claims 1 to 7 when executing the program for exporting dynamic grouping headers to Excel based on xlsx.

10. A computer-readable storage medium, characterized in that: The readable storage medium stores a program for exporting dynamic grouping headers to Excel based on xlsx, and when the program for exporting dynamic grouping headers to Excel based on xlsx is executed by a processor, the steps of the method for exporting dynamic grouping headers to Excel based on xlsx as claimed in any one of claims 1 to 7 are implemented.