Template file processing method, device, electronic device and storage medium

By automatically filling content with placeholders in template files, the problem of manual filling affecting accuracy and efficiency is solved, and the rapid resource replacement and management of template files is realized, and processing efficiency is improved.

CN118798149BActive Publication Date: 2024-12-31TIANZHI ENG CONSULTING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411268419.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2024-12-31
Estimated Expiration
2044-09-11

AI Technical Summary

Technical Problem

During the processing of template files, manual filling may affect accuracy and efficiency, and problems such as network delay and file leakage lead to storage and access difficulties.

Method used

By obtaining the placeholders in the initial template file, decompressing them into XML format, replacing the placeholders according to the content to be replaced, generating the target file, and realizing automated fill and quick resource replacement.

Benefits of technology

Improves the accuracy and efficiency of template file processing, reduces manual filling steps, suitable for template management and updates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118798149B_ABST
    Figure CN118798149B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a template file processing method, device, electronic device and storage medium, which are applied to the field of file processing technology and can solve the problem that manually filling in template files affects accuracy and efficiency. An initial template file in an initial format is obtained, the initial template file includes at least one initial placeholder, each initial placeholder corresponds to a replacement position, and the initial format is docx format; the initial template file is decompressed to obtain a target template file in a target format, and the target format is xml format; according to the replacement position corresponding to at least one content to be replaced, the target placeholder corresponding to each content to be replaced is determined in the target template file; the target placeholder is replaced according to the content to be replaced to obtain the target file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of file processing technology, and in particular to a template file processing method, device, electronic device and storage medium. Background Art

[0002] Normally, template files are stored in storage platforms, databases or file servers. According to the development needs of developers, template files can be retrieved and then modified and filled in. In this process, network delays, file leakage and other problems may occur in the process of retrieving template files, and the template files need to be filled in manually, which may affect the accuracy and efficiency of template file processing. Summary of the invention

[0003] In order to solve the above technical problems or at least partially solve the above technical problems, the embodiments of the present application provide a template file processing method, device, electronic device and storage medium to solve the problem that manually filling in template files affects accuracy and efficiency.

[0004] In order to achieve the above purpose, the technical solutions provided by the embodiments of the present application are as follows:

[0005] In a first aspect, an embodiment of the present application provides a template file processing method, the template file processing method comprising: obtaining an initial template file in an initial format, the initial template file comprising at least one initial placeholder, each initial placeholder corresponding to a mark of a replacement position, the initial format being a docx format;

[0006] Decompressing the initial template file to obtain a target template file in a target format, wherein the target format is an XML format;

[0007] Determine, in the target template file, a target placeholder corresponding to each to-be-replaced content according to a replacement position corresponding to at least one to-be-replaced content;

[0008] Replace the target placeholder according to the content to be replaced, and obtain the target file

[0009] As an optional implementation manner, in the first aspect of the embodiment of the present application, the obtaining of the initial template file in the initial format includes:

[0010] Obtaining the original template file in the initial format;

[0011] In the original template file, determining at least one replacement position;

[0012] The initial placeholder is added at each replacement position to obtain the initial template file.

[0013] As an optional implementation manner, in the first aspect of the embodiment of the present application, after obtaining the initial template file, the method further includes:

[0014] The initial template file is packaged by a preset tool to obtain a target JAR file;

[0015] Upload the target JAR file to the server.

[0016] As an optional implementation manner, in the first aspect of the embodiment of the present application, the obtaining of the initial template file in the initial format includes:

[0017] The initial template file in the initial format is retrieved from the server.

[0018] As an optional implementation manner, in the first aspect of the embodiment of the present application, replacing the target placeholder according to the content to be replaced to obtain the target file includes:

[0019] According to the replacement rule corresponding to each replacement position in the target template file, the target placeholder is replaced according to the content to be replaced to obtain the target file.

[0020] As an optional implementation manner, in the first aspect of the embodiment of the present application, replacing the target placeholder according to the content to be replaced to obtain the target file includes:

[0021] Replace the target placeholder according to the content to be replaced to obtain a first file;

[0022] The format of the first file is converted from the target format to the initial format to obtain the target file.

[0023] In a second aspect, an embodiment of the present application provides a template file processing device, the template file processing device comprising: an acquisition module, used to acquire an initial template file in an initial format, the initial template file comprising at least one initial placeholder, each initial placeholder corresponding to a replacement position, the initial format being a docx format;

