An adaptive word table data dynamic encapsulation method and system

By using an adaptive method for dynamically encapsulating Word table data and employing a binary search approach to calculate the optimal font size and hierarchical structure, this approach solves the problems of low efficiency, poor compatibility, and format preservation in existing technologies. It achieves efficient automated encapsulation of table data, adapting to different data volumes and table structures.

CN123159290APending Publication Date: 2026-11-24商飞软件有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611439509.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-16
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing automated encapsulation technologies for Word table data have significant shortcomings in terms of efficiency, environmental compatibility, format preservation, and adaptation to complex tables. In particular, they lack the ability to adaptively and collaboratively adjust layout parameters such as font size within the table.

Method used

It adopts an adaptive method for dynamically encapsulating Word table data, calculates the optimal font size in table cells using a binary search method, and combines a hierarchical architecture and predefined structured tags in templates to adaptively adjust layout parameters to adapt to different data volumes and table structures without manual intervention.

Benefits of technology

It significantly improves the efficiency and success rate of automated encapsulation of Word table data, solves the problems of poor cross-version document format compatibility and font misalignment, and reduces operation complexity and maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123159290A_ABST
    Figure CN123159290A_ABST
Patent Text Reader

Abstract

This invention discloses an adaptive dynamic encapsulation method and system for Word table data, comprising the following steps: Step 1, process initiation and basic data acquisition; Step 2, template tag preprocessing; Step 3, text pre-filling; Step 4, binary search parameter initialization; Step 5, interval validity judgment; Step 6, intermediate font size calculation; Step 7, layout parameter calculation; Step 8, region adaptability judgment; Step 9, document generation and output. Through adaptive font size calculation, data filling is automatically completed without changing the original page number and table layout of the document, completely avoiding the manual repeated adjustment of font size and line height, significantly improving encapsulation efficiency and success rate, and effectively solving the font misalignment problem caused by poor cross-version document format compatibility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of document processing system technology, specifically an adaptive method and system for dynamically encapsulating Word table data. Background Technology

[0002] In the field of office automation, the automated encapsulation and export of Word table data is a crucial aspect of information system development. Currently, the mainstream technical solutions for achieving this function mainly include macro methods based on VBA scripts, automated Office calls based on COM interoperability, text replacement solutions based on template engines, and programmatic operation solutions based on open-source or commercial libraries.

[0003] The VBA-based approach is the most traditional and widely used method, employing macro code to assign values ​​to individual table cells in the Word object model. However, this approach has significant drawbacks. Operationally, VBA processes data sequentially by assigning values ​​cell by cell. When dealing with large amounts of table data, the export speed becomes extremely slow and inefficient. When handling complex tables, macro code often skips parts of the table or causes abnormal column width shrinkage, requiring manual correction. Environmentally, VBA is highly dependent on the Microsoft Office environment and cannot run on servers or Linux containers without Office installed, severely limiting deployment scenarios. Functionally, VBA is not designed specifically for document assembly and lacks crucial scripting features such as the three-state logic necessary for enterprise-level document automation. Implementing complex logic requires writing a large amount of redundant code.

