A method for implementing a PPT table conditional formatting function

By parsing the table objects and conditional formatting scripts in the PPT file and dynamically rendering the table cells, the problem of the lack of conditional formatting in PPT is solved, and custom conditional formatting is realized, which improves the display effect and scalability of PPT tables.

CN120744001BActive Publication Date: 2025-12-16CHINA LIFE INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511178558.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-22
Publication Date
2025-12-16
Estimated Expiration
2045-08-22

AI Technical Summary

Technical Problem

The lack of conditional formatting in PowerPoint makes it impossible for users to highlight specific data when presenting large amounts of data, affecting the effectiveness and efficiency of data presentation.

Method used

By receiving PPT files, parsing table objects and reading conditional formatting scripts, and dynamically rendering table cells, the system supports custom conditional formatting scripts to implement conditional formatting functionality for PPT tables.

Benefits of technology

It improves the data display effect and efficiency of PPT tables, supports users to write custom scripts to implement complex business rules, enhances the scalability and practicality of templates, reduces user learning costs and increases the flexibility of cross-environment deployment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120744001B_ABST
    Figure CN120744001B_ABST
Patent Text Reader

Abstract

The application provides a kind of method for realizing PPT table conditional format function, comprising the following steps: S1: receiving the PPT file that user transmits, creates into PPT object;S2: traversing the element object in PPT object, judges and stores table object into table set;S3: judging and traversing the table object in table set, reads conditional format script content and parses and stores into script set;S4: traversing the script object in script set, according to the cell start and end position of current script object, filters out the table cell object that meets the range from current table object;S5: executes conditional function and filters out the table cell object that needs to set style;S6: executes style function to complete the conditional style rendering of table cell;The method is automatically parsed PPT file, and dynamically applies conditional format to table according to the real-time data of table, realizes dynamic visual effect, and improves work efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and particularly relates to a method for realizing PPT table conditional format function. BACKGROUND

[0002] In modern office software Excel, conditional format is a built-in function, which can judge the data in the cells according to the conditions set by the user, and display the cells meeting the conditions with a specially defined format, and the user can set certain conditions to highlight the data to be displayed; this function greatly improves the readability and intuitiveness of data.

[0003] Although Excel has powerful conditional format function, this function is not supported in PPT; PPT is a tool commonly used for display and demonstration, and its table function is relatively simple, mainly used for text and numerical presentation, and lacks the conditional format setting options similar to Excel; when a large amount of data needs to be displayed in PPT and specific data needs to be highlighted, the user usually cannot realize the effect of conditional format through the built-in function, which leads to the user having to manually adjust the data format, affecting the effect and efficiency of data display and lacking flexibility. SUMMARY

[0004] The present application relates to the technical field of computer, and particularly relates to a method for realizing PPT table conditional format function.

[0005] To achieve the above object, the present application adopts the following technical scheme:

[0006] A method for realizing PPT table conditional format function, comprising the following steps:

[0007] S1: receiving a PPT file input by a user to create a PPT object;

[0008] comprising the following sub-steps:

[0009] S11: receiving a PPT file input by a user;

[0010] The PPT file includes file complete path, file input stream object, file object or file byte array, etc.

[0011] S12: verifying the PPT file and type;

[0012] The received PPT file is verified, comprising the following sub-steps:

[0013] S121: verifying whether the PPT file is empty;

[0014] If the received PPT file is empty, an error message is returned and the verification ends; if the received PPT file is not empty, step S122 is entered;

[0015] S122: verifying the type of the PPT file;

[0016] The file magic number of the PPT file is verified; if the file magic number of the PPT file does not conform to the standard format of the PPT file, the verification fails and an error message is returned; if it conforms, the verification passes and step S13 is entered;

[0017] S13: creating the PPT file into a file stream object;

[0018] The received PPT file is converted into a file stream object, the file stream object is created into a buffer stream object, the buffer stream object is transmitted into a PPT parser, and a PPT object is generated.

[0019] S2: traversing the element objects in the PPT object, judging and storing the table objects into a table collection;

[0020] The following sub-steps are included:

[0021] S21: cyclically traversing the Slide objects in the PPT object;

[0022] All Slide objects contained by the PPT object are obtained by calling the ppt.getSlides method, and each Slide object is cyclically traversed;