[0024] A processing module, used for decompressing the initial template file to obtain a target template file in a target format, wherein the target format is an XML format;

[0025] The processing module is further used to determine, in the target template file, a target placeholder corresponding to each to-be-replaced content according to a replacement position respectively corresponding to at least one to-be-replaced content;

[0026] The processing module is further used to replace the target placeholder according to the content to be replaced to obtain a target file.

[0027] As an optional implementation, in the second aspect of the embodiment of the present application, the acquisition module is further used to acquire the original template file in the initial format;

[0028] The processing module is further used to determine at least one replacement position in the original template file;

[0029] The processing module is further used to add the initial placeholder at each replacement position to obtain the initial template file.

[0030] As an optional implementation, in the second aspect of the embodiment of the present application, the processing module is further used to package the initial template file through a preset tool to obtain a target JAR file;

[0031] The processing module is specifically used to upload the target JAR file to the server.

[0032] As an optional implementation, in the second aspect of the embodiment of the present application, the processing module is further used to retrieve the initial template file in the initial format from the server.

[0033] As an optional implementation, in the second aspect of the embodiment of the present application, the processing module is specifically used to replace the target placeholder according to the content to be replaced according to the replacement rule corresponding to each replacement position in the target template file to obtain the target file.

[0034] As an optional implementation, in the second aspect of the embodiment of the present application, the processing module is specifically configured to replace the target placeholder according to the content to be replaced to obtain a first file;

[0035] The processing module is specifically used to convert the format of the first file from the target format to the initial format to obtain the target file.

[0036] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising:

[0037] A memory storing executable program code;

[0038] a processor coupled to the memory;

[0039] The processor calls the executable program code stored in the memory to execute the template file processing method in the first aspect of the embodiment of the present application.

[0040] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute the template file processing method in the first aspect of the embodiment of the present application. The computer-readable storage medium includes a ROM / RAM, a magnetic disk or an optical disk, etc.

[0041] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute part or all of the steps of any one of the methods of the first aspect.

[0042] In a sixth aspect, an embodiment of the present application provides an application publishing platform, which is used to publish a computer program product, wherein when the computer program product runs on a computer, the computer executes part or all of the steps of any one method of the first aspect.

[0043] Compared with the prior art, the embodiments of the present application have the following beneficial effects:

[0044] The embodiment of the present application provides a template file processing method, device, electronic device and storage medium, which obtains an initial template file of an initial format, wherein the initial template file includes at least one initial placeholder, each initial placeholder corresponds to a replacement position, and the initial format is docx format; the initial template file is decompressed to obtain a target template file of a target format, and the target format is xml format; according to the replacement position corresponding to at least one content to be replaced, the target placeholder corresponding to each content to be replaced is determined in the target template file; the target placeholder is replaced according to the content to be replaced to obtain the target file. In this scheme, by adding a placeholder to each replacement position in the template file, when the template file is modified and filled with content, the placeholder at the corresponding position can be directly replaced, so that manual filling is not required, and the format of the template file is converted into an xml format suitable for filling and editing, which realizes quick resource replacement and template management and update, and effectively improves the accuracy and efficiency of template file processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0047] Figure 1 This is a schematic diagram of a template file processing method provided in an embodiment of the present application. Figure 1 ;

[0048] Figure 2 This is a schematic diagram of a template file processing method provided in an embodiment of the present application. Figure 2 ;

[0049] Figure 3 It is a structural schematic diagram of a template file processing device provided in an embodiment of the present application;

[0050] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0052] The terms “first”, “second” and the like in the description and claims of the present application are used to distinguish different objects rather than to describe a specific order of the objects.

[0053] The terms "including" and "having" and any variations thereof in the embodiments of the present application are intended to cover non-exclusive inclusions. For example, a process, method, system, product or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products or apparatuses.

[0054] It should be noted that, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0055] During the development process, developers usually put template files into storage platforms, databases or file servers. This process has some shortcomings, such as network latency issues: if template files are stored in a remote storage platform, database or file server, they may be affected by network latency and read files more slowly; and reliability issues: the storage platform, database or file server may fail or become unavailable, making it impossible to read template files; and security issues: storing template files in storage platforms, databases or file servers may increase the risk of file leakage, requiring additional security measures to protect the confidentiality of files; and maintenance cost issues: storage platforms, databases or file servers require additional maintenance costs, including backup, monitoring, and updates, which increases the complexity of the system; and scalability issues: if template files need to be accessed from multiple locations, additional work may be required to ensure file synchronization and consistency.