[0004] COM-based Office automation solutions (such as C# manipulating documents through Word components) share similar problems with VBA solutions: each operation requires calling an I / O interface, resulting in high resource consumption, slow speed, and poor stability, while also requiring each running machine to have a Word license. Template engine-based solutions (such as Freemarker converting Word documents into template files for variable replacement) simplify the data entry process to some extent, but suffer from various compatibility issues, including template variable splitting leading to replacement failures, poor support for higher version docx files, export errors when lists are empty, and loss of text formatting. Open-source library-based solutions (such as Apache POI manipulating Word's XML structure) face challenges such as unintuitive operation, structural errors and row / column offsets in complex nested tables, and batch loss of styles (borders, fonts, alignment), among other formatting preservation difficulties. Furthermore, emerging AI-assisted form-filling tools frequently exhibit misalignment issues in formatting and cannot yet meet precise formatting requirements.

[0005] In summary, existing Word table data automation encapsulation technologies have significant shortcomings in terms of efficiency, environmental compatibility, format preservation, and adaptation to complex tables. In particular, they lack the ability to adaptively and collaboratively adjust layout parameters such as text size within tables. There is an urgent need for a solution that can adaptively adjust layout parameters and be compatible with multiple version formats. Summary of the Invention

[0006] The technical solution adopted in this invention is as follows: An adaptive method for dynamically encapsulating Word table data, comprising the following steps:

[0007] Step 1: Process Initiation and Basic Data Acquisition: Obtain the user business data to be filled and read the Word document template selected by the user.

[0008] Step 2: Template Tag Preprocessing: Parse the predefined placeholder tags in the Word document template, establish the field mapping relationship between the placeholder tags and the user business data, and complete the association mapping between tags and data;

[0009] Step 3: Text pre-filling: Convert the user business data into text to be filled according to the mapping relationship, replace the corresponding placeholder labels in the Word document template, and complete the initial data placeholder;

[0010] Step 4: Initialize the binary search parameters: Set the initial range for font size search for the cell range to be filled, define the minimum font size boundary as low and the maximum font size boundary as high, and complete the initialization of the search range;

[0011] Step 5: Interval validity check: Check if the current search interval satisfies low≤high. If not, exit the loop and output the final font size result. If it satisfies, proceed to step 6.

[0012] Step 6: Calculate the middle font size: Take the middle value of the current search interval as the font size mid to be tested;

[0013] Step 7: Layout parameter calculation: Arrange the text to be filled according to the font size mid to be tested, calculate the actual total number of lines after text wrapping and the maximum text width of all lines, and calculate the actual total height of the text.

[0014] Step 8: Region Adaptability Judgment: Determine whether the text formatted according to the font size mid to be tested fully adapts to the reserved fillable range of the cell region to be filled. If it adapts, update the minimum boundary low of the search interval low=mid+1 and return to step 5. If it does not adapt, update the maximum boundary high of the search interval high=mid-1 and return to step 5.

[0015] Step 9: Document Output Generation: When the binary search loop ends (i.e., low > high), the final optimal font size is taken as the largest font size that fits the current cell. All data tags are then reformatted according to the optimal font size and bound to the corresponding positions in the Word document template to generate a complete document data stream output.

[0016] Furthermore, in step seven, when calculating the actual total number of lines after text wrapping and the maximum text width of all lines, the line spacing coefficient and cell margin are also obtained as input parameters for the layout parameter calculation.

[0017] Furthermore, in step eight, when determining whether the text formatted according to the font size mid fully fits the reserved fillable range of the cell area to be filled, the determination conditions include: the actual total height does not exceed the fillable height of the cell area to be filled, and the maximum text width of all lines does not exceed the fillable width of the cell area to be filled.

[0018] Furthermore, before step one, a template predefinition step is included: embedding structured tags in the table cells of the Word document template that need to be dynamically filled, wherein the structured tags include tag names and dynamic parameter information.

[0019] Furthermore, in step two, the tag blocks in the Word document template are located by traversing through regular expression matching, and the tag names and dynamic parameters are extracted to complete the parsing of the placeholder tags.

[0020] An adaptive Word table data dynamic encapsulation system, applied to any of the above-described adaptive Word table data dynamic encapsulation methods, includes a user layer, a control layer, a service layer, and a data layer.

[0021] The user layer includes ordinary user units, special user units, and administrator units. The user layer is used to control the operation permissions of various types of users in the system and determine whether to allow users to initiate data export requests based on user permissions. The user layer is connected to the control layer and the service layer respectively.

[0022] The control layer includes a permission checking unit, a data assembly unit, and a file stream transmission unit. The control layer is connected to the user layer and the service layer. The control layer is used to receive user requests sent by the user layer, verify the user requests through the permission checking unit, convert the generated document into a binary file stream through the data assembly unit, and push the binary file stream to the user layer in real time through the file stream transmission unit. The control layer also sends the Word document template selected by the user to the service layer.

[0023] The service layer includes a data storage unit, a model calculation unit, a tag parsing unit, a data mapping unit, and an adaptive encapsulation unit. The service layer is connected to the control layer, the user layer, and the data layer. The service layer receives the Word document template from the control layer, calculates a dynamic parameter model based on the Word document template using the model calculation unit, and sends a data request to the data layer through the data storage unit. The tag parsing unit uses regular expression matching to locate tag blocks in the Word document template, extracting tag names and dynamic parameters. The data mapping unit retrieves corresponding data in the data layer based on the tag names and injects parameters to generate formatted text. The adaptive encapsulation unit obtains user data and a specified Word document template, parses the table, binds various data tags to the required data in the data layer, initializes the minimum and maximum font sizes, line spacing coefficients, and cell margins based on the font, calculates the number of line breaks and content height required to fill the corresponding cells using a binary search method, confirms whether the cell width and height requirements are met, obtains the optimal font size solution, and exports the corresponding file stream.

[0024] The data layer includes a data preprocessing unit and a MySQL unit. The data layer is connected to the service layer. The data layer is used to preprocess data through the data preprocessing unit, persist data through the MySQL unit, and provide standardized data to the service layer when the service layer needs to access the data.

[0025] Furthermore, in the user layer, the ordinary user unit has no right to initiate a data export request, while the special user unit has the right to initiate a data export request. The administrator unit is used to add, modify, and delete the permissions of the ordinary user unit and the special user unit.

[0026] Furthermore, in the control layer, the permission checking unit determines whether to continue the service based on the data fields in the user request. If there is an abnormal data request in the user request, the service is interrupted and a prompt message is returned to the user layer.

[0027] The data assembly unit converts the generated document into a binary file stream, and the file stream transmission unit pushes the binary file stream to the user layer in real time.

[0028] Furthermore, in the service layer, the tag parsing unit uses regular expression matching to traverse and locate the tag blocks in the Word document template, and extracts the tag names and dynamic parameters.

[0029] The data mapping unit retrieves the corresponding data in the data layer according to the tag name and injects parameters to generate formatted text; the adaptive encapsulation unit calculates the optimal font size using a binary search method and encapsulates the filled data according to the target parameter rules.

[0030] Furthermore, in the data layer, the data preprocessing unit embeds structured tags in the table cells of the Word document template that need to be dynamically filled, and the structured tags include tag names and dynamic parameter information;

[0031] The MYSQL unit is built on the MySQL relational database and is used to store raw data and the relationships between data. It achieves logical integration of data from multiple tables through foreign key constraints and join queries.

[0032] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are:

[0033] (1) This invention adaptively calculates the optimal font size in a table cell using a binary search method. It can automatically fill in data without changing the original number of pages in the Word document or the overall layout of the table. This completely avoids the need for manual adjustment of row height and font size due to content overflow in the traditional VBA script method. It significantly improves the efficiency and success rate of Word table data automatic encapsulation, and effectively solves the problems of poor cross-version document format compatibility and font misalignment.

[0034] (2) This invention systematically constructs a layered architecture that includes a user layer, a control layer, a service layer and a data layer. By combining the collaborative work of the tag parsing engine, the data mapping module and the adaptive encapsulator, it realizes a fully automated encapsulation process from user permission management, template tag parsing, automatic data retrieval and mapping to font size adaptive adjustment and real-time document stream push. It can adapt to different data volumes and different table structures without manual intervention, which greatly reduces the complexity of operation.

[0035] (3) The present invention adopts a template predefined structured tag method to decouple the business fields of the data layer from the Word template placeholder tags. The mapping configuration can be completed by simply embedding the tags in the template cell. When the business data changes, there is no need to modify the underlying code. Ordinary business personnel can adjust the export format by maintaining the template tags, which significantly reduces the maintenance cost of the system and the threshold for secondary development. Attached Figure Description

[0036] Figure 1 This is a schematic diagram of the process of the present invention;

[0037] Figure 2 This is a schematic diagram of the overall architecture of the system of the present invention. Detailed Implementation

[0038] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0039] Example 1, referring to Figures 1-2 :

