Construction organization design word document intelligent generation method and system
By adopting the deep integration method of Python-docx and PyQt5 in the field of construction engineering, establishing preset templates and using placeholder replacement technology, the poor template reusability and confusing format problems in construction document editing are solved, and efficient construction organization design and intelligent generation of special construction plans are achieved.
Patent Information
- Application Number
- CN202510905051.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-02
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-07-02
AI Technical Summary
There are problems such as poor template reusability, confusing format, low coordination efficiency, low compilation efficiency and version conflict in the editing of construction documents in the field of construction engineering. In particular, different projects require repeated editing of the same chapter content, and there is no standardized compilation requirement when many people participate, resulting in inefficiency.
Using deep integration technology based on Python-docx and PyQt5, we create preset templates and use placeholders to replace project feature information content, combine web views and HTML interfaces to achieve precise positioning and editing, process Excel data through Python's pandas library, automatically replace and insert project feature information, and ensure document format consistency and collaborative efficiency.
It has realized the intelligent and standardized generation of construction organization design and special construction plans, improved the compilation efficiency by more than 5 times, ensured the unified document format, reduced the difficulty of data preparation and version conflicts, and improved the efficiency of collaborative editing by multiple people.
Smart Images

Figure CN120409435A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the cross - technical field of construction project informatization and intelligent document processing, and particularly relates to an intelligent generation method and system for construction organization design word documents based on deep integration of Python - docx and PyQt5, which is particularly suitable for the intelligent generation of standardized documents such as construction organization design and special construction plans in the field of construction engineering. Background Technique
[0002] The objects targeted by construction organization design in the field of housing construction projects can be simply classified according to usage, structural type, etc. as: residential projects, public building concrete projects, public building steel structure projects, concrete structure factory building projects, steel structure factory building projects, etc. Special construction plans can be simply classified according to sub - part and item categories and construction objects as: formwork engineering, deep foundation pit engineering, steel structure engineering, scaffolding engineering, decoration engineering, hoisting and installation and disassembly engineering of hoisting machinery, etc.
[0003] The compilation of construction organization design should be based on relevant technical standards and administrative regulatory documents, and its chapter content generally should include: compilation basis, project overview, construction deployment, construction progress plan and guarantee measures, construction preparation and main resource allocation plan, main construction plan and technical measures, quality management control measures, safety production control measures, occupational health control measures, environmental protection control measures, civilized construction control measures, construction site layout, etc.
[0004] The compilation of special construction plans should also be based on relevant technical standards and administrative regulatory documents, and its chapter content should include: project overview, compilation basis, construction plan, construction technology, construction guarantee measures, construction management and allocation and division of labor of operation personnel, acceptance requirements, emergency disposal measures, calculation books and relevant construction drawings, etc.
[0005] From the aspects of compliance with technical regulations and contract performance requirements, the content of various construction organization designs and special construction plans can be divided into fixed - content, project - characteristic information content, and project - specific content. Among them, the fixed - content includes relevant content such as chapter structure, compilation basis, main construction technology, and requirements of specification clauses; the project - characteristic information content reflecting the specific characteristics of the project includes project overview, construction progress plan, main resource allocation plan, construction site layout, and allocation and division of labor of construction management and operation personnel, calculation books and relevant construction drawings in special plans, etc.; the project - specific content for special situations and requirements of the project, including quality excellence planning meeting contract agreements, construction period guarantee measures, safety guarantee measures due to special surrounding environments of the project, special safety requirements of special construction plans for project characteristics, etc., which reflects the content of project - differentiated requirements.
[0006] The following technical pain points exist in the editing of construction documents in the current construction engineering field: (1) Poor template reusability: For different projects, the same chapter content needs to be repeatedly edited, and the existing technology requires repeated settings for the specific format requirements of enterprises; (2) The standardization degree of paragraph text, pictures, and table styles is low, and the generated document formats are not unified; (3) Low collaboration efficiency: When multiple personnel are involved, there are no standardized compilation requirements, and the habitual differences lead to a lot of rework and low efficiency; (4) Low compilation efficiency: The single-person compilation work takes a long time and cannot guide the construction operation in a timely manner; (5) Version conflicts: The content of each version is chaotic and prone to errors. Summary of the Invention
[0007] As described in the previous background, when compiling construction organization designs or special construction plans for different projects of the same category in construction engineering, there are many identical paragraph contents, but the technical pain point of having to repeatedly edit them exists, and the content reflecting the project characteristic information has a certain regularity. The present invention combines the two, forms a standardized template based on the fixed content, replaces the content reflecting the regularity of the project characteristic information with corresponding placeholders to become a preset template, replaces the project characteristic information content by certain technical means, and then adds project characteristic content to the file after replacing the project characteristic information, so as to realize a targeted construction organization design or special construction plan for guiding engineering construction and reflect the differentiated needs of the project. The present invention precisely provides such a method, which solves the technical problems such as poor template reusability, format chaos, low collaboration efficiency, low compilation efficiency, and version conflicts in the traditional construction plan compilation on the basis of enterprise-level standardized management of construction organization designs. Under the condition that multiple people collaborate to complete the structured project characteristic information content and project characteristic content according to the specified format, the compilation work of the construction organization design or special construction plan can be quickly completed, and the efficiency is increased by more than 5 times.
[0008] To achieve the above object, the following specific technical solutions are adopted in the present invention.
[0009] In the first aspect, a method for intelligently generating a construction organization design word document is provided, which includes the following steps: S1. Establish a preset template: Establish preset templates for various construction organization designs and special construction plans. The content structure of the preset template includes fixed content and project characteristic information content represented by placeholders; establishing a preset template is used for subsequent replacement of project characteristic information content and insertion of project characteristic content.
[0010] S2. Preset Template Loading and Display: Select a preset template that matches the pre-generated solution, load the preset template, and display the fixed content and placeholder information of the preset template in a web view. The document types corresponding to the pre-generated solutions include two categories: construction organization design and special construction plans, which are further divided into multiple template types according to engineering categories or structural types. For example, the residential project construction organization template, public building concrete project construction organization template, public building steel structure project construction organization template, etc. for construction organization design; the template project special plan template, deep foundation pit project special plan template, steel structure project special plan template, decoration project special plan template, etc. for special construction plans. Here, select the corresponding document type and the matching preset template. This step prepares for reading the placeholder information of the preset template and can also fully check whether the loaded template matches the pre-generated solution.
[0011] S3. Data Loading: Read the data of the Excel file through the pandas library in Python. First, determine the Excel file type based on the keywords in the Excel file name, and then call the corresponding loading method. The data of each Excel file is classified and stored in different dictionaries after non-empty verification: the paragraph text and table cell text data are stored as dictionary data in the form of placeholders and text content, and the paragraph pictures and table cell pictures data are stored as dictionary data in the form of placeholders and their corresponding picture paths, sizes, and style information. S4. Placeholder Replacement: Traverse the paragraphs and tables in the preset template, search for and automatically replace them according to the dictionary data of the corresponding placeholders. This step performs a one-time rapid replacement operation of the placeholder content of the project feature information based on the preset template.
[0012] S5. Generate a Temporary Intermediate Solution File: After performing the placeholder replacement, save the replaced document as a temporary intermediate solution file with a timestamp, save it as a temporary file in the preset temporary folder, and record the temporary file path. This step ensures that the timestamped document after placeholder replacement can be temporarily saved and accurately located in the preset temporary folder for subsequent editing of inserting project-specific content.
[0013] S6. Web-based editing communication settings: The system constructs a visual environment by loading a preset HTML template, sets the insertion point through the div element of HTML and CSS styles. When the insertion point is clicked, a JavaScript function triggers a custom editor: / / URL Scheme, and the request is processed by the EditorUrlSchemeHandler class to achieve front-end and back-end communication; accurately locates the target paragraph by clicking the insertion point and inserts elements such as text, pictures, and Excel tables; this step is the premise for inserting project feature information editing on the basis of webization for the temporary intermediate solution file, bypassing the conventional Web native communication restrictions and achieving an accurate mapping of "click and locate".
[0014] S7. Editing the temporary intermediate solution file: Use WordEditor to insert project feature content into the temporary intermediate solution file to form a solution file to be generated, specifically including: loading and parsing the temporary intermediate solution file, visual insertion point positioning based on QWebEngineView, identifying the content type and performing corresponding text, Excel table, and picture insertion operations, maintaining style consistency, and converting to HTML through Pandoc for preview, and finally saving versioned as a temporary file; this step ensures that the document after placeholder replacement can be edited and customized for project feature information content.
[0015] S8. Editing the cover information of the solution file to be generated: By identifying the placeholders in the document, replace them with the corresponding cover information, including automatic filling of the project name, unit project name, and compilation date, and insertion of the cover picture; this step ensures that the cover information of the document can be automatically filled, improving the professionalism, integrity, and enterprise standardization of the document.
[0016] S9. Generating and saving the final document: Preview the solution file to be generated with the loaded cover information, generate the final document based on the temporary file through generate_from_temp, output and save. Load and process the document content, and save it with a file name containing the project name, document type, and timestamp. This step ensures that the final document can be generated and output for users to use.
[0017] Furthermore, the preset template in S1 contains four types of placeholders: paragraph text placeholder, paragraph image placeholder, table cell text placeholder, and table cell image placeholder; Loading the preset template in S2 and displaying it in a web view specifically means: After selecting the preset template, load the preset template from the specified path, use the Pandoc tool to convert the preset template into HTML format, display it through the QWebEngineView component, retain the fixed and unchanging content and placeholder markers in the preset template, and at the same time apply CSS styles to ensure the correct rendering of tables and images, and dynamically enhance the display effect through JavaScript after loading; For the data loading in S3, the paragraph text placeholder and the table cell text placeholder build a text_replacements dictionary by reading the "placeholder" and "text" columns, while the paragraph image placeholder and the table cell image placeholder read the "placeholder", "path", "width_cm", and "height_cm" columns to build an image_replacements dictionary. During the loading process, record the successfully loaded files and the error information of the loading failures to ensure the integrity and accuracy of the data, and finally form a complete dictionary data containing the placeholder names and the corresponding content; The placeholder replacement in S4 traverses the paragraphs and table cells in the preset template and uses replace_paragraph_text_optimized() to process the replacement of the paragraph text placeholder: First, save the style of the first run of the paragraph, check the placeholder and build new text, process the special date format, clear the original run and insert the new text with the style of the first run. Use replace_paragraph_image_optimized() to traverse the image configuration, parse the path and obtain the size with PIL, create a new paragraph and insert the image centered, calculate the height according to the width, clear the original placeholder, and use replace_table_text() to process the table text according to the replacement logic of the paragraph text placeholder; Use replace_table_image() to first clear the placeholder, parse the path and calculate the size, and insert the cell according to the configured width and alignment. All replacements are based on the PlaceholderDataLoader dictionary data, automatically handling the conversion of relative paths and style inheritance.
[0018] The structured Excel data file in step S3 is pre-stored in a preset folder. The first row of the paragraph text.xlsx or table text.xlsx file is four list headers of placeholder, text, font, and size. The first column of the second row is the paragraph or table text placeholder, such as {{paragraph:text-1}} or {{table:text-1}}. The second column of the second row is the text content to be replaced. The third and fourth columns of the second row are the corresponding styles of the font to be replaced, and so on for other rows. The first row of the paragraph picture.xlsx or table picture.xlsx file is five list headers of placeholder, path, Wideth-cm (picture width, unit: centimeter), Height-cm (picture height, unit: centimeter), and Alignment (alignment method). The first column of the second row is the paragraph or table picture placeholder, such as {{paragraph:image-1}} or {{table:image-1}}. The second column of the second row is the specific location and format of the picture in the system, such as. / images / 2.PNG. The third, fourth, and fifth columns of the second row are the picture size and symmetry method, such as 15.75x13.65, center (centered), and so on for other rows.
[0019] Further, the placeholder replacement in S4 is specifically as follows: The placeholder replacement is performed by traversing the paragraphs and table cells in the preset template, and making precise matches based on the dictionary data loaded by the PlaceholderDataLoader. When the replacement fails, the placeholder is retained and an error prompt is added to ensure the reliability of document generation. The specific replacement of the four types of placeholders is as follows: The paragraph text placeholder is processed through `_replace_paragraph_text_optimized()`: first, save the style of the first run of the paragraph, check the placeholder and construct new text, automatically convert the special date format to the Chinese format, clear all runs of the original paragraph, and then inject the new text with the style of the first run and inherit the original style; The paragraph picture placeholder is processed through `_replace_paragraph_image_optimized()`: traverse the picture replacement configuration, parse the picture path, obtain the size with the PIL library and calculate the height, create a new paragraph specifically for placing the picture and insert it in the centered alignment method, set the picture width and calculate the height proportionally, clear the original placeholder, and if the processing fails, retain the placeholder and add an error prompt; The placeholder for the table cell image is processed by `_replace_table_image()`: First, clear the cell placeholder, parse the image path, obtain the actual size, calculate the height according to the configured width, insert it into the table cell according to the specified alignment method, and add error prompt text if the image fails to load; The placeholder for the table cell text is processed by `_replace_table_text()`: Traverse the table cells, retain the original style of the first run, clear the placeholder content, construct new text and process special date formats, clear the original run, and inject the new text with the style of the first run to ensure consistent styles; Furthermore, the S5 generates a temporary intermediate solution file, specifically: After the placeholder replacement is completed, call datetime.now().strftime("%Y%m%d_%H%M%S") to generate a timestamp, use strftime("%Y%m%d_%H%M%S") to convert the timestamp to the format of "year-month-day_hour:minute:second", then create a temporary file named "intermediate solution_timestamp.docx" in the temp subdirectory of the project to ensure that each temporary file has a unique identifier. Save the temporary file and record the temporary file path. The temporary file path is stored in the instance variable temp_file. Persistently save the document object with the placeholder replacement completed to this path through the doc.save() method of the docx library. During the process, strictly maintain the integrity of the original document format and the replaced content. Synchronously store the absolute path of the generated temporary file in the instance variable temp_file. This variable serves as a key status identifier to provide a unified file access entry for subsequent operations such as document preview, secondary editing, and final version generation. The automatic cleaning mechanism of the temporary file is triggered after the final document is generated to effectively manage the storage space.
[0020] Furthermore, the web-based editing communication settings in S6 are specifically as follows: After loading the temporary intermediate solution file through the python-docx library, use enumerate(paragraphs) and enumerate(tables) to generate consecutive numbered ID identifiers for the document paragraphs and tables for front-end interaction positioning; In the HTML conversion stage, preset insertion point divs before the normal paragraphs after the first-level heading paragraph, after the table ends, and at the beginning of the document. Automatically insert CSS-style <div class=""insert-point”">Visualization marker; build an HTML visual editing interface based on the QWebEngineView component, use QWebEngineUrlScheme.registerScheme to register a custom URL protocol, establish a front-end and back-end communication channel through the custom editor: / / URL Scheme. When clicking on the insertion point in the HTML interface, the front-end JavaScript triggers an editor: / / / select request through the selectElement() function and carries the target paragraph ID parameter. The back-end captures the request and parses the parameters through the EditorUrlSchemeHandler class implemented by inheriting QWebEngineUrlSchemeHandler, and updates the status of the currently selected paragraph by the handle_element_selected method of DocumentController. The status of the currently selected paragraph includes displaying the unique ID of the currently selected position in the status panel and visually highlighting the target paragraph. In this step, a visual editing interface is built through HTML, and an efficient communication mechanism is established using the custom "editor: / / URL Scheme", breaking through the interaction limitations between traditional Web and native applications. Through the virtual URL, the Web interface is bridged with the document object model to achieve precise Web-based editing of the temporary intermediate solution file. It not only maintains the visual advantages of the browser environment but also realizes the document operation accuracy at the native application level. When clicking on a specific insertion point in the interface, the system front-end captures the element ID through JavaScript and triggers an "editor: / / / select" request. The back-end parses the request parameters through "EditorUrlSchemeHandler", precisely maps the target paragraph position to the corresponding node in the document object model, and establishes a real-time editing channel of "click and locate". As the core prerequisite, this communication mechanism enables the insertion operations of text, images, and Excel tables in the HTML interface to accurately act on the underlying docx document structure: text insertion inherits the style attributes of the target paragraph, images automatically adapt to the cell size and maintain the wrapping layout, and Excel tables are converted into native Word tables through OpenXML while retaining formulas and formats. Finally, a closed-loop workflow of "what you see is what you get - what you click is what you change" is formed in the Web-based editing stage of the temporary file, providing a reliable technical foundation for the dynamic injection of project feature information.
[0021] Furthermore, the specific operation of inserting the project feature information content into the temporary intermediate solution file in S7 by WordEditor is as follows: Edit the project feature content of the temporary intermediate solution file through the WordEditor component. First, load and parse the temporary intermediate solution file that has completed placeholder replacement, and build a two-way mapping relationship between the document object model and the visual editing interface; implement a precise insertion point positioning system based on the visual interface of QWebEngineView. By rendering the document HTML preview and capturing click events, convert the interface coordinates into the physical position index of the document paragraph / table; the system automatically identifies the type of content to be inserted: text / image / table, and calls the corresponding insertion method - for text insertion, use the add_paragraph and add_run methods of python-docx to retain the original format style, for image insertion, implement dynamic size adjustment and wrap layout through the add_picture method, and for Excel table insertion, dynamically generate a Word table after parsing the data with openpyxl and retain the cell style; WordEditor renders the document content in real time through QWebEngineView.setHtml, and combines MutationObserver to listen for DOM changes to ensure that the editing operation is synchronized and updated with the underlying Word document object, and saves the edited document to the file to be generated. All insertion operations are forced to verify format consistency through the style manager to ensure that the newly added content is compatible with the original document style system; a new version with a timestamp ("to-be-generated solution_timestamp.docx") is automatically generated after each edit, which not only retains the editing history but also avoids overwriting the original intermediate file.
[0022] Furthermore, the generation of the temporary file is specifically as follows: Use tempfile.mkstemp() to generate a temporary file with a random suffix during the document editing process. The system will create a subdirectory named temp under the program directory to store the temporary files. When the user performs a save operation, generate a timestamp and use this timestamp to name the temporary file. The naming format of the temporary file is "intermediate solution_timestamp.docx" or "to-be-generated solution_timestamp.docx". The system ensures the existence of the temporary directory through os.makedirs, and saves the current document content to the temporary file through the save method of the Document object; then use shutil.move() atomic operation to replace the target file to avoid document corruption caused by direct writing; the naming of the temporary file integrates the timestamp and the process to ensure uniqueness. At the same time, register a cleanup hook through atexit to automatically delete the residual files when the program exits abnormally. The WordEditor class manages the temporary files through the TempFileManager module.
[0023] Further, the generation of the final document in S9 is specifically as follows: By loading the temporary file "to-be-generated-solution_timestamp.docx", the Document class is used to process the document content: The text content is added or modified paragraph by paragraph through the add_paragraph method, and the run.font attribute is synchronously set to configure the font style; The table content is inserted through the add_table method, including obtaining the number of data rows and columns first and then creating the table structure, and filling the cell data through a double loop; The picture content is inserted through the add_picture, including the verification of the picture path and the calculation of the proportional scaling of the size; In the document saving link, the save method is called to save the document to the specified path. In the generate_from_temp method, first, it is checked whether the temporary file exists, then the temporary document is loaded for processing, and finally, it is saved to the output directory, and the output path is generated through the get_output_path method. In the document saving link, the save method is called to implement the temporary file mechanism. First, write to the temporary file and then rename it to the target file through an atomic operation. The possible IOError and ValueError exceptions are captured through the try-except block to ensure a safe rollback in case of operation failure.
[0024] In a second aspect, a smart generation system for a construction organization design word document is provided, including: A preset template loading module, used to load various preset templates. The document types of the various preset templates are divided into two types: construction organization design and special construction plan. The content structure of the preset template includes fixed content and project feature information content represented by placeholders; A data loading module, used to read placeholder replacement data from an Excel file in a preset path, including paragraph text replacement data, paragraph picture replacement data, table text replacement data, and table picture replacement data; A project feature information replacement module, used to traverse the project feature information placeholders in the preset template and perform automatic replacement to generate a temporary intermediate solution file, including: A paragraph text replacement unit, used to perform text replacement operations on paragraph text placeholders; A paragraph picture replacement unit, used to perform picture replacement operations on paragraph picture placeholders; A table cell text replacement unit, used to perform table cell text replacement operations on table text placeholders; A table cell picture replacement unit, used to perform table cell picture replacement operations on table picture placeholders; The project feature content insertion module is used to insert project feature information content into the temporary intermediate solution file to form the solution file to be generated, including: loading and parsing the temporary intermediate solution file, web-based editing communication settings, visual insertion point positioning based on QWebEngineView, content type recognition and corresponding insertion, style consistency maintenance, and versioned saving; The document preview module is used to convert the paragraphs and tables of the preset template loaded into HTML format and load them into the preview window through the setHtml method, and apply CSS styles to enhance the visual effect to achieve visual preview; assign a unique ID to each paragraph and table, and use JavaScript to achieve real-time update and interaction to highlight and scroll and position the selected elements; The cover processing module is used to process the document cover information of the solution file to be generated, including automatic filling of the project name, unit project name, and compilation date, and insertion of the cover picture; The document generation module is used to output the final word document for the solution file to be generated with the cover information completed.
[0025] The present invention solves the problems of poor template reusability, format chaos, low collaboration efficiency, low compilation efficiency, version conflicts, etc. in the traditional construction plan compilation, realizes the intelligent and standardized generation of construction organization design documents, and the editing of Excel structured data can realize multi-person collaborative data editing operations, greatly reducing the data preparation difficulty of using JSON key-value structures to edit placeholder data, greatly reducing the data preparation difficulty of plan editors, improving team efficiency, and multi-person collaboration also improves the efficiency of data editing. The placeholder one-key replacement method provided by the present invention improves the plan editing work efficiency by more than 5 times, and ensures the standardized output and text quality of plan compilation. Description of the Drawings
[0026] Figure 1 It is the flowchart of document generation in the present invention; Figure 2 It is the structural diagram of table text data in the present invention; Figure 3 It is the structural diagram of paragraph picture data in the present invention; Figure 4 It is the flowchart of the document editor in the present invention; Figure 5 It is the program architecture diagram of the present invention. Detailed Embodiments
[0027] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in combination with some codes and system operation interfaces in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention.
[0028] Embodiment 1: As Figure 1 shown, taking the construction organization design of residential projects as an example, a method for intelligent generation of a construction organization design word document includes the following steps: S1. Establish a preset template: Establish preset templates for various construction organization designs and special construction plans. The content structure of the preset template includes fixed content and project feature information content represented by placeholder symbols; the preset template contains four types of placeholder symbols: paragraph text placeholder, paragraph picture placeholder, table text placeholder, and table picture placeholder.
[0029] S2. Load and display the preset template: Select the type of plan corresponding to the pre-generated plan and the adapted preset template; load the preset template and display the fixed content and placeholder information of the preset template in a web view; specifically, for example, when preparing the construction organization design of a residential project, the document type should be selected as the construction organization design, and the preset template should be selected as the construction organization design template for residential projects. After loading, the fixed content and placeholder information of the preset template can be displayed in a web view, and it can be clearly found whether the loaded template matches the pre-generated construction organization design of the residential project.
[0030] S3. Data Loading: Read the data from the Excel file through the pandas library in Python. First, judge the Excel file type according to the keywords in the Excel file name, and then call the corresponding loading method; After non-empty verification, the data of each Excel file is classified and stored in different dictionaries: the paragraph text and table cell text data are stored as dictionary data in the form of placeholders and text content, and the paragraph pictures and table cell picture data are stored as dictionary data in the form of placeholders and their corresponding picture paths, sizes and style information; The first row of the paragraph text.xlsx or table text.xlsx file in the placeholder Excel file sheet data is the four-column headers of placeholder, text, font, and size. The first column of the second row is the paragraph or table cell text placeholder name, such as {{paragraph:text-1}} or {{table:text-1}}, the second column of the second row is the text content to be replaced, and the third and fourth columns of the second row are the corresponding styles of the font to be replaced. The data of other rows is the same by analogy; The first row of the paragraph picture.xlsx or table cell picture.xlsx file is the five-column headers of placeholder, path, Wideth-cm (picture width, unit: centimeter), Height-cm (picture height, unit: centimeter), and Alignment (alignment method). The first column of the second row is the paragraph or table cell picture placeholder name, such as {{paragraph:image-1}} or {{table:image-1}}, the second column of the second row is the specific position and format of the picture path, such as. / images / 2.PNG, and the third, fourth, and fifth columns of the second row are the picture size and symmetry method, such as 15.75x13.65, center (centered). The data of other rows is the same by analogy.
[0031] S4. Placeholder replacement: Traverse the paragraphs and tables in the preset template, search and perform automatic replacement according to the dictionary data of the corresponding placeholders; this step performs a one-time quick replacement operation of the placeholder content of the project feature information based on the preset template. Placeholder replacement includes: performing paragraph text replacement operations on paragraph text placeholders, performing paragraph image replacement operations on paragraph image placeholders, performing table cell text replacement operations on table cell text placeholders, and performing table cell image replacement operations on table cell image placeholders; when specifically performing replacement, for paragraph text placeholders, perform paragraph text replacement operations: use _replace_paragraph_text_optimized(), first save the style baseline of the first run of the paragraph, construct new text through placeholder matching, automatically process the conversion of special date formats to Chinese formats, after clearing all runs of the original paragraph, inject the new text with the style of the first run and inherit the original style; for paragraph image placeholders, perform paragraph image replacement operations: traverse the image configuration through _replace_paragraph_image_optimized(), parse the path and use the PIL library to obtain the size and calculate the height according to the configured width, create a new paragraph specifically for placing the image, insert it in a centered alignment and set the size, clear the original placeholder, if the processing fails, retain the placeholder and add an error prompt; for table cell text placeholders, perform table cell text replacement operations: adopt _replace_table_text(), the logic is the same as that of paragraph text replacement, retain the original style of the first run when traversing table cells, process the placeholder text and special date formats, clear the original run and then inject the new text and inherit the style; for table cell image placeholders, perform table cell image replacement operations: first clear the cell placeholder through _replace_table_image(), parse the image path to obtain the actual size and calculate the height according to the configured width, insert it into the table cell in the specified alignment, if the image fails to load, add an error prompt text.
[0032] S5. Generate a temporary intermediate solution file: After performing placeholder replacement, save the replaced document as a time-stamped temporary intermediate solution file, which is saved as a temporary file in a preset temporary folder, and record the temporary file path at the same time; this step ensures that the time-stamped document after placeholder replacement can be temporarily saved and accurately located in the preset temporary folder for subsequent editing of inserting project-specific content. After the placeholder replacement operation is completed, first create a storage space automatically in the temp subdirectory under the project root directory (create a new one if it does not exist), and then construct a complete file path according to the naming rule of "intermediate solution_timestamp.docx". Dynamically construct a temporary document path containing a time stamp (formatted as "year-month-day_hour:minute:second") through the _generate_output_path() method, generate a time stamp accurate to seconds by calling datetime.now().strftime("%Y%m%d_%H%M%S"), and format it into a standard string format of "year-month-day_hour:minute:second" to ensure that each temporary file has a unique identifier; persistently save the document object after placeholder replacement to this path through the doc.save() method of the docx library, strictly maintaining the integrity of the original document format and the replaced content during the process. Synchronously store the absolute path of the generated temporary file in the instance variable temp_file, which serves as a key status identifier to provide a unified file access entry for subsequent operations such as document preview, secondary editing, and final version generation.
[0033] S6. Web-based editing communication settings: In the Web-based editing interface, the insertion point is set through HTML div elements and CSS styles. When the insertion point is clicked, a JavaScript function triggers a custom editor: / / URL Scheme, which is processed by the EditorUrlSchemeHandler class to achieve front-end and back-end communication; the target paragraph is accurately located and elements such as text, pictures, and Excel tables are inserted by clicking on the insertion point; this step is the prerequisite for inserting project feature information editing on the basis of the Web for the temporary intermediate scheme file, bypassing the conventional Web-native communication limitations and achieving an accurate mapping of "click and locate". After loading the temporary intermediate scheme file through the python-docx library, consecutive numbered ID identifiers such as para_0 and table_1 are generated for the document paragraphs and tables using enumerate(paragraphs) and enumerate(tables) for front-end interaction positioning; in the HTML conversion stage, insertion point divs are preset before the normal paragraph after the first-level heading paragraph, after the table ends, and at the beginning of the document. The visual feedback is achieved through basic CSS:.insert-point:hover changes the background color, and the.active-insert class achieves a pulsating border effect through keyframe animation; the communication layer adopts the standard implementation scheme of PyQt5: when the QWebEngineUrlSchemeHandler subclass processes the editor: / / protocol request, the paragraph ID is directly forwarded to the main window slot function through QTimer.singleShot (without the complex parameters encapsulated in QByteArray); the actual working process of the positioning system is: the front-end click triggers selectElement() to send a URL request containing para_id → the back-end EditorUrlSchemeHandler parses the ID → WordEditor.highlight_selected() performs three operations through runJavaScript: clearing the old highlight → positioning the target insertion point → adding the.active-insert class and triggering smooth scrolling.
[0034] S7. Edit the temporary intermediate solution file: Use WordEditor to insert project feature content into the temporary intermediate solution file to form the solution file to be generated. Specifically, it includes: loading and parsing the temporary intermediate solution file, positioning the visual insertion point based on QWebEngineView, identifying the content type and performing corresponding text, Excel table, and picture insertion operations, maintaining style consistency, and converting to HTML through Pandoc for preview, and finally saving it as a temporary file after versioning; first, load and parse the temporary intermediate solution file that has completed placeholder replacement, and build a two-way mapping relationship between the document object model and the visual editing interface; implement a precise insertion point positioning system based on the visual interface of QWebEngineView, render the document HTML preview and capture click events, and convert the interface coordinates to the physical position index of the document paragraph / table; the system automatically identifies the content type to be inserted (text / picture / table) and calls the corresponding insertion method - the text content inherits the font style attributes of the target paragraph, the picture automatically calculates the aspect ratio and applies the preset wrapping format, and the Excel table is parsed through openpyxl and converted into the native Word table structure; all insertion operations are forced to verify format consistency through the style manager to ensure that the newly added content is compatible with the original document style system; a new version with a timestamp ("solution_to_be_generated_timestamp.docx") is automatically generated after each edit, which not only retains the editing history but also avoids overwriting the original intermediate file. This process ensures a safe evolution from the temporary file to the final solution through atomic operations, so that even in case of abnormal interruption, it can be rolled back to the most recent valid version. The specific method is: for text insertion, use the add_paragraph and add_run methods of python-docx to retain the original format style, for picture insertion, use the add_picture method to achieve dynamic size adjustment and wrapping layout (use OxmlElement to operate on XML to set the wrap attribute), and for Excel tables, parse the data through openpyxl and dynamically generate Word tables (doc.add_table) and retain the cell styles; the editor renders the document content in real time through QWebEngineView.setHtml, and combines MutationObserver to listen for DOM changes to ensure that the editing operation is synchronized with the underlying Word document object, and saves the edited document to the solution file to be generated.
[0035] S8. Edit the cover information of the document to be generated: By identifying the placeholders in the document and replacing them with the corresponding cover information, including the automatic filling of the project name, unit project name, and compilation date, and the insertion of the cover image; By parsing the input project name, unit project name, compilation date, and cover image path, locate the predefined placeholders {{title-1}}, {{title-2}}, {{yyyy-mm-dd-1}}, and {{image:fm-1}} corresponding to the project name, unit project name, and compilation date in the document for replacement. For the cover image placeholder, the system first verifies the validity of the image path. If it exists, clear the placeholder paragraph content and insert the specified image, set the image width to 6 inches and center it. If the image does not exist, retain the placeholder text. The digital Gregorian calendar compilation date in the UI dialogue is converted to Chinese capital format through the convert_calendar_date() function, such as "May 10, 2025". All style modifications directly act on the paragraph Run object to maintain the original format characteristics of the template. The status of the process is recorded through the logging module. This step ensures that the cover information of the document can be automatically filled, improving the standardization, integrity, and enterprise standardization of the cover information. The document to be generated with the cover information loaded can proceed to the next step of previewing the solution.
[0036] S9. Generate and save the final document: Preview the to-be-generated solution file with the loaded cover information, generate the final document from the temporary file based on generate_from_temp, and output and save it. Load and process the document content, and save it with a file name containing the project name, document type, and timestamp. By parsing the XML structure of the Word document, extract the paragraph text and style attributes to generate visual content, and reference and display the pictures in the form of temporary files; when generating the document, accurately locate placeholders such as {{title-1}} for content replacement, and maintain the font, size, and bold style of the original template through the font attribute of paragraph.runs. For table processing, use doc.add_table to create the basic structure and then fill in the data cell by cell and copy style attributes such as bold and border; strictly verify the validity of the file path when inserting pictures, support encoding conversion processing, automatically calculate the height in proportion according to the specified width, and then embed it through run.add_picture; when saving the document, use the naming convention of "Unit Project Name_Document Type_Timestamp.docx", such as "Main Structure Project of Building 1#_Construction Organization Design_20240101_120000.docx", where the document type is automatically converted to "Construction Organization Design" or "Special Construction Plan", and the timestamp is accurate to the second to ensure uniqueness; for exception handling, record errors during file operations, picture loading, etc. through the logging module without interrupting the process; the final document will automatically add a header containing the enterprise logo. All operations are based on the direct modification of the XML structure of the Word document by the python-docx library, which not only maintains the original format characteristics of the template but also ensures the professionalism and standardization of the generated document.
[0037] An intelligent generation system for construction organization design word documents, including: A preset template loading module for loading various preset templates. The document types of the various preset templates are divided into two types: construction organization design and special construction plan. The content structure of the preset template includes fixed content and project feature information content represented by placeholders; A data loading module for reading placeholder replacement data from Excel files in a preset path, including paragraph text replacement data, paragraph picture replacement data, table text replacement data, and table picture replacement data; A project feature information replacement module for traversing the project feature information placeholders in the preset template and automatically replacing the placeholder replacement data to generate a temporary intermediate solution file, including: A paragraph text replacement unit for performing text replacement operations on paragraph text placeholders; A paragraph picture replacement unit for performing picture replacement operations on paragraph picture placeholders; A table cell text replacement unit for performing table cell text replacement operations on table text placeholders; A table cell picture replacement unit for performing table cell picture replacement operations on table picture placeholders; A project feature content insertion module for inserting project feature information content into a temporary intermediate solution file to form a solution file to be generated; including: loading and parsing the temporary intermediate solution file, web-based editing communication settings, visual insertion point positioning based on QWebEngineView, content type recognition and corresponding insertion, maintaining style consistency, and versioned saving; A document preview module for converting the paragraphs and tables of a loaded preset template into HTML format and loading them into a preview window through the setHtml method, and applying CSS styles to enhance the visual effect to achieve visual preview; assigning a unique ID to each paragraph and table, and implementing real-time update and interaction through JavaScript to achieve highlighting and scrolling positioning of selected elements; A cover processing module for processing document cover information for the solution file to be generated, including automatic filling of the project name, unit project name, and compilation date, and insertion of cover pictures; A document generation module for outputting the final word document for the solution file to be generated with completed cover information.
[0038] Embodiment 2: Taking the special construction plan of the template project as an example, a method for intelligently generating a construction organization design word document includes the following steps: S1. Establish a preset template: Establish preset templates for various construction organization designs and construction special plans. The content structure of the preset template includes fixed content and project feature information content represented by placeholders; the preset template contains four types of placeholders: paragraph text placeholders, paragraph picture placeholders, table text placeholders, and table picture placeholders.
[0039] S2. Loading and displaying the preset template: Select the solution type corresponding to the solution to be generated and the adapted preset template; load the preset template and display the fixed content and placeholder information of the preset template in a web view; specifically, for example, when compiling the special construction plan of the template project, the document type should be selected as the special construction plan, and the preset template should be selected as the special construction plan template of the template project. After loading, the fixed content and placeholder information of the preset template can be displayed in the web view, and it can be clearly found whether the loaded template matches the special construction plan of the template project to be generated.
[0040] All the remaining steps are the same as those in Embodiment 1.
[0041] Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the present invention.
Claims
1. An intelligent generation method for a construction organization design word document, characterized in that It includes the following steps: S1. Establish a preset template: Establish preset templates for various construction organization designs and special construction plans. The content structure of the preset template includes fixed content and project feature information content represented by placeholders; S2. Preset template loading and display: Select a preset template adapted to the pre-generated plan, load the preset template and display the fixed content and placeholder information of the preset template in a web view; S3. Data loading: Read the data of the Excel file through the pandas library. First, judge the Excel file type according to the keyword in the Excel file name, and then call the corresponding loading method; The data of each Excel file is classified and stored in different dictionaries after non-empty verification: the paragraph text and table cell text data are stored as dictionary data in the form of placeholders and text content, and the paragraph pictures and table cell picture data are stored as dictionary data in the form of placeholders and their corresponding picture paths, sizes and style information; S4. Placeholder replacement: Traverse the paragraphs and tables in the preset template, search and automatically replace according to the dictionary data of the corresponding placeholders; S5. Generate a temporary intermediate plan file: After performing placeholder replacement, save the replaced document as a temporary intermediate plan file with a timestamp and save it to the preset temporary folder, and record the temporary file path at the same time; S6. Web-based editing communication setting: The system constructs a visual environment by loading a preset HTML template, sets the insertion point through the div element of HTML and CSS styles. When the insertion point is clicked, the JavaScript function triggers a custom editor: / / URL Scheme, and the request is processed through the EditorUrlSchemeHandler class to achieve front-end and back-end communication; S7. Edit the temporary intermediate plan file: Insert project feature content into the temporary intermediate plan file through WordEditor to form a plan file to be generated. Specifically, it includes: loading and parsing the temporary intermediate plan file, positioning the visual insertion point based on QWebEngineView, identifying the content type and performing corresponding text, Excel table, and picture insertion operations, maintaining style consistency, and converting to HTML through Pandoc for preview, and finally saving it as a temporary file after versioning; S8. Edit the cover information of the plan file to be generated: By identifying the placeholders in the document, replace them with the corresponding cover information, including the automatic filling of the project name, unit project name and compilation date, and the insertion of the cover picture; S9. Generate the final document and save it: Generate the final document based on the temporary file through generate_from_temp, output and save it.
2. The intelligent generation method of the construction organization design word document according to claim 1, characterized in that: The preset template in S1 contains four types of placeholders: paragraph text placeholder, paragraph image placeholder, table cell text placeholder, and table cell image placeholder; in S2, the preset template is loaded and displayed in a web view. Specifically: after selecting the preset template, it is loaded from the specified path, and the Pandoc tool is used to convert the preset template into HTML format, which is then displayed through the QWebEngineView component. The fixed content and placeholder markers in the preset template are retained, and CSS styles are applied to ensure the correct rendering of tables and images. After loading is completed, the display effect is dynamically enhanced through JavaScript; for data loading in S3, the paragraph text placeholder and the table cell text placeholder are used to construct a text_replacements dictionary by reading the "placeholder" and "text" columns, while the paragraph image placeholder and the table cell image placeholder read the "placeholder", "path", "width_cm", and "height_cm" columns to construct an image_replacements dictionary. During the loading process, the successfully loaded files and error messages for failed loading are recorded to ensure the integrity and accuracy of the data. Finally, a complete dictionary data containing placeholder names and corresponding content is formed; for placeholder replacement in S4, by traversing the preset template paragraphs and table cells, the replace_paragraph_text_optimized() is used to process the paragraph text placeholder, retaining the first run style and processing special date formats; after parsing the image path using replace_paragraph_image_optimized(), a new paragraph is created to center and insert the image, the height is calculated according to the size, the original placeholder is cleared, the replace_table_text() is used to process the table text according to the paragraph logic, and the replace_table_image() is used to first clear the placeholder, calculate the height according to the configured width, and insert the table cell according to the specified alignment method. All replacements are based on the PlaceholderDataLoader data, automatically handling relative path conversion and style inheritance.
3. The intelligent generation method of the construction organization design word document according to claim 1, characterized in that: S5 generates a temporary intermediate solution file, specifically: After the placeholder replacement is completed, datetime.now().strftime("%Y%m%d_%H%M%S") is called to generate a timestamp, and strftime("%Y%m%d_%H%M%S") is used to convert the timestamp into the format of "year-month-day_hour:minute:second". Then, a temporary file named "intermediate solution_timestamp.docx" is created in the temp subdirectory of the project, the temporary file is saved, and the temporary file path is recorded. The temporary file path is stored in the instance variable temp_file.
4. The intelligent generation method of the construction organization design word document according to claim 1, wherein: The web-based editing communication settings in S6 are specifically as follows: After loading the temporary intermediate solution file through the python-docx library, use enumerate(paragraphs) and enumerate(tables) to generate consecutive numbered ID identifiers for the document paragraphs and tables for front-end interactive positioning; in the HTML conversion stage, preset insertion point divs before the ordinary paragraphs after the first-level heading paragraph, after the end of the table, and at the beginning of the document. Automatically insert CSS-style <div class=""insert-point”">Visualization marker; build an HTML visualization editing interface based on the QWebEngineView component, use QWebEngineUrlScheme.registerScheme to register a custom URL protocol, establish a front-end and back-end communication channel through the custom editor: / / URL Scheme. When a click occurs at the insertion point in the HTML interface, the front-end JavaScript triggers an editor: / / / select request through the selectElement() function and carries the target paragraph ID parameter. The back-end captures the request and parses the parameters through the EditorUrlSchemeHandler class implemented by inheriting QWebEngineUrlSchemeHandler, and updates the status of the currently selected paragraph by the handle_element_selected method of DocumentController. The status of the currently selected paragraph includes displaying the unique ID of the currently selected position in the status panel and visually highlighting the target paragraph.
5. The intelligent generation method of the construction organization design word document according to claim 1, wherein: The specific operation of inserting project feature information content into the temporary intermediate solution file through WordEditor in S7 is as follows: For text insertion, the add_paragraph and add_run methods of python-docx are used to retain the original format style. For picture insertion, dynamic size adjustment and wrap layout are achieved through the add_picture method. For Excel table insertion, the data is parsed by openpyxl and then a Word table is dynamically generated and the cell styles are retained. WordEditor renders the document content in real time through QWebEngineView.setHtml, and combines MutationObserver to monitor DOM changes to ensure that the editing operations are synchronized with the underlying Word document object, and saves the edited document to the solution file to be generated.
6. The intelligent generation method of the construction organization design word document according to claim 1, characterized in that The generation of temporary files is specifically as follows: During the document editing process, the system creates a subdirectory named temp for storing temporary files in the directory where the program is located. When the user performs a save operation, a timestamp is generated and used to name the temporary file. The naming format of the temporary file is "intermediate solution_timestamp.docx" or "solution to be generated_timestamp.docx". The system ensures the existence of the temporary directory through os.makedirs, and saves the current document content to the temporary file through the save method of the Document object.
7. The intelligent generation method of the construction organization design word document according to claim 6, wherein The generation of the final document in S9 is specifically as follows: By loading the temporary file "to-be-generated-solution_timestamp.docx", the Document class is used to process the document content. The text content is added or modified paragraph by paragraph through the add_paragraph method, and the run.font property is synchronously set to configure the font style. The table content is inserted through the add_table method, including obtaining the number of data rows and columns first and then creating the table structure, and filling the cell data through a double-layer loop. The picture content is inserted through the add_picture, including the verification of the picture path and the calculation of the proportional scaling of the size. In the document saving link, the save method is called to save the document to the specified path. In the generate_from_temp method, first, it is checked whether the temporary file exists, then the temporary document is loaded for processing, and finally, it is saved to the output directory. The output path is generated through the get_output_path method.
8. An intelligent generation system for construction organization design word documents, characterized in that, Including: A preset template loading module for loading various preset templates. The document types of the various preset templates are divided into two types: construction organization design and special construction plan. The content structure of the preset template includes fixed content and project feature information content represented by placeholders. A data loading module for reading placeholder replacement data from Excel files in a preset path, including paragraph text replacement data, paragraph picture replacement data, table text replacement data, and table picture replacement data. A project feature information replacement module for traversing the project feature information placeholders in the preset template and automatically replacing the placeholder replacement data to generate a temporary intermediate solution file, including: A paragraph text replacement unit for performing text replacement operations on paragraph text placeholders. A paragraph picture replacement unit for performing picture replacement operations on paragraph picture placeholders. A table cell text replacement unit for performing table cell text replacement operations on table text placeholders. A table cell picture replacement unit for performing table cell picture replacement operations on table picture placeholders. A project feature content insertion module for inserting project feature information content into the temporary intermediate solution file to form a to-be-generated solution file, including: loading and parsing the temporary intermediate solution file, web-based editing communication settings, visual insertion point positioning based on QWebEngineView, content type recognition and corresponding insertion, maintaining style consistency, and versioned saving. A document preview module for converting the paragraphs and tables of the loaded preset template into HTML format and loading them into the preview window through the setHtml method, and applying CSS styles to enhance the visual effect to achieve visual preview. A unique ID is assigned to each paragraph and table, and real-time update and interaction are achieved through JavaScript to highlight and scroll and position the selected elements. A cover processing module for processing the document cover information of the to-be-generated solution file, including the automatic filling of the project name, unit project name, and compilation date, and the insertion of the cover picture. A document generation module for outputting a final word document for a solution file to be generated with cover information already completed.
Citation Information
Patent Citations
Method for intelligently generating report by algorithm model research result
CN115392210A
Water conservancy project construction scheme intelligent management system and construction organization design method
CN116562819A
Construction organization design intelligent compilation method and system
CN118798151A
Professional online collaborative editing method and system for hydropower project cost schemes
CN119720965A
Intelligent auxiliary generation method for power grid project review opinions based on information extraction
CN119721021A
Cited By
Method and device for replacing logo picture in document, equipment and medium
CN121053257A
Method and system for generating construction scheme in infrastructure field
CN121117207A
Special construction scheme document generation method based on large language model
CN121810224A