[0056] In order to solve the above technical problems, the embodiment of the present application proposes a template file processing method, device, electronic device and storage medium, obtains an initial template file of an initial format, the initial template file includes at least one initial placeholder, each initial placeholder corresponds to a replacement position, and the initial format is docx format; decompresses the initial template file to obtain a target template file of a target format, and the target format is xml format; according to the replacement position corresponding to at least one content to be replaced, the target placeholder corresponding to each content to be replaced is determined in the target template file; the target placeholder is replaced according to the content to be replaced to obtain the target file. In this scheme, by adding a placeholder to each replacement position in the template file, when the template file is modified and filled with content, the placeholder at the corresponding position can be directly replaced, so that manual filling is not required, and the format of the template file is converted into an xml format suitable for filling and editing, which realizes quick resource replacement and template management and update, and effectively improves the accuracy and efficiency of template file processing.

[0057] like Figure 1 As shown, Figure 1 A flowchart of a template file processing method provided in an embodiment of the present application, the method may include the following steps:

[0058] 101. Obtain an initial template file in an initial format.

[0059] In an embodiment of the present application, the initial template file may include at least one initial placeholder, and each initial placeholder corresponds to a replacement position. That is to say, in the initial template file, there is an initial placeholder for each position that can be replaced, and when replacing, the placeholder can be directly replaced by the content to be replaced.

[0060] It should be noted that the initial template file may include at least one replacement position, and the replacement position may be one, two or more, and the number is not limited.

[0061] In some embodiments, a placeholder is a concept widely used in computer programming and document editing. It is mainly used to represent a position that will be replaced or filled with actual content in the future. A placeholder is a symbol that first occupies a fixed position and waits for the user or program to add content to it. A placeholder is replaceable, that is, the position where it is located will eventually be replaced by other values ​​or content.

[0062] Placeholders can be applied to multiple scenarios, such as document editing. In slide production, placeholders appear as a virtual box, which often has prompts such as "Click here to add a title" inside. They are used to plan the slide structure, and in document typesetting, when you need to reserve space for pictures or other content in the layout, you can use placeholders to set the width and height first, and then replace them with actual content after deciding. It can also be applied to web design, specifically to adjust the position of each part of the layout in the web page. By adjusting the size and position of the placeholder, you can easily control the layout of page elements. It can also be applied to the field of programming. In programming languages, placeholders are often used in scenarios such as string formatting, SQL statement construction, and URL splicing. Through placeholders, you can dynamically generate strings or build query statements at runtime to improve the readability and maintainability of the code.

[0063] Common placeholder symbols include percent sign (%) and curly braces ({}). In the old string formatting methods, such as the % operator in Python, %s represents a string placeholder, and %d represents an integer placeholder. In modern programming languages, such as Python's .format() method and f-string (formatted string literal), curly braces are often used as placeholders. Through the .format() method or f-string, the value of the variable can be filled into the position represented by the curly braces.

[0064] In an embodiment of the present application, the placeholder can be represented by ${x}, where x can be a number used to indicate the number of each initial placeholder, such as: ${1}, ${2}, ${3}, ..., ${n}, etc.

[0065] In some embodiments, the initial format is a docx format. The format of the initial template file obtained after at least one initial placeholder exists is a docx format. docx (Microsoft Word Document) is mainly used to create, edit and save complex documents such as text, images, tables and multimedia content. The docx format is actually a compressed file containing multiple files and folders. These files and folders store document content in XML and ZIP formats. It supports more text styles, images, tables and multimedia content, making the document content richer. Files in docx format have smaller storage space, occupy fewer resources, and have faster transmission speeds. docx supports digital signatures and encryption technology, which can better ensure the security and integrity of documents.

[0066] 102. Decompress the initial template file to obtain a target template file in a target format.

[0067] In an embodiment of the present application, in order to facilitate the subsequent editing of the template file, the content of the target format in the initial template file in docx format can be decompressed and extracted, and determined as the target template file. The target format includes the xml format, and of course it can also be other plain text formats. The embodiment of the present application does not make specific limitations.