[0023] S22: traversing each Shape object in the current Slide object, judging whether the current Shape object is a Table object, and storing the Table object into a tableList collection;

[0024] Each Slide object contains multiple Shape objects, such as text boxes, pictures, tables, etc.; all Shape objects in the Slide object are obtained by calling the slide.getShapes method;

[0025] Each Shape object is traversed and judged whether the current Shape object is a Table object; if yes, the Shape object is converted into a Table object and added to a List collection, which is recorded as a tableList collection; if not, the next Shape object is traversed; until the traversal is completed;

[0026] The elements of the tableList collection are Table objects.

[0027] S3: judging and traversing table objects in the table set, reading the conditional format script content and parsing and storing into the script set;

[0028] comprising the following sub-steps:

[0029] S31: judging whether the number of elements in the tableList set is 0;

[0030] If the number of elements in the tableList set is 0, the rendering is ended; if not, step S32 is entered;

[0031] S32: obtaining the XML object of the current Table table object;

[0032] calling the getXmlObject method of the Table table object to obtain the XML object contained therein;

[0033] S33: extracting the conditional format script content from the XML object;

[0034] finding the description attribute in the XML object, reading the value of the description attribute, which is the conditional format script content, if the conditional format script content is empty, skipping the Table table object and continuing to traverse the next Table table object, if the Table table object is not empty, the next step is executed;

[0035] The position of the description attribute is: opening the PPT file by office software, selecting the table, right-clicking the table with the mouse, selecting the shape format setting, and the description in the selectable text column of the pop-up box, the content in the description is the conditional format script string.

[0036] The PPT table row and column position definition specification is consistent with the Excel table, the first column of the table is A column, the second column is B column, and so on, the first row of the table is 1, the second row is 2, and so on. The position of the cell in the third row and the third column is C3.

[0037] The format of the conditional format script is: start cell position: end cell position = condition function (condition parameter): style function (style parameter). For example: D2:D7 = TOP(3):TEXT(RED).

[0038] The conditional format script content can have 0 or more conditional format scripts, and each conditional format script must be separated by a line break.

[0039] By defining the conditional format script syntax, the application range of the conditional format script is defined according to the table row and column position definition specification, the conditional function is used to filter the cells that need to be set with conditional format, and the style function is used to set these cells to the required style;

[0040] S34: parse the conditional formatting script content and store it in the Scripts collection;

[0041] Create the conditional formatting script content as a text buffer stream;

[0042] Traverse each line of text in the text buffer stream. If the line of text is not empty, use a regular expression to determine if the line of text matches. If it does not match, end rendering and return an error message. If it does match, obtain the start cell position, end cell position, condition function, condition parameters, style function, style parameters, and other script information through the regular expression. Wrap the script information into a script object and store it in the List collection, denoted as the Scripts collection. If it is empty, skip the line;

[0043] The properties of the script object include: start cell position, end cell position, condition function name, condition parameters, style function name, and style parameters.

[0044] S4: Traverse the script objects in the script collection and filter out the table cell objects that meet the range according to the start and end positions of the current script object in the current table object;

[0045] Including the following sub-steps:

[0046] S41: According to the table row and column position definition specification, store each TableCell table cell object in the current Table table object and the row and column position corresponding to the TableCell table cell object in a Map type data collection named tableMap;

[0047] The keys of the tableMap collection are row and column positions, and the values are TableCell table cell objects;

[0048] S42: Traverse each key-value pair in the tableMap collection. If the key of the current key-value pair is located between the start cell position and the end cell position in the script object, store it in the List collection named preparedTableCells;

[0049] The elements in the preparedTableCells collection are tableCell table cell objects.

[0050] S5: Execute the condition function and filter out the table cell objects that need to be styled;

[0051] Including the following sub-steps:

[0052] S51: Query the corresponding ConditionFunction from the global configuration according to the ConditionFunction name of the script object;

[0053] S52: Determine whether the ConditionFunction is empty, and throw an exception if it is empty;

[0054] If the ConditionFunction is empty, throw an exception and end the rendering process; otherwise, proceed to the next step.

[0055] S53: Execute the ConditionFunction to complete the filtering of TableCell objects.

