Table processing method and device, computer equipment and readable storage medium
The method generates and merges tables based on layout document requirements, enhancing flexibility and diversity, addressing limitations in existing layout document systems.
Patent Information
- Application Number
- CN202411250555.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2024-12-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing layout document systems lack flexibility and diversity in inserting tables, particularly in complex structures, limiting their usability in various scenarios.
A method to generate an initial table based on title, header, and column information, merge cells according to merging information, and insert the merged table into a preset layout page using position information, allowing for flexible and complex table layouts.
Enhances the flexibility and diversity of table layouts in layout documents, improving user experience and efficiency by enabling more complex and adaptable table structures.
Smart Images

Figure CN119089878A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of formatted document processing, and in particular to a table processing method, device, computer equipment and readable storage medium. Background Art
[0002] A layout document is an electronic document with a fixed layout, such as PDF (Portable Document Format) format documents and OFD (Open Fixed-layout Document) format documents. Layout documents are widely used due to their convenience and stability. However, inserting a table into a layout document is complicated.
[0003] The table insertion function of traditional layout documents only supports simple row and column structures, which makes it impossible for users to create complex tables. This limits the flexibility of the table and the diversity of the layout, and cannot meet the advanced requirements for table structure in different scenarios. Summary of the invention
[0004] Based on this, it is necessary to provide a table processing method, device, computer equipment, computer readable storage medium and computer program product to address the above technical problems, which can improve the flexibility and diversity of tables inserted into preset layout pages.
[0005] In a first aspect, the present application provides a form processing method, comprising:
[0006] Get the data source, which includes title information, table header information, number of rows, number of columns, and cell merge information;
[0007] Generate an initial table based on title information, table header information, row number information and column number information;
[0008] According to the cell merging information, merge the cells of the initial table to obtain the merged table;
[0009] Based on the position information of each cell in the merged table, the merged table is inserted into the preset layout page using the operator corresponding to the preset layout page.
[0010] In one embodiment, cells of an initial table are merged according to the cell merging information to obtain a merged table, including:
[0011] When the cell merging information includes column merging information, the width ratio of each row of cells in the initial table is obtained; and the width ratio is adjusted according to the column merging information.
[0012] Adjust the width of each row of cells in the initial table based on the adjusted width ratio;
[0013] Based on the adjusted width, determine the merged table.
[0014] In one embodiment, adjusting the width of each row of cells in the initial table based on the adjusted width ratio includes:
[0015] According to the page width of the preset layout page, determine the starting position of the initial table in the preset layout page;
[0016] If the sum of the initial table width of the initial table and the abscissa of the starting position is greater than the page width, determining the adjusted table width based on the page width and the abscissa of the starting position;
[0017] According to the adjusted table width and the adjusted width ratio, the width of each row of cells in the initial table is proportionally scaled to determine the adjusted width corresponding to each row of cells.
[0018] In one embodiment, cells of an initial table are merged according to the cell merging information to obtain a merged table, including:
[0019] In the case where the cell merging information includes row merging information, traverse each row of cells in the initial table, and if the row merging information indicates that there is no merging in the current row, adjust the height of each cell in the current row to the maximum height of each cell in the current row;
[0020] If the row merge information indicates that the current row is merged, determine the target column and the target rows where the multiple cells to be merged are located according to the row merge information; and adjust the heights of the cells in the target rows based on the heights of the multiple cells to be merged in the target column;
[0021] A merged table is determined based on the adjusted heights of the cells in the multiple target rows.
[0022] In one embodiment, adjusting the heights of the cells in the target rows based on the heights of the cells to be merged in the target column includes:
[0023] If the sum of the heights of the multiple cells to be merged in the target column is less than the sum of the maximum heights corresponding to all target rows, the heights of the cells in the multiple target rows are adjusted to the maximum heights corresponding to the target rows;
[0024] If the sum of the heights of the multiple cells to be merged in the target column is greater than the sum of the maximum heights corresponding to all target rows, the sum of the heights is proportionally divided into each target row based on the row heights of each of the multiple target rows to obtain the adjusted heights corresponding to each cell in the multiple target rows.
[0025] In one embodiment, based on the position information of each cell in the merged table, the merged table is inserted into the preset layout page using an operator corresponding to the preset layout page, including:
[0026] Get cell format requirements;
[0027] According to the cell format requirements, the merged table is formatted to obtain a formatted table;
[0028] Based on the position information of each cell in the merged table, the formatted table is inserted into the preset layout page using the operator corresponding to the preset layout page.
[0029] In one embodiment, the form processing method further includes:
[0030] If the vertical coordinate of any cell in the merged table exceeds the coordinate range of the preset layout page, all rows between the row where the current cell is located and the last row of the merged table are moved to the new layout page.
[0031] In a second aspect, the present application further provides a form processing device, comprising:
[0032] The acquisition module is used to obtain the data source, which includes title information, table header information, row number information, column number information and cell merge information;
[0033] A generation module, used for generating an initial table according to title information, table header information, row number information and column number information;
[0034] The merging module is used to merge cells of the initial table according to the cell merging information to obtain the merged table;
[0035] The insert module is used to insert the merged table into the preset layout page based on the position information of each cell in the merged table and using the operator corresponding to the preset layout page.
[0036] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0037] Get the data source, which includes title information, table header information, number of rows, number of columns, and cell merge information;
[0038] Generate an initial table based on title information, table header information, row number information and column number information;
[0039] According to the cell merging information, merge the cells of the initial table to obtain the merged table;
[0040] Based on the position information of each cell in the merged table, the merged table is inserted into the preset layout page using the operator corresponding to the preset layout page.
[0041] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0042] Get the data source, which includes title information, table header information, number of rows, number of columns, and cell merge information;
[0043] Generate an initial table based on title information, table header information, row number information and column number information;
[0044] According to the cell merging information, merge the cells of the initial table to obtain the merged table;
[0045] Based on the position information of each cell in the merged table, the merged table is inserted into the preset layout page using the operator corresponding to the preset layout page.
[0046] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0047] Get the data source, which includes title information, table header information, number of rows, number of columns, and cell merge information;
[0048] Generate an initial table based on title information, table header information, row number information and column number information;
[0049] According to the cell merging information, merge the cells of the initial table to obtain the merged table;
[0050] Based on the position information of each cell in the merged table, the merged table is inserted into the preset layout page using the operator corresponding to the preset layout page.
[0051] The above-mentioned table processing method, device, computer equipment, computer-readable storage medium and computer program product generate an initial table through the title information, header information, row number information and column number information in the data source. On the basis of the initial table, the initial table is merged based on the cell merging information in the data source to obtain a merged table. The merged table includes title information, header information and other data rows, which is conducive to intuitively displaying the structure and meaning of the table; at the same time, the operator corresponding to the preset layout page is used, combined with the position information of each cell, to insert the merged table into the preset layout page. Since the information in the data source can be flexibly set according to needs, the cells in the merged table can cover multiple rows or columns, so that the table can have a more flexible and complex layout structure, thereby helping to improve the flexibility and diversity of the table inserted into the preset layout page. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0053] FIG1 is an application environment diagram of a table processing method in one embodiment;
[0054] FIG2 is a schematic diagram of a flow chart of a table processing method in one embodiment;
[0055] FIG3 is a schematic diagram of the overall flow of a table processing method in one embodiment;
[0056] FIG4 is a structural block diagram of a table processing device in one embodiment;
[0057] FIG. 5 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0058] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0059] The table processing method provided in the embodiment of the present application can be applied to the application environment shown in Figure 1. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. This embodiment uses the method applied to the terminal 102 as an example. It can be understood that the method can also be applied to the server, and can also be applied to the system including the terminal and the server, and is implemented through the interaction between the terminal and the server. The terminal 102 obtains a data source, and the data source includes title information, header information, row number information, column number information and cell merge information; based on the title information, header information, row number information and column number information, an initial table is generated; according to the cell merge information, the initial table is merged to obtain a merged table; based on the position information of each cell in the merged table, the operator corresponding to the preset layout page is used to insert the merged table into the preset layout page. The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. Head-mounted devices may be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server 104 may be an independent physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides cloud computing services.
[0060] In an exemplary embodiment, as shown in FIG2 , a table processing method is provided, which is described by taking the method applied to the terminal 102 in FIG1 as an example, and includes the following steps 202 to 208 . Among them:
[0061] Step 202, obtaining a data source, the data source includes title information, table header information, row number information, column number information and cell merge information.
[0062] The data source refers to the data information to be inserted into the table, which may be obtained by manual input, or may be read from a file, or may be extracted from a database.
[0063] The title information is information used to indicate the subject of the table to be inserted, and the title information includes the number of rows in the title row and the title content. The header information is information used to indicate the category of the data in each column of the table to be inserted, and the header information includes the number of rows in the header row and the header content. The number of rows information is information used to indicate the number of rows in the table to be inserted. The number of columns information is information used to indicate the number of columns in the table to be inserted. The cell merge information is information used to characterize the cells in the table to be inserted that need to be merged into columns or rows, and the cell merge information includes at least one of the column merge information or the row merge information.
[0064] The data source generally includes row number information and column number information. In some embodiments, the data source may also include at least one of title information, table header information, and cell merge information.
[0065] Step 204, generating an initial table according to the title information, table header information, row number information and column number information.
[0066] The initial table is a two-dimensional array containing cell data. Cell data includes location information, cell content, format characteristics, etc. The number of rows in the initial table is equal to the sum of the number of rows in the data source, the number of rows in the title row, and the number of rows in the header row. The number of columns in the initial table is equal to the number of columns in the data source.
[0067] Step 206: merge cells of the initial table according to the cell merging information to obtain a merged table.
[0068] Among them, since the cell merge information indicates the information of the cells that need to be merged in columns or rows, the terminal can determine the columns that need to be merged based on the column merge information in the cell merge information, and then merge the columns that need to be merged; and determine the rows that need to be merged based on the row merge information in the cell merge information, and then merge the rows that need to be merged to obtain the merged table.
[0069] Step 208: Based on the position information of each cell in the merged table, the merged table is inserted into the preset layout page using the operator corresponding to the preset layout page.
[0070] The preset layout page refers to a layout page for inserting a table. The preset layout page can be a PDF format document page, an OFD format document page, and the like.
[0071] The preset layout page complies with the format specifications of the corresponding layout document. The presentation of the preset layout page is independent of the device. When reading, printing or printing on various devices, the presentation results of the layout are consistent.
[0072] The position information refers to the position coordinates of each cell in the merged table. The position of the cell in the preset layout page can be determined based on the position information.
[0073] Operators refer to operators that perform graphic operations in a preset layout page. Operators should comply with the standard syntax specifications of the corresponding layout document. For example, a preset layout page is a PDF document page, and operators can be used to control line drawing, layout, font, color, transparency, interactivity and other properties in the PDF page.
[0074] The terminal draws the merged table in the preset layout page based on the position information of each cell in the merged table and uses corresponding operators to insert the merged table into the preset layout page, thereby enhancing the flexibility and operability of inserting the table into the preset layout page, which is conducive to improving the user experience and efficiency of using tables in preset layout documents.
[0075] In the above table processing method, an initial table is generated through the title information, header information, row number information, and column number information in the data source. On the basis of the initial table, the initial table is merged based on the cell merging information in the data source to obtain a merged table. The merged table includes title information, header information and other data rows, which is conducive to intuitively displaying the structure and meaning of the table; at the same time, the operator corresponding to the preset layout page is used, combined with the position information of each cell, to insert the merged table into the preset layout page. Since the information in the data source can be flexibly set according to needs, the cells in the merged table can cover multiple rows or columns, so that the table can have a more flexible and complex layout structure, thereby helping to improve the flexibility and diversity of the table inserted into the preset layout page.
[0076] In an exemplary embodiment, cells of an initial table are merged according to cell merge information to obtain a merged table, including: when the cell merge information includes column merge information, obtaining the width ratio of each row of cells in the initial table; adjusting the width ratio according to the column merge information; adjusting the width of each row of cells in the initial table based on the adjusted width ratio; and determining the merged table based on the adjusted width.
[0077] The cell merging information includes column merging information, indicating that there are cells in the initial table that need to be merged into columns.
[0078] The width ratio refers to the ratio of the widths of cells in the same row in the initial table. In some embodiments, the width ratio can be read from a data source. In other embodiments, the data source includes the width of each cell, and the width ratio of each row of cells can be determined based on the widths of cells in the same row.
[0079] The column merging information indicates the columns that need to be merged. According to the column merging information, these columns can be merged to change the width ratio of the initial table. For example, the initial table is a 4×5 table, in which the width ratio of a row of cells is 4:3:2:1:1. The column merging information indicates that the first column and the second column are to be merged. Therefore, after the first column and the second column are merged, the adjusted width ratio is 7:2:1:1.
[0080] The width of each row of cells can be adjusted according to the adjusted width ratio to obtain the adjusted width of each cell in each row. After the columns are merged, the width of each cell in each row of the merged table is the corresponding adjusted width.
[0081] In this embodiment, when the cell merging information includes column merging information, the width ratio of each row of cells in the initial table is adjusted according to the column merging information, and the width is adjusted using the adjusted width ratio to obtain a merged table. In this merged table obtained by merging columns, cells can cover multiple columns, so that the table can display a more complex layout structure, for example, complex registration or statistical tables, thereby improving the flexibility and diversity of the table layout.
[0082] In an exemplary embodiment, the width of each row of cells in the initial table is adjusted based on the adjusted width ratio, including: determining the starting position of the initial table in the preset layout page according to the page width of the preset layout page; if the sum of the initial table width of the initial table and the horizontal coordinate of the starting position is greater than the page width, determining the adjusted table width based on the page width and the horizontal coordinate of the starting position; and scaling the width of each row of cells in the initial table proportionally according to the adjusted table width and the adjusted width ratio to determine the adjusted width corresponding to each row of cells.
[0083] The page width refers to the width of the preset layout page. The starting position refers to the position of the starting cell of the initial table in the preset layout page, for example, it can be the position of the upper left corner of the initial table. The starting position includes a horizontal coordinate and a vertical coordinate. The horizontal coordinate of the starting position should be within the width range of the preset layout page, and the vertical coordinate of the starting position should be within the height range of the preset layout page.
[0084] To ensure that the table inserted into the preset layout page can be fully presented, it is necessary to adjust the width of each cell. The terminal can determine the width range of the initial table in the preset layout page based on the page width. For example, if the page width is 20, the width range can be 0-20, and the starting position can be 2.
[0085] The initial table width refers to the width of the initial table. The sum of the initial table width and the horizontal coordinate of the starting position indicates the width of the initial table in the preset layout page. If the width is greater than the page width, it means that the initial table will exceed the page width of the preset layout page. If the initial table is directly inserted, the initial table will not be fully presented. Therefore, the table width needs to be adjusted.
[0086] To ensure that the table after the table width is adjusted can be completely in the preset layout page, the adjusted table width can be the difference between the page width and the horizontal coordinate of the starting position. For example, the starting position is (x0, y0), the page width is pw, and the adjusted table width w=pw-x0.
[0087] The width of each cell in each row can be scaled proportionally according to the adjusted width ratio. The width ratio between the adjusted widths corresponding to the cells in each row should be equal to the width ratio before proportional scaling. Moreover, the sum of the adjusted widths corresponding to each cell in each row should be equal to the adjusted table width. This ensures that the table inserted into the preset layout page is fully presented and that the width ratio of the table remains unchanged.
[0088] In some embodiments, determining the merged table based on the adjusted width includes: determining the horizontal coordinates of each row of cells according to the horizontal coordinates of the starting position and the adjusted width, and determining the merged cells according to the horizontal coordinates of each row of cells and the adjusted width.
[0089] In this embodiment, the starting position corresponding to the initial table is determined by the page width of the preset layout page. When the sum of the initial table width and the horizontal coordinate of the starting position is greater than the page width, it indicates that the initial table will exceed the range of the preset layout page. Therefore, the width of the initial table cell is scaled proportionally to ensure that the adjusted width has the same proportional relationship as before adjustment, and to ensure that the table with adjusted width can be fully presented in width when inserted into the preset layout page, thereby ensuring the presentation integrity of the table.
[0090] In an exemplary embodiment, cells of an initial table are merged according to cell merge information to obtain a merged table, including: when the cell merge information includes row merge information, each row of cells in the initial table is traversed, and if the row merge information indicates that there is no merge in the current row, the height of each cell in the current row is adjusted to the maximum height of each cell in the current row; if the row merge information indicates that there is a merge in the current row, the target column and multiple target rows where multiple cells to be merged are located are determined according to the row merge information; based on the heights of the multiple cells to be merged in the target column, the corresponding heights of each cell in the multiple target rows are adjusted; based on the adjusted heights of each cell in the multiple target rows, the merged table is determined.
[0091] The cell merging information includes row merging information, indicating that there are cells in the initial table that need to be merged.
[0092] The terminal traverses each row of cells in the initial table and determines whether the current row is merged based on the row merge information. If the row merge information indicates that the current row is not merged, there is no need to perform a row merge operation on the current row. The terminal can adjust the height of each cell in the current row to the maximum height of each cell in the current row to ensure that each cell in the current row has the same maximum height, which is conducive to ensuring that each cell is neatly arranged and improving the information display effect of the table.
[0093] The cells to be merged refer to the cells that need to be merged. For multiple cells to be merged that are to be merged into a large cell, they are often in different rows of the same column. If the row merge information indicates that there is a merge in the current row, the row merge information determines the target column and multiple target rows where the cells to be merged that need to be merged are located. For example, a 4×5 table, in which the two cells in the second and third rows of the first column are merged, is a new cell in the second row and the first column, the target column is the first column, and the multiple target rows include the second row and the third row.
[0094] Since multiple cells to be merged need to be merged in rows, the height of each cell may change after the row is merged. For example, after the two cells in the second and third rows of the first column are merged in rows, the height of the new second row and first column cell can be equal to the sum of the heights of the two cells in the second and third rows of the first column.
[0095] After the rows are merged, the height of each cell in the merged table should be the corresponding adjusted height.
[0096] In some embodiments, the cell merging information includes both column merging information and row merging information, so the terminal can first merge the columns of the initial table, and then merge the rows of the table after the column merging to obtain the merged table. Alternatively, the terminal can first merge the rows of the initial table, and then merge the columns of the table after the row merging to obtain the merged table.
[0097] In this embodiment, by traversing each row of cells when the cell merging information includes row merging information, it is determined whether each row needs to be merged; for rows that do not need to be merged, the height of each cell in the row can be uniformly adjusted to the maximum height of the row, which is conducive to the effective display of the cell content and improves the display effect of the table; for rows that need to be merged, multiple cells to be merged in the target column can be merged according to the row merging information to obtain a merged table. In this merged table obtained by row merging, cells can cover multiple rows, so that the table can display a more complex layout structure, thereby improving the flexibility and diversity of the table layout.
[0098] In an exemplary embodiment, based on the heights of multiple cells to be merged in the target column, the heights corresponding to each cell in multiple target rows are adjusted, including: if the sum of the heights of multiple cells to be merged in the target column is less than the sum of the maximum heights corresponding to all target rows, then the heights of each cell in the multiple target rows are adjusted to the maximum heights corresponding to each target row; if the sum of the heights of multiple cells to be merged in the target column is greater than the sum of the maximum heights corresponding to all target rows, then based on the row heights of the multiple target rows, the sum of the heights is geometrically divided into each target row to obtain the adjusted heights corresponding to each cell in the multiple target rows.
[0099] The maximum height corresponding to each target row refers to the maximum height of the cell heights in other columns of the target column in each target row. The maximum heights corresponding to all target rows are summed. If the sum of the heights of multiple cells to be merged in the target column is less than the sum of the maximum heights corresponding to all target rows, that is, the height after merging the cells is less than the sum of the maximum heights of the target rows, the terminal can adjust the heights of each cell in the multiple target rows to the maximum heights corresponding to each target row.
[0100] If the sum of the heights of multiple cells to be merged in the target column is greater than the sum of the corresponding maximum heights of all target rows, which means that the height after merging the cells is greater than the sum of the maximum heights of the target rows, the terminal can divide the heights of each target row in equal proportion, thereby increasing the height of each cell in the target row, and ensuring that each target row has a uniform height, the ratio of which is consistent with the ratio of the maximum height in the corresponding target row, thereby ensuring that the data in each target row is fully displayed.
[0101] For example, in a 4×5 table, if the second and third cells in the first column are merged into a new cell in the first column of the second row, first calculate the height h1 of the cell in the first column of the second row (i.e., the height after cell merging), then calculate the maximum height h2 of the second row except for the first column, calculate the maximum height h3 of the third row except for the first column, and obtain h4 = h2 + h3. If h1 < h4, then assign h4 to h1; if h1 > h4, then assign h1×h2÷(h2 + h3) to h2 and h1×h3÷(h2 + h3) to h3.
[0102] In some embodiments, based on the adjusted heights corresponding to each cell in multiple target rows, determining the merged table includes: determining the adjusted ordinate corresponding to each cell in each row according to the ordinate of the starting position and the adjusted heights corresponding to each cell in multiple target rows, and determining the merged table from the adjusted ordinates and adjusted heights corresponding to each cell in each row.
[0103] In this embodiment, when the sum of the heights of multiple cells to be merged in the target column is less than the sum of the maximum heights corresponding to all target rows, the heights of each cell in multiple target rows are adjusted to the maximum heights corresponding to each target row respectively. When the sum of the heights of multiple cells to be merged in the target column is greater than the sum of the maximum heights corresponding to all target rows, the sum of the heights is divided proportionally among the target rows, ensuring that each target row has a unified height, and the ratio of this height is consistent with the ratio of the maximum height in the corresponding target row, which can ensure the complete display of the data in each target row and improve the display effect of the table.
[0104] In an exemplary embodiment, based on the position information of each cell in the merged table, using the operators corresponding to the preset layout page to insert the merged table into the preset layout page includes: obtaining the cell format requirements; performing format settings on the merged table according to the cell format requirements to obtain a formatted table; and based on the position information of each cell in the merged table, using the operators corresponding to the preset layout page to insert the formatted table into the preset layout page.
[0105] Among them, the cell format requirements refer to the user's format requirements for the cells in the table. In some embodiments, the terminal includes a human-computer interaction interface, and the cell format requirements can be obtained by acquiring the format requirement text input by the user and parsing the format requirement text. For example, the cell format requirements include border styles, color settings, and alignment methods. Among them, the border styles include whether there is a border, the thickness of the border, etc., the color settings include the border color, background color, and transparency, and the alignment methods include the horizontal and vertical alignment methods of the cell content.
[0106] The terminal formats the merged table according to the cell format requirements to obtain a formatted table, so that the formatted table can be inserted into a preset layout page.
[0107] In this embodiment, by obtaining the cell format requirements, formatting the merged table according to the cell format requirements, and then inserting the formatted table into the preset layout page, since the format of the table can be flexibly set according to user needs, the flexibility and diversity of the table are further improved.
[0108] In an exemplary embodiment, the table processing method also includes: if the vertical coordinate of any cell in the merged table exceeds the coordinate range of the preset layout page, all rows between the row where the current cell is located and the last row of the merged table are moved to the new layout page.
[0109] Among them, the vertical coordinate of any cell in the merged table exceeds the coordinate range of the preset layout page, indicating that the merged table exceeds the preset layout page in the vertical direction, and the entire merged table cannot be fully presented in the preset layout page. Therefore, the terminal moves all rows between the row where the current cell is located and the last row of the merged table to the new layout page. This method of cross-page processing of the part that exceeds the preset layout page can ensure that the table is presented completely.
[0110] In some embodiments, a newly created layout page may include a title row and a header row, and the title row and the header row may adopt the information of the title row and the header row of the merged cell, including the format, size, and cell content, etc. The vertical coordinate of each cell in the newly created layout page may be expressed as: new vertical coordinate = old vertical coordinate - the height of the spanned pages - the distance from the top of the page to the spanned pages. Among them, the new vertical coordinate represents the vertical coordinate of each cell in the newly created layout page, the old vertical coordinate represents the vertical coordinate of the corresponding cell in the merged cell, the height of the spanned pages refers to the height of all rows between the previous row of the row where the current cell is located and the first row of the merged table, and the distance from the top of the page to the top of the page refers to the distance from the starting row in the newly created layout page to the top of the page.
[0111] In other embodiments, if the horizontal coordinate of any cell in the merged table exceeds the coordinate range of the preset layout page, all columns between the column where the current cell is located and the last column of the merged table are moved to the new layout page. The horizontal coordinate of each cell in the new layout page can be expressed as: new horizontal coordinate = old horizontal coordinate - the width of the page span - the distance of the page span from the left side of the page. Among them, the new horizontal coordinate represents the horizontal coordinate of each cell in the new layout page, the old horizontal coordinate represents the horizontal coordinate of the corresponding cell in the merged cell, the width of the page span refers to the width of all columns between the previous column of the column where the current cell is located and the first row and column of the merged table, and the distance of the page span from the left side of the page refers to the distance from the starting column in the new layout page to the left side of the page.
[0112] In this embodiment, by determining whether the vertical coordinate of any cell in the merged table exceeds the coordinate range of the preset layout page, if it exceeds, all rows between the row where the current cell is located and the last row of the merged table are moved to the new layout page. This cross-page processing method avoids the problem of obstruction of the table content and is conducive to the complete presentation of the table.
[0113] To explain the table processing method and effect in this solution in detail, the following is a most detailed example:
[0114] For the scenario of inserting a table into a preset layout page, the preset layout page may be a PDF format document page, an OFD format document page, etc. FIG3 is a schematic diagram of the overall flow of a table processing method in one embodiment.
[0115] 1. The terminal obtains the data source to be inserted into the table, which can be data manually entered, read from a file, or extracted from a database.
[0116] 2. Generate an initial table based on the title information, header information, number of rows and number of columns in the data source, defined as T1. If there are title rows and header rows in the data source, the number of rows in the initial table is equal to the number of rows in the data source plus the title row and header row, and the number of columns is equal to the number of columns in the data source.
[0117] 3. If the cell merge information in the data source includes column merge information, calculate the width ratio of each row of cells in the initial table T1 (the default is equal ratio), adjust the width ratio according to the column merge information, adjust the width of each row of cells in the initial table based on the adjusted width ratio, and determine the table T2 after the column merge based on the adjusted width. Example: A 4x5 table with a width ratio of 4:3:2:1:1, where the first and second columns of a row are merged, and the calculation shows that the first column accounts for 7, so the adjusted width ratio is 7:2:1:1.
[0118] 4. By adjusting the width of the table, the total number of columns in the table can be accommodated within the preset layout page. Obtain the starting position (x0, y0) and the initial table width w of the initial table in the data source. If the sum of the abscissa x0 of the starting position and the initial table width (i.e., x0 + w) exceeds the page width pw of the preset layout page, then the adjusted table width w = pw - x0. According to the width ratio of each row of cells in table T2 and the adjusted table width, perform equal ratio scaling according to the width ratio of each cell, so as to determine the abscissa and width of each cell in table T2 in the preset layout page, and generate table T3.
[0119] 5. When the cell merging information in the data source includes row merging information, calculate the height of each cell in the initial table T1. The calculation method is as follows: traverse each row. If there is no merging in the current row, the height of each cell in the current row is adjusted to the maximum height of the cells in the current row; if there is merging in the current row, calculate the sum of the heights of multiple cells to be merged in the target column and the heights of the cells corresponding to each row in multiple target rows. If the sum of the heights of multiple cells to be merged in the target column is greater than the sum of the maximum heights corresponding to each target row, then divide the excess value equally according to the proportion of each row. If the sum of the heights of multiple cells to be merged in the target column is less than the sum of the maximum heights corresponding to each target row, then adjust the heights of the cells in multiple target rows to the maximum heights corresponding to each target row respectively. For example: for a 4×5 table, where the second and third cells in the first column are merged into a new cell in the first column of the second row. First, calculate the height h1 of the cell in the first column of the second row (i.e., the height after cell merging), then calculate the maximum height h2 of the cells in the second row except the first column, calculate the maximum height h3 of the cells in the third row except the first column, and obtain h4 = h2 + h3. If h1 < h4, then assign h1 to h4; if h1 > h4, then assign h2 to h1×h2÷(h2 + h3), and assign h3 to h1×h3÷(h2 + h3). Thus, the ordinate and height of each cell in each row can be calculated. According to the abscissa and width of the cells in table T3, the coordinates of each cell, including the upper left coordinate and the lower right coordinate, can be known, and table T4 is generated.
[0120] 6. Determine whether there is a column span, that is, the column width exceeds the preset layout page. If (x0+w)>pw in step 4, first recalculate the horizontal coordinate and width of each cell in the table according to the width ratio of each row of cells in table T2 and the table width; then recalculate the vertical coordinate and height of each cell in the table according to the method of calculating the height in step 5. Get the coordinates (x1, y1) of the last cell, that is, the lower right cell, and the page height ph of the preset layout page. If y1<=ph, that is, the page height of the preset layout page can accommodate the table, then define the generated table T5.
[0121] 7. If table T5 exists, use table T5, otherwise use table T4. Get the cell format requirements, and set the cell style of the table according to the cell format requirements, including: border style (with or without border, border thickness); color settings (border color and background color, transparency can be set); alignment (horizontal and vertical alignment of cell content), and generate table T6. At this time, each cell in table T6 contains: coordinate information, data, and drawing style.
[0122] 8. Use the operator corresponding to the preset layout page, for example, the PDF operator, to insert the generated table T6 into the preset layout page. Check whether the position of each cell in the table (i.e., the upper left coordinate and the lower right coordinate) exceeds the coordinate range of the preset layout page. If it exceeds the coordinate range of the preset layout page, perform cross-page processing, that is, move the exceeding content to the next layout page or a new layout page, and display the title row and header row of the table on each page. The cross-page cell coordinate processing rules are as follows: if it is a row cross-page (i.e., T5 does not exist), the horizontal coordinate remains unchanged, and the new vertical coordinate = the old vertical coordinate - the height of the cross-page sum - the distance from the top of the page to the cross-page; if it is a column cross-page (i.e., T5 exists), the vertical coordinate remains unchanged, and the new horizontal coordinate = the old horizontal coordinate - the width of the cross-page sum - the distance from the left side of the page to the cross-page.
[0123] The table processing method generates an initial table through the title information, header information, row number information, and column number information in the data source. On the basis of the initial table, the initial table is merged based on the cell merging information in the data source to obtain a merged table. The merged table includes the title information, header information, and other data rows, which is conducive to intuitively displaying the structure and meaning of the table; at the same time, the operator corresponding to the preset layout page is used, combined with the position information of each cell, to insert the merged table into the preset layout page. Since the information in the data source can be flexibly set according to the needs, the cells in the merged table can cover multiple rows or columns, so that the table can have a more flexible and complex layout structure, which is conducive to improving the flexibility and diversity of the table inserted into the preset layout page. At the same time, the flexibility of the table layout is enhanced, and complex table layout and data display are realized, which is suitable for a variety of application scenarios, such as reports, statistical tables, and financial data tables. The readability and professionalism of the table are improved, and the setting of the title and header enhances the recognition and systematization of the table, especially when it is displayed across pages (the table exceeds the current page), the coherence and readability of the table content are ensured. The table layout and adaptability are optimized. The row height and width can be automatically adjusted or fixed, so that the table can adapt to the display needs of different contents and keep it neat and beautiful. The visual effect and diversity of the document are improved. The flexible border selection allows the table to conform to the design style of different documents, improving the overall aesthetics and professionalism of the document.
[0124] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0125] Based on the same inventive concept, the embodiment of the present application also provides a table processing device for implementing the table processing method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more table processing device embodiments provided below can refer to the limitations of the table processing method above, and will not be repeated here.
[0126] In an exemplary embodiment, as shown in FIG. 4 , a table processing device 400 is provided, comprising: an acquisition module 420 , a generation module 440 , a merging module 460 , and an inserting module 480 , wherein:
[0127] The acquisition module 420 is used to acquire a data source, where the data source includes title information, table header information, row number information, column number information, and cell merge information;
[0128] A generating module 440, for generating an initial table according to the title information, the header information, the row number information and the column number information;
[0129] A merging module 460 is used to merge cells of the initial table according to the cell merging information to obtain a merged table;
[0130] The inserting module 480 is used to insert the merged table into the preset layout page based on the position information of each cell in the merged table and using the operator corresponding to the preset layout page.
[0131] The above-mentioned table processing device generates an initial table through the title information, header information, row number information, and column number information in the data source. On the basis of the initial table, the initial table is merged based on the cell merging information in the data source to obtain a merged table. The merged table includes title information, header information and other data rows, which is conducive to intuitively displaying the structure and meaning of the table; at the same time, the operator corresponding to the preset layout page is used, combined with the position information of each cell, to insert the merged table into the preset layout page. Since the information in the data source can be flexibly set according to needs, the cells in the merged table can cover multiple rows or columns, so that the table can have a more flexible and complex layout structure, thereby helping to improve the flexibility and diversity of the table inserted into the preset layout page.
[0132] In one embodiment, cells of an initial table are merged according to the cell merge information to obtain a merged table, and the merge module 460 is also used to: when the cell merge information includes column merge information, obtain the width ratio of each row of cells in the initial table; adjust the width ratio according to the column merge information; adjust the width of each row of cells in the initial table based on the adjusted width ratio; and determine the merged table based on the adjusted width.
[0133] In one embodiment, the width of each row of cells in the initial table is adjusted based on the adjusted width ratio, and the merge module 460 is also used to: determine the starting position of the initial table in the preset layout page according to the page width of the preset layout page; if the sum of the initial table width of the initial table and the horizontal coordinate of the starting position is greater than the page width, determine the adjusted table width based on the page width and the horizontal coordinate of the starting position; and proportionally scale the width of each row of cells in the initial table according to the adjusted table width and the adjusted width ratio to determine the adjusted width corresponding to each row of cells.
[0134] In one embodiment, cells of an initial table are merged according to cell merge information to obtain a merged table, and the merge module 460 is further used for: when the cell merge information includes row merge information, traversing each row of cells in the initial table, if the row merge information indicates that there is no merge in the current row, adjusting the height of each cell in the current row to the maximum height of each cell in the current row; if the row merge information indicates that there is a merge in the current row, determining a target column and a plurality of target rows where multiple cells to be merged are located according to the row merge information; adjusting the corresponding heights of each cell in the multiple target rows based on the heights of the multiple cells to be merged in the target column; and determining the merged table based on the adjusted corresponding heights of each cell in the multiple target rows.
[0135] In one embodiment, based on the heights of multiple cells to be merged in the target column, the heights corresponding to each cell in multiple target rows are adjusted, and the merging module 460 is also used to: if the sum of the heights of multiple cells to be merged in the target column is less than the sum of the maximum heights corresponding to all target rows, then the heights of each cell in the multiple target rows are adjusted to the maximum heights corresponding to each target row; if the sum of the heights of multiple cells to be merged in the target column is greater than the sum of the maximum heights corresponding to all target rows, then based on the row heights of the multiple target rows, the sum of the heights is geometrically divided into each target row to obtain the adjusted heights corresponding to each cell in the multiple target rows.
[0136] In one embodiment, based on the position information of each cell in the merged table, the merged table is inserted into the preset layout page using the operator corresponding to the preset layout page, and the insertion module 480 is also used to: obtain cell format requirements; format the merged table according to the cell format requirements to obtain a formatted table; based on the position information of each cell in the merged table, the operator corresponding to the preset layout page is used to insert the formatted table into the preset layout page.
[0137] In one embodiment, the table processing device 400 also includes a processing module, which is used to: if the vertical coordinate of any cell in the merged table exceeds the coordinate range of the preset layout page, all rows between the row where the current cell is located and the last row of the merged table are moved to the new layout page.
[0138] Each module in the above table processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0139] In an exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG5. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner may be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a table processing method is implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0140] Those skilled in the art will understand that the structure shown in FIG. 5 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0141] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0142] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0143] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0144] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0145] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0146] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0147] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A table processing method, characterized in that: The method comprises: Obtaining a data source, wherein the data source includes title information, table header information, row number information, column number information, and cell merge information; Generate an initial table according to the title information, the table header information, the row number information and the column number information; Merge cells of the initial table according to the cell merging information to obtain a merged table; Based on the position information of each cell in the merged table, the merged table is inserted into the preset layout page using an operator corresponding to the preset layout page.
2. The method according to claim 1, characterized in that The step of merging cells of the initial table according to the cell merging information to obtain a merged table includes: In the case where the cell merging information includes column merging information, obtaining a width ratio of each row of cells in the initial table; and adjusting the width ratio according to the column merging information; Adjusting the width of each row of cells in the initial table based on the adjusted width ratio; Based on the adjusted width, determine the merged table.
3. The method according to claim 2, characterized in that The step of adjusting the width of each row of cells in the initial table based on the adjusted width ratio includes: Determining the starting position of the initial table in the preset layout page according to the page width of the preset layout page; If the sum of the initial table width of the initial table and the horizontal coordinate of the starting position is greater than the page width, determining the adjusted table width based on the page width and the horizontal coordinate of the starting position; According to the adjusted table width and the adjusted width ratio, the width of each row of cells in the initial table is proportionally scaled to determine the adjusted width corresponding to each row of cells.
4. The method according to claim 1, characterized in that The step of merging cells of the initial table according to the cell merging information to obtain a merged table includes: In the case where the cell merging information includes row merging information, traversing each row of cells in the initial table, and if the row merging information indicates that there is no merging in the current row, adjusting the height of each cell in the current row to the maximum height of each cell in the current row; If the row merging information indicates that the current row is merged, determine the target column and target rows where the multiple cells to be merged are located according to the row merging information; and adjust the heights of the cells in the target rows based on the heights of the multiple cells to be merged in the target column; A merged table is determined based on the adjusted heights of the cells in the multiple target rows.
5. The method according to claim 4, characterized in that The adjusting the heights of the cells in the target rows based on the heights of the cells to be merged in the target column includes: If the sum of the heights of the multiple cells to be merged in the target column is less than the sum of the maximum heights corresponding to all target rows, the heights of the cells in the multiple target rows are adjusted to the maximum heights corresponding to the target rows; If the sum of the heights of the multiple cells to be merged in the target column is greater than the sum of the maximum heights corresponding to all target rows, then based on the row heights of the multiple target rows, the sum of the heights is proportionally divided into each target row to obtain the adjusted heights corresponding to each cell in the multiple target rows.
6. The method according to claim 1, characterized in that The method of inserting the merged table into the preset layout page by using an operator corresponding to the preset layout page based on the position information of each cell in the merged table includes: Get cell format requirements; According to the cell format requirement, formatting the merged table to obtain a formatted table; Based on the position information of each cell in the merged table, the formatted table is inserted into the preset layout page using an operator corresponding to the preset layout page.
7. The method according to claim 1, characterized in that The method further comprises: If the vertical coordinate of any cell in the merged table exceeds the coordinate range of the preset layout page, all rows between the row where the current cell is located and the last row of the merged table are moved to the new layout page.
8. A table processing device, characterized in that: The device comprises: An acquisition module is used to acquire a data source, wherein the data source includes title information, table header information, row number information, column number information, and cell merge information; A generating module, used for generating an initial table according to the title information, the table header information, the row number information and the column number information; A merging module, used for merging cells of the initial table according to the cell merging information to obtain a merged table; The inserting module is used to insert the merged table into the preset layout page based on the position information of each cell in the merged table and using the operator corresponding to the preset layout page.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