[0068] In some embodiments, the decompression method can be achieved through a decompression algorithm, which refers to an algorithm that restores a compressed file or data to its original size, format, and content. The decompression algorithm can be Huffman decoding, Lempel-Ziv-Welch (LZW) decoding, or Deflate decoding, etc., which is not limited by the embodiments of the present application.

[0069] 103. Determine a target placeholder corresponding to each to-be-replaced content in the target template file according to a replacement position corresponding to at least one to-be-replaced content.

[0070] In an embodiment of the present application, the content to be replaced is the content that needs to replace the placeholder in the target template file. The content to be replaced can refer to specific text content, and the replacement position can indicate the specific position in the template file where the text content needs to replace the content. Since there may be some fixed text in the template file, the fixed text cannot be modified. There may also be some replaceable text in the template file, and the replaceable text can be replaced and modified according to the content to be replaced, thereby obtaining a modified file.

[0071] It should be noted that since the number of contents to be replaced is at least one, the number of initial placeholders in the target template file is also at least one, that is, there may be only one content to be replaced, which needs to correspond to a certain placeholder in the target template file; there may also be multiple contents to be replaced, which need to correspond to multiple placeholders in the target template file; therefore, at least one content to be replaced corresponds to at least one replacement position, then it is necessary to determine these replacement positions in the target template file so that the content to be replaced can be replaced and filled.

[0072] Text replacement can be performed at each replacement position, but not every position needs to be replaced every time a file is replaced. Some positions can directly use template content. Therefore, you can match the replacement position corresponding to each content to be replaced in the target template file, find the position that needs to be replaced, and then determine the initial placeholders corresponding to these positions as the target placeholders. The target placeholders are the ones that need text replacement.

[0073] It should be noted that in the target template file, each replacement position is numbered by a placeholder, which is unique for each replacement position, and each content to be replaced corresponds to a unique replacement position, which is also determined by the number. Therefore, the replacement position and the placeholder can be directly matched by the number.

[0074] 104. Replace the target placeholder according to the content to be replaced to obtain the target file.

[0075] In an embodiment of the present application, after the target placeholder is determined, that is, each position and corresponding content that needs to be replaced, the target placeholder can be replaced according to the content to be replaced, thereby obtaining a target file, in which the target placeholder in the original template file has been replaced with the content to be replaced.

[0076] For example, assuming that the target template file may include: name: ${1}; gender: ${2}; age: ${3}, it can be seen that the target template file includes three placeholders, that is, "name", "gender" and "age" are fixed template contents, while the specific name, gender and age can be filled in freely, so placeholders are used. Assuming that the content to be replaced includes: Zhang San, {1}; female, {2}; 26, {3}, it can be seen that in the above three contents to be replaced, each of the contents to be replaced corresponds to a replacement position number, so the three contents to be replaced can be matched with the three placeholders in the target template file, that is, "Zhang San" corresponds to ${1}, "female" corresponds to ${2}, and "26" corresponds to ${3}, so "Zhang San" can be replaced with ${1}, "female" can be replaced with ${2}, and "26" can be replaced with ${3}, so as to obtain the target file, which can be expressed as: name: Zhang San; gender: female; age: 26.

[0077] The embodiment of the present application provides a template file processing method, which obtains an initial template file in an initial format, wherein the initial template file includes at least one initial placeholder, each initial placeholder corresponds to a replacement position, and the initial format is docx format; the initial template file is decompressed to obtain a target template file in a target format, and the target format is xml format; according to the replacement position corresponding to at least one content to be replaced, the target placeholder corresponding to each content to be replaced is determined in the target template file; the target placeholder is replaced according to the content to be replaced to obtain the target file. In this scheme, by adding placeholders to each replacement position in the template file, when the template file is modified and filled with content, the placeholders at the corresponding positions can be directly replaced, so that manual filling is not required, and the format of the template file is converted into an xml format suitable for filling and editing, which realizes quick resource replacement and template management and update, and effectively improves the accuracy and efficiency of template file processing.

[0078] like Figure 2 As shown, Figure 2 A flow chart of a template file processing method provided in an embodiment of the present application, the method may also include the following steps:

[0079] 201. Obtain an original template file in an initial format.

[0080] In an embodiment of the present application, the original template file may be a pre-stored template file that is directly retrieved, and the original template file may include some fixed text content.