[0040] This embodiment provides an adaptive method for dynamically encapsulating Word table data, including the following steps:

[0041] Step 1: Process Initiation and Basic Data Acquisition: Obtain the user business data to be filled and read the Word document template selected by the user.

[0042] In a specific embodiment of the present invention, the system is built on Spring Boot and Vue. The overall system business architecture includes a user layer, a control layer, a service layer, and a data layer. After the process starts, the system first obtains the user business data to be populated, and simultaneously reads the Word document template selected by the user. The user selects the Word document template to be exported through the user layer, and after receiving the request, the system control layer sends the selected Word document template to the service layer for processing.

[0043] Step 2: Template Tag Preprocessing: Parse the predefined placeholder tags in the Word document template, establish the mapping relationship between the placeholder tags and the fields of user business data, and complete the association mapping between tags and data.

[0044] In a specific embodiment of the present invention, after the service layer obtains the template, the tag parsing engine uses regular expression matching to traverse and locate the tag blocks in the template, extracting the tag names and dynamic parameters. The data mapping module then retrieves the corresponding data from the MySQL database in the data layer based on the tag names, injects parameters to generate formatted text, and completes the tag-data association mapping.

[0045] Step 3: Text pre-filling: Convert user business data into text to be filled according to the mapping relationship, replace the corresponding placeholder labels in the Word document template, and complete the initial data placeholder.