[0056] The ConditionFunction accepts a List collection named preparedTableCells and a condition parameter, executes the execute method, and returns a List collection, denoted as styleCells.

[0057] The elements in the styleCells collection are TableCell objects.

[0058] The execute method receives two parameters, namely the preparedTableCells parameter and the condition parameter.

[0059] Specifically, the preparedTableCells parameter is the collection of preprocessed TableCell objects obtained in step S42, and the condition parameter is the condition parameter in the script object, which defines the filtering rules for the TableCell objects.

[0060] The execute method selects TableCell objects that meet the condition parameter based on the data in the collection and returns them.

[0061] S6: Execute the StyleFunction to complete the conditional style rendering of the TableCell objects.

[0062] It includes the following sub-steps:

[0063] S61: Query the corresponding StyleFunction from the global configuration according to the StyleFunction name of the script object.

[0064] S62: Determine whether the StyleFunction is empty, and throw an exception if it is empty.

[0065] If the StyleFunction is empty, throw an exception and end the rendering; otherwise, proceed to the next step.

[0066] S63: Execute the StyleFunction to complete the conditional style rendering.

[0067] The style function accepts a List collection named styleCells and a style parameter, executes the execute method, sets the specified table cells to the specified style according to the definition of the style parameter, and completes the conditional style rendering of the cells.

[0068] Compared with the prior art, the method has the following beneficial effects:

[0069] The method reuses the PPT native field to carry the script, and gives the template engine the ability of custom conditional format rendering in a lightweight and low-invasive manner, which not only retains the universality of the template, but also enables the template to flexibly adapt to various data scenarios through scripting design, especially suitable for template engine scenarios that need to generate personalized PPT (such as reports, dashboards, etc.), greatly improving the extensibility and practicality of the template. Specifically as follows:

[0070] (1) The method ingeniously uses the PPT native "optional text-description" field as a script carrier, without the need for additional development of complex UI interaction interface, realizing innovative reuse of existing software functions, reducing user learning cost, and realizing function reuse and extension.

[0071] (2) The method reads the PPT file and parses the custom script in the description field through the program, separates the table data processing and format rendering logic from the PPT client, avoids strong dependence on Office plug-ins, and improves the flexibility of cross-environment deployment.

[0072] (3) The method breaks through the limitations of the built-in conditional format function of PPT through a dynamic rendering mechanism, supports users to write custom scripts to implement complex business rules (such as multi-dimensional data comparison, threshold dynamic calculation, etc.), and enables the table visualization effect to be dynamically updated according to real-time data or custom logic.

[0073] (4) The method adopts a low-invasive design, does not modify the core structure of the PPT file, and only drives rendering by parsing metadata fields, ensuring the compatibility and security of the original document, and reserving extension space for subsequent function iteration (such as supporting more script syntax and extending rendering styles).

[0074] (5) The method uses custom scripts as conditional format rules carriers through scripting extension capability, allowing users to quickly adapt to different business scenarios by modifying script content without recompiling the program, greatly improving function iteration efficiency and individual configuration flexibility. BRIEF DESCRIPTION OF DRAWINGS

[0075] Figure 1 The method is a step flowchart for realizing the PPT table conditional format function. DETAILED DESCRIPTION

[0076] For the purpose, structure, features, and functions of the present application, the following detailed description is provided in conjunction with the embodiments.

[0077] As shown in the figure, a method for implementing the PPT table conditional formatting function includes the following steps: Figure 1

[0078] S1: receiving the PPT file input by the user, creating a PPT object;

[0079] Including the following sub-steps:

[0080] S11: receiving the PPT file input by the user;

[0081] The PPT file contains file complete path, file input stream object, file object or file byte array, etc.

[0082] S12: checking the PPT file and type;

[0083] The received PPT file is checked, including the following sub-steps:

[0084] S121: checking whether the PPT file is empty;

[0085] If the received PPT file is empty, return an error message and end the check; if the received PPT file is not empty, go to S122;

[0086] S122: checking the type of the PPT file;

[0087] Check if the file magic number of the PPT file is correct, that is, if the file magic number of the PPT file does not conform to the standard format of the PPT file, the check fails and an error message is returned; if it is correct, the check is passed and step S13 is entered;