[0081] 202. In the original template file, determine at least one replacement position.

[0082] In an embodiment of the present application, the original template file includes fixed text and replaceable text, so the replacement position corresponding to each replaceable text can be determined. The replaceable text and the replacement position are one-to-one corresponding, and the replacement position may include at least one, one, two or more.

[0083] 203. Add an initial placeholder at each replacement position to obtain an initial template file.

[0084] In the embodiment of the present application, a placeholder needs to be added for each replacement position, so that at least one initial placeholder is added to the original template file to obtain an initial template file.

[0085] In some embodiments, after the initial placeholder is added at each replacement position, an initial template file is generated by the template engine.

[0086] It should be noted that the Template Engine is a technology commonly used in software development, especially in Web development, which allows developers to separate interface design from business logic and dynamically generate HTML or other types of documents by using predefined template tags. The working principle of the template engine is usually to combine the template file (usually an HTML file with the specific syntax of the template engine embedded in it) with the data model to generate the final document. The template file defines the static part and the dynamic content part of the page. The dynamic content part uses template tags to specify how to obtain data from the data model and display it on the page.

[0087] In the embodiment of the present application, the template engine may generally be Freemarker or Thymeleaf.

[0088] Among them, FreeMarker was originally designed to generate HTML pages in the Web development framework of the MVC (Model-View-Controller) mode, but it is not bound to Servlet or HTML or anything Web-related, so it can also be used in non-Web application environments. FreeMarker is a Java class library that programmers can embed into the components of the products they develop. The working principle of FreeMarker can be simply summarized as "template + data model = output". Developers first prepare the data model, which usually involves operations such as database queries and business operations. Then, the FreeMarker engine combines the prepared data model with the template file to generate the final output text. In the template file, developers use FTL syntax to define how to display data, such as using interpolation expressions ${...} to output the value of variables, or using FTL instructions to control loops, conditional judgments and other logic. Thymeleaf is a modern server-side Java template engine for Web and standalone environments that can process HTML, XML, JavaScript, CSS and even plain text. The main goal of Thymeleaf is to provide an elegant and highly maintainable way to create templates. It injects its logic into template files by establishing the concept of natural templates. In the embodiments of the present application, Freemarker or Thymeleaf can be used to generate the initial template file. Of course, other template engines can also be used, and the embodiments of the present application do not make specific limitations.

[0089] 204. The initial template file is packaged by a preset tool to obtain a target JAR file.

[0090] In the embodiment of the present application, after the initial template file is obtained, the initial template file can be packaged by a preset tool to obtain a target JAR file.

[0091] In some embodiments, when the initial template file is packaged, a replacement rule may also be included, that is, the initial template file and the replacement rule are packaged together to obtain a target JAR file. The replacement rule may indicate a rule for replacing each placeholder.

[0092] It should be noted that a JAR (Java Archive) file is a file format used to package multiple Java class files, related metadata, and resources (such as text, images, etc.) so that they can be distributed, transmitted, or deployed as a single unit. A JAR file is an archive file format based on the ZIP file format, but with specific metadata and directory structure that enables it to be directly recognized and executed by the Java Virtual Machine (JVM). A JAR file can package all necessary components of an application or library into a single file for easy download and installation by users. Java Web Start technology allows users to directly launch Java applications through a browser, and these applications are usually packaged into JAR files. In Java EE applications, JAR files are also used to package Java Servlets, JSP pages, and other resources to form part of a WAR (Web Application Archive) file for deploying Web applications. The Java platform can be extended through JAR files, which contain additional class libraries or extensions to the Java Virtual Machine (JVM).

[0093] In some embodiments, packaging the template file into a JAR file can easily deploy the application to different environments without paying extra attention to the location and deployment of the template file. Placing the template file and the application code in the same JAR file can make the application neater and easier to maintain and manage. The JAR file is a cross-platform packaging format that can run on different operating systems without worrying about path separators and file system differences. The resource files in the JAR file can be easily accessed through the class loader, making it simple to read the template file in the code.

[0094] It should be noted that the preset tool can be a Maven build tool. Maven is a project management and build automation tool based on the concept of Project Object Model (POM). Maven enables developers to manage project builds, reports, and documents more easily. Maven provides a standard directory structure, life cycle, and plug-in system, making the build process more standardized and reusable.