[0046] In a specific embodiment of the present invention, the data mapping module converts user business data into text to be filled according to the mapping relationship, replaces the corresponding placeholder labels in the Word document template, and completes the initial data placeholder.

[0047] Step 4: Initialize the binary search parameters: Set the initial range for font size search for the cell range to be filled, define the minimum font size boundary as low and the maximum font size boundary as high, and complete the initialization of the search range.

[0048] In a specific embodiment of the present invention, the adaptive wrapper calculates the optimal font size through template parameters. First, it sets the initial range for font size lookup for the cell area to be filled, defines the minimum font size boundary as low and the maximum font size boundary as high, and completes the initialization of the lookup range.

[0049] Step 5: Interval validity check: Check if the current search interval satisfies low≤high. If not, exit the loop and output the final font size result. If it satisfies, proceed to step 6.

[0050] In a specific embodiment of the present invention, the adaptive wrapper determines whether the current search interval satisfies low≤high. If it does not satisfy the condition, it exits the loop directly and outputs the final result.

[0051] Step 6: Calculate the middle font size: Take the middle value of the current search interval as the font size mid to be tested.

[0052] In a specific embodiment of the present invention, the adaptive wrapper takes the middle value of the current search interval as the character number mid to be tested.

[0053] Step 7: Layout parameter calculation: Arrange the text to be filled according to the font size mid to be tested, calculate the actual total number of lines after text wrapping and the maximum text width of all lines, and calculate the actual total height of the text.

[0054] In a specific embodiment of the present invention, the adaptive wrapper typesets the text to be filled according to the current font size mid, calculates the actual total number of lines after text wrapping, the maximum text width of all lines, and the actual total height of the text. During the calculation process, line spacing coefficients and cell margins are also obtained as input parameters for the layout parameter calculation.

[0055] Step 8: Region Adaptability Judgment: Determine whether the text formatted according to the font size mid to be tested fully adapts to the reserved fillable range of the cell area to be filled. If it adapts, update the minimum boundary low of the search interval low=mid+1 and return to Step 5. If it does not adapt, update the maximum boundary high of the search interval high=mid-1 and return to Step 5.

[0056] In a specific embodiment of the present invention, the adaptive wrapper determines whether the text after the current font size layout fits the reserved cell area of ​​the template. The determination condition is: the actual total height does not exceed the fillable height of the cell area to be filled, and the maximum text width of all rows does not exceed the fillable width of the cell area to be filled. If the condition is met, it means that there is still room for the current font size to be increased, and the minimum boundary of the search interval is updated low=mid+1, and the process jumps back to step five to enter the next round of search; if the condition is not met, it means that the current font size is too large to fit the area, and the maximum boundary of the search interval is updated high=mid-1, and the process jumps back to step five to enter the next round of search.

[0057] Step 9: Document Output Generation: When the binary search loop ends (low > high), the final optimal font size is used as the largest font size that fits the current cell. All data labels are then reformatted according to the optimal font size and bound to the corresponding positions in the Word document template, generating a complete document data stream output.

[0058] In a specific embodiment of the present invention, when the binary search loop ends (i.e., low > high), the final obtained mid is the optimal font size that fits the current cell and has the largest size. After the adaptive wrapper rearranges all data tags according to the optimal font size, it binds them to the corresponding positions in the template, generates a complete document data stream output, and the entire process ends.