[0088] S13: creating a PPT file into a file stream object;

[0089] The received PPT file is converted into a file stream object, and the file stream object is input into the PPT parser to generate a PPT object.

[0090] Through file checking, it is ensured that the PPT file conforms to the standard format and the integrity of the file is checked to prevent rendering failure due to incorrect file format or file damage, ensure that there is no error in the conversion and parsing process of the file, and improve the stability and reliability of the method.

[0091] S2: traversing the element object in the PPT object, judging and storing the table object into the table collection;

[0092] Including the following sub-steps: ​

[0093] S21: traversing Slide slide object in PPT object;

[0094] obtaining all Slide slide objects contained in the PPT object by calling the ppt.getSlides method, and traversing each Slide slide object;

[0095] S22: traversing each Shape shape object in the current Slide slide object, judging whether the current Shape shape object is a Table table object, and storing the Table table object in the tableList collection;

[0096] Each Slide slide object contains multiple Shape shape objects, such as text boxes, pictures, tables, etc. The slide.getShapes method is called to obtain all Shape shape objects in the Slide slide object;

[0097] traversing each Shape shape object and judging whether the current Shape shape object is a Table table object. If yes, the Shape shape object is converted into a Table table object and added to the List collection, denoted as the tableList collection. If not, the next Shape shape object is traversed; until the traversal is completed;

[0098] The elements of the tableList collection are Table table objects.

[0099] By traversing all Shape objects in the PPT and judging whether they are table objects, the table objects are extracted into a collection for processing, thereby avoiding omission and repeated processing.

[0100] S3: judging and traversing table objects in the table collection, reading conditional format script content and parsing and storing in the script collection;

[0101] including the following sub-steps:

[0102] S31: judging whether the number of elements in the tableList collection is 0;

[0103] If the number of elements in the tableList collection is 0, the rendering is ended. If not, step S32 is entered;

[0104] S32: traversing each element Table table object in the tableList collection, obtaining the XML object of the current Table table object;

[0105] traversing each element Table table object in the tableList collection;

[0106] Call the getXmlObject method of the current Table object to obtain the XML object contained therein;

[0107] S33: Extract the conditional formatting script content from the XML object;

[0108] Find the description attribute in the XML object, read the value of the description attribute, which is the conditional formatting script content. If the conditional formatting script content is empty, skip this Table object and continue to traverse the next Table object. If the Table object is not empty, perform the next step.

[0109] The location of the description attribute is: open the PPT file by office software, select the table, right-click the table with the mouse, select Set Shape Format, click the description in the selectable text column of the pop-up menu box, and the content in the description is the conditional formatting script content.

[0110] The PPT table row and column position definition specification is consistent with the Excel table, the first column of the table is column A, the second column is column B, and so on. The first row of the table is row 1, the second row is row 2, and so on. The position of the cell in the third row and the third column is C3.

[0111] The syntax of the conditional formatting script is: start cell position: end cell position = condition function (condition parameter): style function (style parameter). For example: D2:D7 = TOP(3):TEXT(RED), which means that the text of the cell with the top three values in columns D2 to D7 is set to red.

[0112] The conditional formatting script content can have 0 or more conditional formatting scripts, and each conditional formatting script must be separated by a line break.

[0113] By defining the conditional formatting script syntax, the application range of the conditional formatting script is defined according to the table row and column position definition specification. The condition function is used to filter the cells that need to be set with conditional formatting, and the style function is used to set these cells to the required style.

[0114] S34: Parse the conditional formatting script content into a Scripts script object List collection.

[0115] Create a text buffer stream for the conditional formatting script content;

[0116] Traverse each line of text in the text buffer stream, if the line of text is not empty, use regular expression to determine whether the line of text matches, if it does not match, end rendering and return error information, if it matches, obtain the start cell position, end cell position, condition function, condition parameter, style function, style parameter and other script information through regular expression, wrap the script information into a script object, and store the script object in the List collection, denoted as Scripts collection; if it is empty, skip this line;

[0117] The attributes of the script object include: start cell position, end cell position, condition function name, condition parameter, style function name, and style parameter.