[0095] Among them, Maven provides a powerful dependency management function, which can automatically download the libraries (jar packages) that the project depends on and manage the dependencies between these libraries. Developers only need to declare the required dependencies in the project's pom.xml file, and Maven will automatically handle the download and version conflicts of these dependencies. Maven supports various stages of the project's build life cycle, such as compilation, testing, packaging, and deployment. Developers can execute these stages through simple commands without manually configuring complex build scripts. Maven can generate project websites and documents, including project reports, API documents, etc., making project information sharing and document management more convenient. Maven provides a standardized directory structure and build life cycle, making the project structure clearer, and also facilitating integration and collaboration between different projects. Maven's plug-in system is very powerful. Developers can use or develop plug-ins to extend Maven's functionality to meet the specific needs of the project.

[0096] It should be noted that Maven is mainly used through the command line tool mvn. Developers can execute Maven commands in the root directory of the project to build, test, and package projects. For example, the mvn clean install command will first clean the project, then compile, test, and package the project, and finally install the packaged files into the local repository.

[0097] 205. Upload the target JAR file to the server.

[0098] In an embodiment of the present application, the packaged target JAR file can be uploaded to the server, so that other users can also retrieve the target JAR file from the server and disassemble the initial template file to perform text replacement.

[0099] 206. Obtain the file to be replaced.

[0100] In an embodiment of the present application, the file to be replaced may refer to a file that needs to be substituted into a template file for replacement. The file to be replaced may include at least one content to be replaced and a corresponding replacement position. The content to be replaced may refer to specific text content. The replacement position may indicate the specific position in the template file where the text content needs to replace the content. Since there may be some fixed text in the template file, the fixed text cannot be modified. There may also be some replaceable text in the template file, and the replaceable text can be replaced and modified by itself to obtain a modified file.

[0101] It should be noted that the file to be replaced is used to replace the replaceable text in the template file, so as to generate the desired complete file.

[0102] In some embodiments, the method of obtaining the file to be replaced may include: obtaining the file to be replaced uploaded by the user; or, retrieving the file to be replaced from a database; or, editing the file to be replaced online according to needs. Of course, it may also include many other methods, which are not specifically limited in the embodiments of the present application.

[0103] It should be noted that the file to be replaced uploaded by the user can be the content that the user needs to replace through the template file. The template file is replaced according to the file to be replaced uploaded by the user, so as to obtain the file the user wants and then output it to the user; the file to be replaced retrieved from the database can be a text formed by some pre-stored content, such as a daily fixed task-type file. The content that needs to be filled in and replaced for the template file is pre-fixed, so it can be retrieved directly from the database every day without the need for re-editing; the file to be replaced can be obtained by online editing according to needs, which can be generated by real-time editing. The replacement content and the corresponding replacement position can be directly edited online for the replaceable text in the template file, so as to generate the file to be replaced.

[0104] 207. Retrieve an initial template file in an initial format from a server.

[0105] 208. Decompress the initial template file to obtain a target template file in a target format.

[0106] 209. Determine a target placeholder corresponding to each to-be-replaced content in the target template file according to a replacement position corresponding to at least one to-be-replaced content.

[0107] 210. Replace the target placeholder according to the content to be replaced to obtain the target file.

[0108] In the embodiment of the present application, for the description of steps 208 to 210, please refer to the detailed description of steps 102 to 104 in the above embodiment, which will not be repeated in the embodiment of the present application.

[0109] In some embodiments, when replacing the target placeholder according to the content to be replaced, it is necessary to perform the replacement according to certain rules. The rule may be a rule corresponding to each replacement position. That is to say, when adding the initial placeholder at each replacement position, the replacement rule corresponding to the replacement position may be determined at the same time. In this way, when the content is subsequently replaced, the replacement may be performed according to the replacement rule. Specifically, according to the replacement rule corresponding to each replacement position in the target template file, the target placeholder is replaced according to the content to be replaced to obtain the target file.

[0110] It should be noted that the replacement rule may be some pre-stored fixed rules, or may be a rule set by oneself when adding a placeholder, and the embodiment of the present application does not make any specific limitation.

[0111] In some embodiments, specifically, the target placeholder is replaced according to the content to be replaced to obtain the first file; and the format of the first file is converted from the target format to the initial format to obtain the target file.