[0059] Specifically, in step seven, when calculating the actual total number of lines after text wrapping and the maximum text width of all lines, the line spacing coefficient and cell margin are also obtained as input parameters for the layout parameter calculation.

[0060] In a specific embodiment of the present invention, when the adaptive wrapper calculates the actual total number of lines after text wrapping and the maximum text width of all lines, it also obtains the line spacing coefficient and cell margin as input parameters for the layout parameter calculation, so as to ensure that the typesetting calculation result is consistent with the actual Word document rendering effect.

[0061] Specifically, in step eight, when determining whether the text formatted according to the font size mid fully fits the reserved fillable range of the cell area to be filled, the judgment conditions include: the actual total height does not exceed the fillable height of the cell area to be filled, and the maximum text width of all rows does not exceed the fillable width of the cell area to be filled.

[0062] In a specific embodiment of the present invention, when the adaptive wrapper determines whether the text formatted according to the font size mid fully fits the reserved fillable range of the cell area to be filled, the determination condition is: the actual total height does not exceed the fillable height of the cell area to be filled, and the maximum text width of all lines does not exceed the fillable width of the cell area to be filled. Only when both of the above conditions are met simultaneously is the current font size determined to be compatible.

[0063] Specifically, before step one, there is also a template pre-definition step: embedding structured tags in the table cells of the Word document template that need to be dynamically filled. The structured tags contain tag names and dynamic parameter information.

[0064] In a specific embodiment of the present invention, before the process starts, the data preprocessing unit of the data layer predefines a Word document template and embeds structured tags in the table cells that need to be dynamically filled. The structured tags contain tag names and dynamic parameter information, providing a basis for subsequent tag parsing and data mapping.

[0065] Specifically, in step two, the tag blocks in the Word document template are located by traversing through regular expression matching, and the tag names and dynamic parameters are extracted to complete the parsing of placeholder tags.

[0066] In a specific embodiment of the present invention, the tag parsing engine uses regular expression matching to traverse and locate the tag blocks in the Word document template, extracts the tag names and dynamic parameters, and completes the parsing of placeholder tags.

[0067] An adaptive Word table data dynamic encapsulation system, applied to any of the above-mentioned adaptive Word table data dynamic encapsulation methods, includes a user layer, a control layer, a service layer, and a data layer.

[0068] In a specific embodiment of the present invention, the system is built on Spring Boot and Vue, and adopts a layered design, including the following core modules: user layer, control layer, service layer, and data layer. The user layer controls various user permissions within the system to ensure that only specific users can access and export sensitive data. The control layer aggregates and validates various requests and sends the required Word templates to the service layer for processing. After obtaining the templates, the service layer calculates relevant dynamic parameter models based on the template data and simultaneously sends requests to the data layer. The data layer is built on a MySQL relational database, storing raw data and relationships, and achieving logical integration of multi-table data through foreign key constraints and join queries.

[0069] Specifically, the user layer includes ordinary user units, special user units, and administrator units. The user layer is used to control the operation permissions of various types of users in the system and to determine whether to allow users to initiate data export requests based on user permissions.

[0070] In a specific embodiment of the present invention, the user layer controls the permissions of various users within the system to ensure that only specific users can access and export sensitive data. Ordinary user units are not authorized to initiate data export requests, while special user units are authorized to do so. The administrator unit can add, modify, and delete permissions for both ordinary and special user units.

[0071] Specifically, the control layer includes an access control unit, a data assembly unit, and a file stream transmission unit. The control layer is connected to the user layer and the service layer. The control layer is used to receive user requests sent by the user layer, verify the user requests through the access control unit, convert the generated documents into binary file streams through the data assembly unit, and push the binary file streams to the user layer in real time through the file stream transmission unit.

[0072] In a specific embodiment of the present invention, the control layer is primarily responsible for receiving user requests, coordinating the service layer to complete data assembly, converting the generated document into a binary file stream, and pushing the file stream to the user layer in real time. The permission check unit determines whether the current service can continue based on the data fields in the user request. If an abnormal data request exists in the user request, the current service is interrupted and a prompt message is returned to the user layer. The data assembly unit converts the generated document into a binary file stream, and the file stream transmission unit pushes the binary file stream to the user layer in real time. The control layer also sends the Word document template selected by the user to the service layer for processing.