[0118] By encapsulating the conditional formatting script content into individual script objects and extracting the attributes therein through regular expression, the user can customize the application range and style of the conditional formatting according to actual needs, thereby increasing the flexibility and expandability of the system.

[0119] S4: Traverse the script objects in the script collection, and filter out the table cell objects that meet the range from the current table object according to the start and end positions of the cells of the current script object;

[0120] Including the following sub-steps:

[0121] S41: According to the table row and column position definition specification, store each TableCell table cell object in the current Table table object and the row and column position corresponding to the TableCell table cell object in a Map type data collection named tableMap;

[0122] The keys of the tableMap collection are row and column positions, and the values are TableCell table cell objects;

[0123] S42: Traverse each key-value pair in the tableMap collection, and if the key of the current key-value pair is located between the start and end cell positions in the script object, store it in a List collection named preparedTableCells;

[0124] The elements in the preparedTableCells collection are TableCell table cell objects.

[0125] S5: Execute the condition function and filter out the table cell objects that need to be styled;

[0126] Including the following sub-steps:

[0127] S51: Query the corresponding ConditionFunction from the global configuration according to the ConditionFunction name of the script object;

[0128] S52: Determine whether the ConditionFunction is empty, and if so, throw an exception;

[0129] If the ConditionFunction is empty, throw an exception and end the rendering process; otherwise, proceed to the next step;

[0130] S53: Execute the ConditionFunction to complete the filtering of TableCell objects;

[0131] The execute method of the ConditionFunction returns a List collection, denoted as styleCells.

[0132] The elements in the styleCells collection are TableCell objects.

[0133] The execute method receives two parameters, preparedTableCells and condition.

[0134] Specifically, preparedTableCells is the collection of preprocessed TableCell objects obtained in step S42, and condition is the condition parameter in the script object, which defines the filtering rules for the table cells.

[0135] The execute method selects TableCell objects that meet the condition parameter based on the data in the collection and returns them.

[0136] By executing the methods in the ConditionFunction, the table cells that need to be styled can be dynamically filtered, supporting user-defined ConditionFunction and condition parameters, allowing the display of the table to be adjusted according to different needs. This enhances the processing capability of conditional formatting, allowing users to control the scope and effects of format application by writing custom scripts, providing flexible expansion capabilities.

[0137] S6: Execute the StyleFunction to complete the conditional style rendering of the table cells;

[0138] Including the following sub-steps:

[0139] S61: Query the corresponding StyleFunction from the global configuration according to the StyleFunction name of the script object;

[0140] S62: Determine whether the StyleFunction is empty, and if so, throw an exception;

[0141] If the StyleFunction is empty, throw an exception and end the rendering process; otherwise, proceed to the next step;

[0142] S63: The execute method of the style function completes conditional style rendering;

[0143] The execute method of the style function sets the specified table cells to the specified style according to the definition of the style parameter, and completes the conditional style rendering of the cells.

[0144] The execute method receives two parameters, namely the styleCells parameter and the condition parameter;

[0145] The styleCells parameter is the table cell object set obtained in step S53, which contains the table cells that need to be applied with style rendering;

[0146] The style parameter is the style parameter in the script object, which defines the style of the table cells that meet the conditions, including color, font, and other visual effects;

[0147] The style function can support different style setting requirements, and users can customize the style function and the style parameter according to different business requirements, thereby improving the flexibility of PPT display;

[0148] Through the flexible conditional format script, the table data display in the PPT can accurately highlight important information according to the conditions set by the user, thereby meeting the diversified display requirements.

[0149] The present application has been described by the above-mentioned related embodiments, however, the above-mentioned embodiments are only examples for implementing the present application. It must be pointed out that the disclosed embodiments do not limit the scope of the present application. On the contrary, modifications and improvements made without departing from the spirit and scope of the present application are all within the scope of the patent protection of the present application.

Claims