[0112] It should be noted that after the initial placeholder is added to the template file, the XML format file is decompressed and extracted from the docx format file as the target template file. Therefore, after replacing the target placeholder with the content to be replaced, format conversion is required, that is, the XML format file can be compressed and converted into a docx format file again. The target format is the XML format, and the initial format is the docx format.

[0113] A template file processing method provided by an embodiment of the present application adds a placeholder at each replacement position in the template file, so that when the template file is modified and filled with content, the placeholder at the corresponding position can be directly replaced, which does not require manual filling. The format of the template file is converted into an XML format suitable for filling and editing to facilitate replacement and filling, thereby achieving quick resource replacement and template management and updating, and effectively improving the accuracy and efficiency of template file processing.

[0114] like Figure 3 As shown, an embodiment of the present application provides a template file processing device, which may include: an acquisition module 301, used to acquire an initial template file in an initial format, the initial template file includes at least one initial placeholder, each initial placeholder corresponds to a replacement position, and the initial format is a docx format;

[0115] Processing module 302, used to decompress the initial template file to obtain a target template file in a target format, where the target format is XML format;

[0116] The processing module 302 is further configured to determine a target placeholder corresponding to each to-be-replaced content in the target template file according to a replacement position corresponding to at least one to-be-replaced content;

[0117] The processing module 302 is further used to replace the target placeholder according to the content to be replaced to obtain the target file.

[0118] In some embodiments, the acquisition module 301 is further used to acquire an original template file in an initial format;

[0119] The processing module 302 is further used to determine at least one replacement position in the original template file;

[0120] The processing module 302 is further configured to add an initial placeholder at each replacement position to obtain an initial template file.

[0121] In some embodiments, the processing module 302 is further used to package the initial template file through a preset tool to obtain a target JAR file;

[0122] The processing module 302 is specifically configured to upload the target JAR file to the server.

[0123] In some embodiments, the processing module 302 is further used to retrieve an initial template file in an initial format from a server.

[0124] In some embodiments, the processing module 302 is specifically configured to replace the target placeholder according to the content to be replaced according to the replacement rule corresponding to each replacement position in the target template file, so as to obtain the target file.

[0125] In some embodiments, the processing module 302 is specifically configured to replace the target placeholder according to the content to be replaced to obtain the first file;

[0126] The processing module 302 is specifically configured to convert the format of the first file from a target format to an initial format to obtain a target file.

[0127] In the embodiments of the present application, each module can implement the template file processing method provided in the above method embodiments and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0128] like Figure 4 As shown, an embodiment of the present application further provides an electronic device, which may include:

[0129] A memory 401 storing executable program codes;

[0130] a processor 402 coupled to the memory 401;

[0131] The processor 402 calls the executable program code stored in the memory 401 to execute the template file processing method executed by the electronic device in the above-mentioned method embodiments.

[0132] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the template file processing method in the above method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0133] An embodiment of the present application also provides a computer program product, which stores a computer program. When the computer program is executed by a processor, it implements the various processes of the template file processing method in the above method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0134] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media that include computer-usable program code.

[0135] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0136] In the present application, the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0137] In this application, memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0138] In this application, a person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the relevant hardware through a program, and the program can be stored in a computer-readable storage medium, and the computer-readable medium includes permanent and non-permanent, removable and non-removable storage media. The storage medium can implement information storage by any method or technology, and the information can be a computer-readable instruction, a data structure, a module of a program, or other data. Examples of computer storage media include, but are not limited to, Parallel Random Access Memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Programmable Read-only Memory (PROM), Erasable Programmable Read Only Memory (EPROM), other types of Random Access Memory (RAM), Read-Only Memory (ROM), One-time Programmable Read-Only Memory (OTPROM), Electrically-Erasable Programmable Read-Only Memory (EEPROM), flash memory or other memory technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0139] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0140] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. Those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application. The above-mentioned multiple embodiments are not necessarily multiple independent embodiments. Dividing into multiple embodiments is only used to highlight the different technical features in different embodiments. Those skilled in the art should be aware that the above-mentioned multiple embodiments can also be combined in any way.

[0141] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the above-mentioned processes does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0142] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0143] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0144] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several requests for a computer device (which can be a personal computer, server or network device, etc., specifically a processor in a computer device) to perform some or all of the steps of the above-mentioned methods of various embodiments of the present application.