[0073] Specifically, the service layer includes a data storage unit, a model calculation unit, a tag parsing unit, a data mapping unit, and an adaptive encapsulation unit. The service layer is connected to the control layer, the user layer, and the data layer. The service layer is used to receive Word document templates issued by the control layer, calculate dynamic parameter models based on the Word document templates through the model calculation unit, and send data requests to the data layer through the data storage unit.

[0074] In a specific embodiment of the present invention, the service layer processes user requests in the system, mainly in two categories: one category involves users storing, modifying, or clearing data in Word tables; the other category involves users retrieving and exporting adaptively filled Word documents. The service layer receives a Word document template from the control layer, calculates relevant dynamic parameter models using the model calculation unit based on the template, and simultaneously sends a data request to the data layer through the data storage unit. The export module mainly includes a tag parsing engine, a data mapping module, and an adaptive encapsulator. The tag parsing unit uses regular expression matching to traverse and locate tag blocks in the template, extracting tag names and dynamic parameters; the data mapping unit retrieves corresponding data from the MySQL database in the data layer based on the tag names and injects parameters to generate formatted text; the adaptive encapsulation unit calculates the optimal font size using template parameters and then encapsulates the filled data according to the target parameter rules.

[0075] Specifically, the data layer includes a data preprocessing unit and a MySQL unit. The data layer is connected to the service layer. The data layer is used to preprocess data through the data preprocessing unit, persist data through the MySQL unit, and provide standardized data to the service layer when the service layer needs to access the data.

[0076] In a specific embodiment of the present invention, the data layer is primarily responsible for data preprocessing and persistent data storage. The data preprocessing unit predefines Word document templates and embeds structured tags within table cells that require dynamic population. These structured tags contain tag names and dynamic parameter information. The MySQL unit, built on a MySQL relational database, stores raw data and the relationships between data, achieving logical integration of multi-table data through foreign key constraints and join queries. When the service layer needs to access relevant data, the data layer provides standardized data.

[0077] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. An adaptive method for dynamically encapsulating Word table data, characterized in that, Includes the following steps: Step 1: Process Initiation and Basic Data Acquisition: Obtain the user business data to be filled and read the Word document template selected by the user. Step 2: Template Tag Preprocessing: Parse the predefined placeholder tags in the Word document template, establish the field mapping relationship between the placeholder tags and the user business data, and complete the association mapping between tags and data; Step 3: Text pre-filling: Convert the user business data into text to be filled according to the mapping relationship, replace the corresponding placeholder labels in the Word document template, and complete the initial data placeholder; Step 4: Initialize the binary search parameters: Set the initial range for font size search for the cell range to be filled, define the minimum font size boundary as low and the maximum font size boundary as high, and complete the initialization of the search range; Step 5: Interval validity check: Check if the current search interval satisfies low≤high. If not, exit the loop and output the final font size result. If it satisfies, proceed to step 6. Step 6: Calculate the middle font size: Take the middle value of the current search interval as the font size mid to be tested; Step 7: Layout parameter calculation: Arrange the text to be filled according to the font size mid to be tested, calculate the actual total number of lines after text wrapping and the maximum text width of all lines, and calculate the actual total height of the text. Step 8: Region Adaptability Judgment: Determine whether the text formatted according to the font size mid to be tested fully adapts to the reserved fillable range of the cell region to be filled. If it adapts, update the minimum boundary low of the search interval low=mid+1 and return to step 5. If it does not adapt, update the maximum boundary high of the search interval high=mid-1 and return to step 5. Step 9: Document Output Generation: When the binary search loop ends (i.e., low > high), the final optimal font size is taken as the largest font size that fits the current cell. All data tags are then reformatted according to the optimal font size and bound to the corresponding positions in the Word document template to generate a complete document data stream output.

2. The adaptive Word table data dynamic encapsulation method according to claim 1, characterized in that, In step seven, when calculating the actual total number of lines after text wrapping and the maximum text width of all lines, the line spacing coefficient and cell margin are also obtained as input parameters for the layout parameter calculation.

3. The adaptive Word table data dynamic encapsulation method according to claim 1, characterized in that, In step eight, when determining whether the text formatted according to the font size mid fully fits the reserved fillable range of the cell area to be filled, the determination conditions include: the actual total height does not exceed the fillable height of the cell area to be filled, and the maximum text width of all lines does not exceed the fillable width of the cell area to be filled.