1. A method of implementing a PPT table conditional formatting function, characterized in that: The method comprises the following steps: S1: receiving a PPT file input by a user, and creating a PPT object; S2: traversing element objects in the PPT object, and storing table objects in a table set; traversing all Shape shape objects in the PPT object and judging whether the Shape shape objects are Table table objects, and storing the Table table objects in a tableList table set; S3: judging and traversing table objects in the table set, reading conditional format script content, and storing the conditional format script content in a script set; judging whether the number of Table table objects is 0, if not, traversing each Table table object in the tableList set, obtaining an XML object, extracting conditional format script content from the XML object, creating a text buffer stream, reading and parsing each row of data in the text buffer stream, and storing the each row of data in the script set; S4: traversing script objects in the script set, screening out table cell objects in a current table object according to a start position and an end position of a cell of the current script object; according to a table row and column position definition specification, storing each TableCell table cell object in the current Table table object and a corresponding row and column position in a tableMap Map type data set; traversing each key-value pair in the tableMap set, and storing values of key-value pairs meeting a condition in a List set named preparedTableCells; S5: executing a conditional function and screening out table cell objects needing to be set with a style; querying a corresponding ConditionFunction conditional function from a global configuration according to a conditional function name of the script object, and executing an execute method to complete TableCell table cell object screening; S6: executing a style function to complete conditional style rendering of a cell; querying a corresponding StyleFunction style function from the global configuration according to a style function name of the script object, and executing an execute method to complete conditional style rendering.

2. The method for implementing a PPT table conditional format function according to claim 1, wherein: step S1 comprises the following sub-steps: S11: receiving a PPT file input by a user; S12: verifying the PPT file and type; if the received PPT file is not empty, verifying the type of the PPT file; verifying whether the file magic number of the PPT file is correct, that is, if the file magic number of the PPT file meets the standard format of the PPT file, the verification is passed, and step S13 is entered; S13: creating the PPT file into a file stream object; converting the received PPT file into a file stream object, and transmitting the file stream object into a PPT parser to generate a PPT object.

3. The method for implementing a PPT table conditional format function according to claim 1, wherein: step S2 comprises the following sub-steps: S21: traversing Slide slide objects in the PPT object; ​ Obtaining all Slide objects contained in the PPT object, and traversing each Slide object; S22: Traversing each Shape object in the current Slide object, judging whether the current Shape object is a Table object, and storing the Table object in the tableList collection.

4. The method of claim 1, wherein: Step S3 includes the following sub-steps: S31: judging whether the number of elements in the tableList collection is 0; If the number of elements in the tableList collection is 0, go to step S32; S32: traversing each Table object in the tableList collection, and obtaining the XML object of the current Table object; Calling the getXmlObject method of the Table object to obtain the XML object contained therein; S33: extracting the conditional formatting script content from the XML object; Finding the description attribute in the XML object, and reading the value of the description attribute, which is the conditional formatting script content; S34: parsing the conditional formatting script content and storing it in the Scripts collection; Creating the conditional formatting script content as a text buffer stream; Traversing each line of text in the text buffer stream, obtaining script information through a regular expression, wrapping the script information into a script object, and storing the script object in the List collection, denoted as the Scripts collection.

5. The method of claim 1, wherein: Step S4 includes the following sub-steps: S41: according to the table row and column position definition specification, storing each TableCell object in the current Table object and the row and column position corresponding to the TableCell object in a Map type data collection named tableMap; S42: traversing each key-value pair in the tableMap collection, and if the key of the current key-value pair is between the start cell position and the end cell position in the script object, storing it in a List collection named preparedTableCells.

6. The method of claim 1, wherein: Step S5 includes the following sub-steps: S51: querying the corresponding ConditionFunction from the global configuration according to the condition function name of the script object; S52: judging whether the condition function is empty, and if so, throwing an exception; S53: executing the execute method of the ConditionFunction to complete the TableCell object filtering; The execute method receives two parameters, namely the preparedTableCells parameter and the condition parameter; The execute method selects the table cell object that meets the condition parameter according to the data in the collection and returns it.

7. The method of Claim 1, wherein: Step S6 includes the following sub-steps: S61: Query the corresponding StyleFunction style function from the global configuration according to the style function name of the script object; S62: Determine whether the style function is empty, and if so, throw an exception; S63: Execute the execute method of the style function to complete the conditional style rendering; The execute method receives two parameters, styleCells parameter and condition parameter. ​

Citation Information

Patent Citations

  • Dynamic rendering method and device for Swing table

    CN115344242A

  • Method for realizing dynamic form by adding dynamic form control based on VUE (Virtual User Equipment)

    CN117667085A