[0145] The above is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A template file processing method, characterized in that: The method comprises: Obtain an initial template file in an initial format, wherein the initial template file includes at least one initial placeholder, each initial placeholder marks a corresponding replacement position, and the initial format is a docx format; Decompressing the initial template file to obtain a target template file in a target format, wherein the target format is an XML format; According to the replacement position corresponding to at least one content to be replaced, a target placeholder corresponding to each content to be replaced is determined in the target template file, wherein when the content to be replaced is text content, the replacement position is used to indicate that the text content needs to replace the content at the corresponding position in the target template file, the target placeholder is the initial placeholder that needs to be replaced with text, the target placeholder and the replacement position are corresponded by numbers, and each content to be replaced corresponds to a number of the replacement position; Replace the target placeholder according to the content to be replaced to obtain a target file; The step of obtaining the initial template file in the initial format includes: Acquire an original template file in the initial format, wherein the original template file is a pre-stored template file obtained by directly calling; In the original template file, determining at least one replacement position, the original template file comprising fixed text and replaceable text, each replaceable text corresponding to one replacement position; Add the initial placeholder at each replacement position to obtain the initial template file, wherein the initial template file is generated by a template engine, and the template engine is Freemarker or Thymeleaf; After obtaining the initial template file, the method further includes: The initial template file is packaged by a preset tool to obtain a target JAR file, wherein the preset tool is a Maven build tool; Upload the target JAR file to the server; Get the file to be replaced; The obtaining of the file to be replaced comprises: obtaining the file to be replaced uploaded by the user; Alternatively, the file to be replaced is retrieved from a database; Alternatively, the file to be replaced is obtained by online editing according to the requirements; The initial template file in the initial format is retrieved from the server.

2. The method according to claim 1, characterized in that The step of replacing the target placeholder according to the content to be replaced to obtain the target file includes: According to the replacement rule corresponding to each replacement position in the target template file, the target placeholder is replaced according to the content to be replaced to obtain the target file.

3. The method according to claim 1, characterized in that The step of replacing the target placeholder according to the content to be replaced to obtain the target file includes: Replace the target placeholder according to the content to be replaced to obtain a first file; The format of the first file is converted from the target format to the initial format to obtain the target file.

4. A template file processing device, characterized in that: The template file processing device comprises: An acquisition module is used to acquire an initial template file in an initial format, wherein the initial template file includes at least one initial placeholder, each initial placeholder corresponds to a mark of a replacement position, and the initial format is a docx format; A processing module, used for decompressing the initial template file to obtain a target template file in a target format, wherein the target format is an XML format; The processing module is further used to determine a target placeholder corresponding to each to-be-replaced content in the target template file according to a replacement position corresponding to at least one to-be-replaced content, wherein when the to-be-replaced content is text content, the replacement position is used to indicate that the text content needs to replace the content at the corresponding position in the target template file, the target placeholder is the initial placeholder that needs to be replaced with text, the target placeholder and the replacement position are corresponded by numbers, and each to-be-replaced content corresponds to a number of the replacement position; The processing module is further used to replace the target placeholder according to the content to be replaced to obtain a target file; The step of obtaining the initial template file in the initial format includes: Acquire an original template file in the initial format, wherein the original template file is a pre-stored template file obtained by directly calling; In the original template file, determining at least one replacement position, the original template file comprising fixed text and replaceable text, each replaceable text corresponding to one replacement position; Add the initial placeholder at each replacement position to obtain the initial template file, wherein the initial template file is generated by a template engine, and the template engine is Freemarker or Thymeleaf; After obtaining the initial template file, the method further includes: The initial template file is packaged by a preset tool to obtain a target JAR file, wherein the preset tool is a Maven build tool; Upload the target JAR file to the server; Get the file to be replaced; The obtaining of the file to be replaced comprises: obtaining the file to be replaced uploaded by the user; Alternatively, the file to be replaced is retrieved from a database; Alternatively, the file to be replaced is obtained by online editing according to the requirements; The initial template file in the initial format is retrieved from the server.

5. An electronic device, characterized in that: include: A memory storing executable program code; and a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the template file processing method according to any one of claims 1 to 3.

6. A computer-readable storage medium, characterized in that: include: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the template file processing method according to any one of claims 1 to 3 is implemented.