4. The adaptive Word table data dynamic encapsulation method according to claim 1, characterized in that, Before step one, there is also a template predefinition step: embedding structured tags in the table cells of the Word document template that need to be dynamically filled, wherein the structured tags include tag names and dynamic parameter information.

5. The adaptive Word table data dynamic encapsulation method according to claim 1, characterized in that, In step two, the tag blocks in the Word document template are located by traversing through regular expression matching, and the tag names and dynamic parameters are extracted to complete the parsing of the placeholder tags.

6. An adaptive Word table data dynamic encapsulation system, characterized in that, The adaptive Word table data dynamic encapsulation method described in any one of claims 1-5 includes a user layer, a control layer, a service layer, and a data layer. The user layer includes ordinary user units, special user units, and administrator units. The user layer is used to control the operation permissions of various types of users in the system and determine whether to allow users to initiate data export requests based on user permissions. The user layer is connected to the control layer and the service layer respectively. The control layer includes a permission checking unit, a data assembly unit, and a file stream transmission unit. The control layer is connected to the user layer and the service layer. The control layer is used to receive user requests sent by the user layer, verify the user requests through the permission checking unit, convert the generated document into a binary file stream through the data assembly unit, and push the binary file stream to the user layer in real time through the file stream transmission unit. The control layer also sends the Word document template selected by the user to the service layer. The service layer includes a data storage unit, a model calculation unit, a tag parsing unit, a data mapping unit, and an adaptive encapsulation unit. The service layer is connected to the control layer, the user layer, and the data layer. The service layer receives the Word document template from the control layer, calculates a dynamic parameter model based on the Word document template using the model calculation unit, and sends a data request to the data layer through the data storage unit. The tag parsing unit uses regular expression matching to locate tag blocks in the Word document template and extracts tag names and dynamic parameters. The data mapping unit retrieves corresponding data from the data layer based on the tag names and injects parameters to generate formatted text. The adaptive encapsulation unit is used to obtain user data and a specified Word document template, parse the table and bind various data tags to the required data in the data layer, initialize the minimum and maximum font size, line spacing coefficient and cell margin according to the font, calculate the number of line breaks and content height required when the data content fills the corresponding cell using the binary search method, confirm whether the cell width and height requirements are met, obtain the optimal solution for the font size, and export the corresponding file stream. The data layer includes a data preprocessing unit and a MySQL unit. The data layer is connected to the service layer. The data layer is used to preprocess data through the data preprocessing unit, persist data through the MySQL unit, and provide standardized data to the service layer when the service layer needs to access the data.

7. The adaptive Word table data dynamic encapsulation system according to claim 6, characterized in that, In the user layer, ordinary user units are not authorized to initiate data export requests, while special user units are authorized to initiate data export requests. The administrator unit is used to add, modify, and delete permissions for ordinary user units and special user units.

8. The adaptive Word table data dynamic encapsulation system according to claim 6, characterized in that, In the control layer, the permission checking unit determines whether to continue the service based on the data fields in the user request. If there is an abnormal data request in the user request, the service is interrupted and a prompt message is returned to the user layer. The data assembly unit converts the generated document into a binary file stream, and the file stream transmission unit pushes the binary file stream to the user layer in real time.

9. The adaptive Word table data dynamic encapsulation system according to claim 6, characterized in that, In the service layer, the tag parsing unit uses regular expression matching to traverse and locate the tag blocks in the Word document template, and extracts the tag names and dynamic parameters. The data mapping unit retrieves the corresponding data in the data layer based on the tag name and injects parameters to generate formatted text; The adaptive encapsulation unit calculates the optimal font size using a binary search method and encapsulates the filled data according to the target parameter rules.

10. The adaptive Word table data dynamic encapsulation system according to claim 6, characterized in that, In the data layer, the data preprocessing unit embeds structured tags in the table cells of the Word document template that need to be dynamically filled. The structured tags include tag names and dynamic parameter information. The MYSQL unit is built on the MySQL relational database and is used to store raw data and the relationships between data. It achieves logical integration of data from multiple tables through foreign key constraints and join queries.