Method, device and equipment for generating word file based on extensible markup language file

文档序号:1799294 发布日期:2021-11-05 浏览:23次 中文

阅读说明:本技术 基于可扩展标记语言文件生成word文件的方法、装置及设备 (Method, device and equipment for generating word file based on extensible markup language file ) 是由 陈凯鹏 于 2021-07-30 设计创作,主要内容包括:本发明涉及一种基于可扩展标记语言文件生成word文件的方法、装置及设备。该方法包括:创建word样式模板;将所述word样式模板转换为可扩展标记语言格式文件;将所述可扩展标记语言格式文件转换为freemarker文件;基于所述freemarker文件生成freemarker模板;将所述freemarker模板输出为word文件。本申请的方法使得word不再难以支持,可以完全通过数据驱动word,可以实现个性化展示以及动态展示,使word生成不再被模板所固定,一个模板可以根据不同数据格式来生成业务场景所需要的word文件,也可让用户根据自己的想法来生成word文件,不用再束缚在预先生成的某个模板上,使得生成word文件的操作更加便捷,降低了维护成本。(The invention relates to a method, a device and equipment for generating a word file based on an extensible markup language file. The method comprises the following steps: creating a word style template; converting the word style template into an extensible markup language format file; converting the extensible markup language format file into a freemarker file; generating a freemarker template based on the freemarker file; and outputting the freemarker template as a word file. The method ensures that the word is not difficult to support any more, the word can be completely driven by data, personalized display and dynamic display can be realized, the generation of the word is not fixed by the template any more, one template can generate the word file required by a service scene according to different data formats, a user can also generate the word file according to own idea without being bound on a certain template generated in advance, the operation of generating the word file is more convenient, and the maintenance cost is reduced.)

1. A method for generating a word file based on an extensible markup language file is characterized by comprising the following steps:

creating a word style template;

converting the word style template into an extensible markup language format file;

converting the extensible markup language format file into a freemarker file;

generating a freemarker template based on the freemarker file;

and outputting the freemarker template as a word file.

2. The method for generating a word file based on an extensible markup language file according to claim 1, wherein said creating a word style template comprises:

setting placeholders and establishing an association relation between the placeholders and data aiming at the word initialization template, editing the word initialization template in a mode of directly filling the placeholders, completing the setting of the template, and obtaining the word style template.

3. The method for generating a word file based on an extensible markup language file according to claim 1, wherein said creating a word style template comprises:

setting a placeholder for marking the position of corresponding data in the word template;

establishing an incidence relation table matched with the placeholder; the incidence relation table is used for storing incidence relations between the placeholders and the corresponding data;

setting a word template according to user requirements, setting placeholders at corresponding positions in the word template, and completing creation of the personalized word template;

acquiring the personalized word template, analyzing the word template content by utilizing the POI to the read-write performance of the word file, and identifying a paragraph part and a table part in the template;

and according to different areas, carrying out distinguishing treatment on each placeholder in the areas.

4. The method for generating a word file based on an extensible markup language file according to claim 3, wherein the distinguishing processing of the placeholders in the region according to the region comprises:

if the paragraph part is processed, identifying the placeholder of the paragraph part according to the placeholder label, and calling a corresponding data from the database to directly replace the placeholder according to the incidence relation between the placeholder and the corresponding data by inquiring the incidence relation table of the universal placeholder;

and if the form part is processed, identifying the placeholder of the form part according to the placeholder label, and forming different data displays according to the placeholder types distributed in each cell by using the row unit to obtain the word style template.

5. The method for generating a word file based on an extensible markup language file according to claim 4, wherein the identifying of the form part placeholder according to the placeholder tag, and the forming of different data displays according to the placeholder types distributed in each cell by a row unit to obtain the word style template comprises:

if all the cells are common placeholders, calling a unique datum from the database to directly replace the common placeholder according to the incidence relation between the placeholder and the corresponding datum by inquiring the incidence relation table of the common placeholder;

if all the cells are the group placeholders, sequentially outputting a matched group of data in a row-by-row cycle manner according to the incidence relation between the characters and the corresponding group of corresponding data by inquiring the incidence relation table of the universal placeholder according to the setting format of the placeholder in each cell;

if the data storage device contains both the common placeholder and the group placeholder, the group placeholder sequentially outputs a matched group of data in a row cycle manner according to the incidence relation between the placeholder and the corresponding data; the general placeholders are used for outputting data according to the circulation times of the group of placeholders, and the corresponding unique data are repeated according to the row circulation in sequence.

6. The method for generating a word file based on an extensible markup language file according to claim 1, wherein said converting the word style template into an extensible markup language format file comprises:

extracting a format object from the word style template; wherein, the objects with different formats have different object format information;

dividing the word style template into at least one level of file blocks according to the format information of the format object;

and converting the divided file blocks of at least one level into extensible markup language format files according to the label information corresponding to each file block and a preset extensible markup language format library.

7. The method for generating a word file based on an extensible markup language file according to claim 1, wherein said converting the word style template into an extensible markup language format file comprises:

converting the content part in the word style template into a first extensible markup language file with a preset format standard through a word structuring engine;

extracting a format file in the word style template;

and appending the format file to the first extensible markup language file to generate a second extensible markup language file.

8. An apparatus for generating a word file based on an extensible markup language file, comprising:

the creating module is used for creating a word style template;

the first conversion module is used for converting the word style template into an extensible markup language format file;

the second conversion module is used for converting the extensible markup language format file into a freemarker file;

a generating module for generating a freemarker template based on the freemarker file;

and the output module is used for outputting the freemarker template into a word file.

9. A computer device comprising a memory and a processor, the memory having stored therein computer readable instructions which, when executed by the processor, cause the processor to carry out the steps of the method of generating a word file based on an extensible markup language file according to any of claims 1 to 7.

10. A storage medium storing computer readable instructions which, when executed by one or more processors, cause the one or more processors to perform the steps of the method of generating a word file based on an extensible markup language file according to any one of claims 1 to 7.

Technical Field

The invention relates to the field of document format processing, in particular to a method and a device for generating a word file based on an extensible markup language file and computer equipment.

Background

With the development of informatization, many business systems now have a requirement for WORD template output in a certain format, and instead of simple WORD content output, WORD documents need to be generated according to a certain standard format to be suitable for specific environments, for example: papers, documents; business process approval forms of the enterprise industry and the like. The word software has no open source all the time, so that the development of the word software by java is extremely difficult. Few third-party plug-ins developed for word software through java can be supported, the functions are single, and only basic word file editing can be supported. Moreover, the third-party plugins are simple in support of word styles, a large amount of api and parameters are needed, a large amount of time is consumed for learning and testing by java development of the words, compatibility is poor, each version of the words needs to use a single corresponding generation method, and excle software is in the same condition.

For generating a word file by data driving, most solutions are realized by using an Apache POI, the word file is generated by using character string occupation, a fixed format, a fixed style, a fixed placeholder, a fixed line number and a fixed page number are required, the word file is very inflexible, the fixed simple data is feasible, but the data format is dynamic, the realization is difficult, corresponding templates are written in advance for different data formats, more templates are required to be maintained for complex service scenes, once one data field is changed or the style or the format is changed, all the templates are required to be modified, and the maintenance cost is high.

Disclosure of Invention

Based on this, it is necessary to provide a method, an apparatus, and a computer device for generating a word file based on an xml file, for the problems that when the word file is generated, a corresponding template needs to be written in advance for a dynamic data format, more templates need to be maintained for a complex service scenario, and once one of the data fields is changed or a style or a format is changed, all the templates also need to be modified, and the maintenance cost is relatively high.

A method for generating a word file based on an extensible markup language file comprises the following steps:

creating a word style template;

converting the word style template into an extensible markup language format file;

converting the extensible markup language format file into a freemarker file;

generating a freemarker template based on the freemarker file;

and outputting the freemarker template as a word file.

In one embodiment, the creating a word style template includes:

setting placeholders and establishing an association relation between the placeholders and data aiming at the word initialization template, editing the word initialization template in a mode of directly filling the placeholders, completing the setting of the template, and obtaining the word style template.

In one embodiment, the creating a word style template includes:

setting a placeholder for marking the position of corresponding data in the word template;

establishing an incidence relation table matched with the placeholder; the incidence relation table is used for storing incidence relations between the placeholders and the corresponding data;

setting a word template according to user requirements, setting placeholders at corresponding positions in the word template, and completing creation of the personalized word template;

acquiring the personalized word template, analyzing the word template content by utilizing the POI to the read-write performance of the word file, and identifying a paragraph part and a table part in the template;

and according to different areas, carrying out distinguishing treatment on each placeholder in the areas.

In one embodiment, the distinguishing, according to the different areas, the processing of the placeholders in the area includes:

if the paragraph part is processed, identifying the placeholder of the paragraph part according to the placeholder label, and calling a corresponding data from the database to directly replace the placeholder according to the incidence relation between the placeholder and the corresponding data by inquiring the incidence relation table of the universal placeholder;

and if the form part is processed, identifying the placeholder of the form part according to the placeholder label, and forming different data displays according to the placeholder types distributed in each cell by using the row unit to obtain the word style template.

In one embodiment, the identifying the form part placeholder according to the placeholder tag, and forming different data displays according to the placeholder types distributed in each cell by using a row unit to obtain a word style template includes:

if all the cells are common placeholders, calling a unique datum from the database to directly replace the common placeholder according to the incidence relation between the placeholder and the corresponding datum by inquiring the incidence relation table of the common placeholder;

if all the cells are the group placeholders, sequentially outputting a matched group of data in a row-by-row cycle manner according to the incidence relation between the characters and the corresponding group of corresponding data by inquiring the incidence relation table of the universal placeholder according to the setting format of the placeholder in each cell;

if the data storage device contains both the common placeholder and the group placeholder, the group placeholder sequentially outputs a matched group of data in a row cycle manner according to the incidence relation between the placeholder and the corresponding data; the general placeholders are used for outputting data according to the circulation times of the group of placeholders, and the corresponding unique data are repeated according to the row circulation in sequence.

In one embodiment, the converting the word style template into an xml format file includes:

extracting a format object from the word style template; wherein, the objects with different formats have different object format information;

dividing the word style template into at least one level of file blocks according to the format information of the format object;

and converting the divided file blocks of at least one level into extensible markup language format files according to the label information corresponding to each file block and a preset extensible markup language format library.

In one embodiment, the converting the word style template into an xml format file includes:

converting the content part in the word style template into a first extensible markup language file with a preset format standard through a word structuring engine;

extracting a format file in the word style template;

and appending the format file to the first extensible markup language file to generate a second extensible markup language file.

An apparatus for generating a word file based on an extensible markup language file, comprising:

the creating module is used for creating a word style template;

the first conversion module is used for converting the word style template into an extensible markup language format file;

the second conversion module is used for converting the extensible markup language format file into a freemarker file;

a generating module for generating a freemarker template based on the freemarker file;

and the output module is used for outputting the freemarker template into a word file.

A computer device comprising a memory and a processor, the memory having stored therein computer readable instructions which, when executed by the processor, cause the processor to perform the steps of any of the above methods of generating a word file based on an extensible markup language file.

A storage medium storing computer readable instructions which, when executed by one or more processors, cause the one or more processors to perform the steps of any one of the above methods of generating a word file based on an extensible markup language file.

According to the method, the device and the equipment for generating the word file based on the extensible markup language file, the word pattern template is created, the word pattern template is converted into the extensible markup language format file, the extensible markup language format file is converted into the freemarker file, the freemarker template is generated based on the freemarker file, and the freemarker template is output as the word file, so that the word is not difficult to support any more, the word can be completely driven by data, personalized display and dynamic display can be realized, the word generation is not fixed by the template, the word file required by a service scene can be generated by one template according to different data formats, the word file can be generated by a user according to own idea, the word file is not bound on a certain template generated in advance, the operation of generating the word file is more convenient, and the maintenance cost is reduced.

Drawings

FIG. 1 is a diagram of an implementation environment of a method for generating a word file based on an extensible markup language file, provided in an embodiment;

FIG. 2 is a block diagram showing an internal configuration of a computer device according to an embodiment;

FIG. 3 is a flow diagram of a method for generating a word file based on an extensible markup language file in one embodiment;

FIG. 4 is a flow diagram of creating a word style template in one embodiment;

FIG. 5 is a flow diagram that illustrates identifying form portion placeholders based on placeholder tags, in one embodiment;

FIG. 6 is a flow diagram that illustrates the conversion of a word style template into an extensible markup language formatted file, under an embodiment;

FIG. 7 is a block diagram of an apparatus for generating a word file based on an extensible markup language file in an embodiment;

FIG. 8 is a block diagram of the structure of a create module in one embodiment;

FIG. 9 is a block diagram showing the configuration of a computer device according to one embodiment;

FIG. 10 is a diagram of a storage medium having computer-readable instructions stored therein according to one embodiment.

Detailed Description

In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

It will be understood that the terms "first," "second," "third," and the like are used merely to distinguish one description from another, and are not intended to indicate or imply relative importance. It will also be understood that, although the terms first, second, third, etc. may be used herein to describe various elements in some of the embodiments of the application, these elements should not be limited by these terms. These terms are only used to distinguish one element from another.

Fig. 1 is a diagram of an implementation environment of a method for generating a word file based on an extensible markup language file in an embodiment, as shown in fig. 1, in the implementation environment, a computer device 110 is included, and the computer device 110 may be used to implement the method for generating a word file based on an extensible markup language file in this embodiment. It should be noted that the computer device 110 may be, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, and the like.

FIG. 2 is a diagram showing an internal configuration of a computer device according to an embodiment. As shown in fig. 2, the computer device includes a processor, a storage medium, a memory, and a network interface connected through a system bus. The non-volatile storage medium of the computer device stores an operating system, a database and computer readable instructions, the database can store control information sequences, and the computer readable instructions can enable a processor to realize a method for generating a word file based on an extensible markup language file when being executed by the processor. The processor of the computer device is used for providing calculation and control capability and supporting the operation of the whole computer device. The memory of the computer device may have stored therein computer readable instructions that, when executed by the processor, may cause the processor to perform a method of generating a word file based on an extensible markup language file. The network interface of the computer device is used for connecting and communicating with the terminal. Those skilled in the art will appreciate that the architecture shown in fig. 2 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.

As shown in fig. 3, in an embodiment, a method for generating a word file based on an extensible markup language file is provided, where the method for generating a word file based on an extensible markup language file may specifically include the following steps:

and S10, creating a word style template.

The word style template is used for describing information such as a frame, a style and the like of a word document. The content of the word style template may include a format object and object format information corresponding to the format object. The format object of the word style template may include at least one of a text object, a table object, a picture object, a formula object, and the like. The object format information corresponding to the text object may be referred to as text object format information. The object format information corresponding to the table object may be referred to as table object format information. The object format information corresponding to the picture object may be referred to as image object format information. The object format information corresponding to the formula object may be referred to as formula object format information.

For example, in order to ensure the correctness of the table object format information, a table format adding function can be newly added in the template making toolbar, and a table format extension attribute is added to the table, so that the table object format information can be added in the word style template.

In order to avoid the loss of the text object format information, the formula object format information, the picture object format information or the form object format information, default text object format information, formula object format information, picture object format information and form object format information can be preset in the word style template. For example, if text object format information is not particularly set when creating a word style template, default text object format information is called when creating the word style template.

In certain embodiments, step S10 includes: setting a placeholder and establishing an association relation between the placeholder and data aiming at the word initialization template, editing the word initialization template in a mode of directly filling the placeholder, finishing the setting of the template and obtaining a word style template.

Referring to fig. 4, in some embodiments, step S10 further includes the steps of:

step S101: and setting a placeholder for marking the position of the corresponding data in the word template. In the word template, a marker is respectively arranged at the front and the back of each placeholder.

For example, a mark may be placed before and after the placeholder, i.e., in the form of an "x placeholder". The placeholders include generic placeholders and custom placeholders.

The universal placeholder is a preset placeholder with universal properties, the custom placeholder is a placeholder which is subsequently defined by a user according to requirements, and the custom placeholder only comprises a common placeholder.

The generic placeholders include general placeholders and group placeholders; where each generic placeholder uniquely points to corresponding data. For example, examples of generic placeholders are: phoneNUMBER, provice, villagename, EMAILADDRESS, receiverNAME, housnestrur, and the like.

When a general placeholder is used in the word template, the placeholder is replaced by the matched corresponding data in the final generated file; each GROUP placeholder is preceded by a "GROUP" as a marker, and uniquely points to a GROUP of corresponding data, for example, can uniquely point to an array; for example, examples of group placeholders are: GROUP _ NUMBER, _ GROUP _ CODESET, _ GROUP _ family, _ GROUP _ membergroup, _ GROUP _ team, etc.

When a group placeholder is used in a word template, it will be cyclically replaced in the final generated file by a corresponding set of data.

Step S102: establishing an incidence relation table matched with the placeholder; the incidence relation table is used for storing incidence relations between the placeholders and the corresponding data so as to accurately display the data at the matched positions in the final file generation process. The association table may be, for example, a dictionary data table.

Step S103: and setting a word template according to user requirements, setting placeholders at corresponding positions in the word template, and completing creation of the personalized word template.

Step S104: acquiring a personalized word template created by a user, analyzing the word template content by utilizing the read-write performance of the POI to the word file, and identifying a paragraph part and a table part in the template; according to different areas, carrying out distinguishing processing on each placeholder in the areas; if the processing is directed to the paragraph part, go to step S105; if the processing is for the table portion, the process goes to step S106.

Poi (point underfuscitation implementation) is an open-source cross-platform application program interface written in Java language, and Java programs can read and write Microsoft Office format documents through the application program interface provided by poi (point underfuscitation implementation).

Step S105: and identifying the placeholder of the paragraph part according to the placeholder label, and calling a corresponding data from the database to directly replace the placeholder according to the association relationship between the placeholder and the corresponding data by inquiring the association relationship table of the universal placeholder.

General placeholders and group placeholders for the paragraph sections are identified from the placeholder tags.

For the general placeholder, a unique data is called from the database to directly replace the general placeholder according to the incidence relation between the placeholder and the corresponding data by inquiring the incidence relation table of the general placeholder.

And for the group placeholder, according to the format set by the current character, including font type, font color, cell filling, cell shading and the like, by inquiring the association relation table of the universal placeholder and according to the association relation between the character and the corresponding group of corresponding data, the corresponding data is circularly output downwards from the current character position.

In some embodiments, custom placeholder processing for paragraph sections is handled in the same manner as generic placeholders for paragraph sections.

Step S106: identifying form part placeholders according to the placeholder labels; and forming different data displays according to the placeholder types distributed in each cell by using the row unit to obtain the word style template.

Referring to fig. 5, step S106 may include the steps of:

s1061, if all the cells are general placeholders, calling a unique datum from the database to directly replace the general placeholder according to the incidence relation between the placeholder and the corresponding datum by inquiring the incidence relation table of the general placeholder;

s1062, if all the cells are the group placeholders, sequentially outputting a matched group of data in a row-by-row cycle manner according to the association relationship between the characters and the corresponding group of corresponding data by inquiring the association relationship table of the universal placeholder according to the setting format of the placeholder in each cell, including the font type, the font type and the font color;

s1063, if the data contains both the common placeholders and the group placeholders, sequentially outputting a matched group of data in a row cycle manner according to the association relationship between the placeholders and the corresponding data by the group placeholders; typically, placeholders repeat the corresponding unique data in a row loop, as many times as the group placeholder loops output data.

And S20, converting the word style template into an extensible markup language format file.

The XML is a subset of standard generalized markup languages, abbreviated as XML, and is a markup language for marking electronic documents to be structured.

Referring to fig. 6, in certain embodiments, S20 includes:

s201, extracting a format object from a word style template; wherein, the objects with different formats have different object format information. The word style template may include at least one of a text object, a table object, a picture object, a formula object, and the like.

In the above step S201, different format objects in the word style template have different object format information therebetween.

Text object format information may include word position, word spacing, paragraph format, word color, word font, font type, word size, and the like.

The picture object format information may include a picture position, a picture format, a picture size, a picture color, a picture shape, and the like.

The table object format information may include a table position, a table row number, a table column number, and an object in each cell, the objects in the cell may also include objects such as a text object, a formula object, and a picture object, and the objects in the cell also have corresponding format information. For example, if the object in a cell is a text object, the text object in the cell also has formatting information such as the text object's text position, word spacing, word color, word font, font type, and font size. If the object in the cell is a picture object, the picture object in the cell may also have format information such as picture position, picture format, picture size, picture color, and picture shape.

The formula object format information may include formula location, formula content, formula size, formula format, and the like.

If the format object in the cell is a formula object, the formula object in the cell also has the formula position, the formula content, the formula size, the formula format and other format information of the formula object.

S202, dividing the word style template into at least one level of file blocks according to the format information of the format object; wherein the file block attributes of a plurality of the file blocks at the same level are different.

In the above step S202, the word style template is divided into text object blocks, picture object blocks, table object blocks, and formula object blocks according to the text object, the picture object, the table object, and the formula object.

In some embodiments, the text object block may be further divided, for example, into a summary part file block, a body part file block, and a reference part file block; furthermore, the abstract part file block can be divided into a title, an abstract, an author, a unit, a keyword and other parts, the text part file block can be divided into chapters and paragraphs, the reference part file block can be subdivided into each reference citation mark number and a reference name language, and each reference can be further fragmented.

S203, converting the divided file blocks of at least one level into extensible markup language format files according to the label information corresponding to each file block and a preset extensible markup language format library.

In step S203, an xml format library including file block tag information and xml is stored in advance.

And for each divided file block, searching matched extensible markup language from an extensible markup language format library according to the label information carried by the file block, storing the file block through the searched extensible markup language, and converting the divided file block into an extensible markup language format file when the storage of all the file blocks is finished.

In certain embodiments, S20 includes:

1) and converting the content part in the word style template into a first extensible markup language file with a preset format standard through a word structuring engine.

Specifically, taking a word file in a paper format as an example, a word structuring engine may be used to convert a paper content part in the word file into a first extensible markup language file meeting a preset standard.

2) And extracting a format file in the word style template.

The format file in the word style template comprises a format object and corresponding object format information. According to an embodiment of the present invention, the format object in the word style template may include: at least one of a text object, a picture object, a table object, and a formula object. Each picture object has unique corresponding picture object format information, each table object has unique corresponding table object format information, and each formula object has unique corresponding formula object format information.

Specifically, a layout.

3) And appending the format file to the first extensible markup language file to generate a second extensible markup language file.

And particularly, appending the layout of the extensible markup language file in the extracted word file to the first extensible markup language file to generate a second extensible markup language file. For example, export an extensible markup language file into the custom extensible markup language folder of a word file.

In an embodiment of the present invention, the appending of the format file to the first xml file, and the step of generating the second xml file may specifically include: and establishing a matching relation between at least one picture object, at least one table object and at least one formula object and corresponding format information. For example, each picture object, table object and formula object is labeled with a unique identifier, and an index for the identifier is added to the format information of the corresponding object.

And supplementing the format information to the first extensible markup language file according to the matching relation, reading an assembly rule of paper assembly metadata, generating a paper reference format, a paper number and a DOI (Digital Object Identifier, DOI for short) according to the assembly rule, and supplementing the paper reference format, the paper number and the DOI to the first extensible markup language file to generate a second extensible markup language file.

The composition file may include, for example, non-article information including data of a header area and a brow area of a paper and content static decoration data.

S30, converting the file in the extensible markup language format into a freemarker file.

The extensible markup language format file is format converted using a format conversion tool in the toolkit to generate a freemarker file, i.e., to generate text in ftl format. Freemaker is a template engine, a generic tool for generating output text based on templates and data to be changed, which is not end-user oriented, but a Java class library, a component that programmers can embed into the products they develop. The toolkit may employ a JAR package. The JAR File is called Java Archive File in its entirety, meaning Java Archive File. The JAR file is a compressed file, compatible with common ZIP compressed files, and therefore also referred to as JAR package.

The principle of freemaker is that the template + data model is output, and the template is only responsible for the representation of data in the page, and does not involve any logic code, and all logic is processed by the data model. Thus, freemaker is able to completely separate the presentation layer and the business logic. The output that the user finally sees is created after the template and the data model are merged. Therefore, the use of freemarker overcomes the following technical drawbacks in the prior art: a large number of business logic codes exist in a page in the JSP development process, so that the content of the page is messy, and later modification and maintenance are difficult.

In addition, according to the development experience of the prior art, JSP pages are used for showing data in the development process. The JSP needs to be converted into Servlet class when being executed for the first time, when the function is adjusted in the development stage, the JSP needs to be frequently modified, compiling and converting are needed to be carried out every time, and much time is wasted in program compiling. Compared with JSP, freemarker template technology has no problem of compiling and converting, so that the problem of wasting time does not exist. So Freemarker can greatly improve the development efficiency.

The Freemarker enables the division of labor in the development process to be more clear, and as an interface developer, only the HTML file, the image and other visual aspects of the Web page need to be created with great concentration, and the data do not need to be collected; and program developers are concentrated on system implementation and are responsible for preparing data to be displayed for pages, so that the working efficiency is improved.

And classifying the freemarker file by using a classification tool in the tool kit to obtain the classified freemarker file. Specifically, the classification tool classifies according to the content in the freemarker file, so as to obtain the classified freemarker file. The classifying tool classifies the freemarker files according to a preset sequence, wherein the preset sequence can be a priority level sequence of the freemarker files or a time sequence corresponding to the generation time of the freemarker files.

S40, generating a freemarker template based on the freemarker file.

The freemarker file is formatted using formatting tools in the toolkit to generate a freemarker template. The Freemarker file will associate the pre-written key values with the incoming data and determine which pattern and how modules different data in the same data format should be presented using. The freemarker file is formatted to obtain a freemarker template, namely the manufactured freemarker template, and the freemarker template can be repeatedly used for many times. Through setting the key value, the setting of the format information can be conveniently realized.

And S50, outputting the freemarker template as a word file.

And converting the freemarker template into a word file in doc format through the self-contained function of the Windows system and outputting the word file. The Windows system is provided with a conversion tool, and can realize the function of converting a freemarker template into a word file in doc format.

By the method for generating the word file based on the extensible markup language file, the word is not supported easily any more, the word can be completely driven by data as a front end, personalized display and dynamic display can be realized, the word generation is not fixed by templates, a template can generate files required by service scenes according to different data formats, a client user can also generate the word according to own ideas, which color and style are liked by the user, which typesetting can be realized according to own wishes, and the user does not need to be bound on a certain template generated in advance, no matter how complex data can be realized through a preset key value, so that the operation of generating the word file is more convenient, the maintenance cost is reduced, and the following defects in the prior art are overcome: when a word file is generated, corresponding templates need to be written in advance according to a dynamic data format, more templates need to be maintained for a complex service scene, once one data field is changed or a style or a format is changed, all the templates also need to be modified, and the maintenance cost is higher.

Referring to fig. 7, in one embodiment, an apparatus for generating a word file based on an xml file is provided, including:

the creating module is used for creating a word style template;

the first conversion module is used for converting the word style template into an extensible markup language format file;

the second conversion module is used for converting the extensible markup language format file into a freemarker file;

a generating module for generating a freemarker template based on the freemarker file;

and the output module is used for outputting the freemarker template into a word file.

In some embodiments, the creation module is specifically configured to:

setting placeholders and establishing an association relation between the placeholders and data aiming at the word initialization template, editing the word initialization template in a mode of directly filling the placeholders, completing the setting of the template, and obtaining the word style template.

Referring to FIG. 8, in some embodiments, the creation module includes:

the first setting unit is used for setting a placeholder and marking the position of the corresponding data in the word template;

the establishing unit is used for establishing an incidence relation table matched with the placeholder; the incidence relation table is used for storing incidence relations between the placeholders and the corresponding data;

the second setting unit is used for setting a word template according to the user requirements, setting placeholders at corresponding positions in the word template, and completing creation of the personalized word template;

the acquisition unit is used for acquiring the personalized word template, analyzing the word template content by utilizing the read-write performance of the POI to the word file and identifying a paragraph part and a table part in the template;

and the processing unit is used for distinguishing and processing the placeholders in the areas according to the difference of the areas.

In some embodiments, the processing unit comprises:

the first sub-processing unit is used for identifying a placeholder of the paragraph part according to the placeholder label if the paragraph part is processed, and calling a corresponding data from the database to directly replace the placeholder according to the association relationship between the placeholder and the corresponding data by inquiring the association relationship table of the general placeholder;

and the second sub-processing unit is used for identifying the placeholders of the table part according to the placeholder labels if the table part is processed, forming different data displays according to the placeholder types distributed in each cell by using a row unit, and obtaining the word style template.

In some embodiments, the identifying the form part placeholder according to the placeholder tag, and forming different data displays according to the type of the placeholder distributed in each cell in a row unit to obtain the word style template includes:

if all the cells are common placeholders, calling a unique datum from the database to directly replace the common placeholder according to the incidence relation between the placeholder and the corresponding datum by inquiring the incidence relation table of the common placeholder;

if all the cells are the group placeholders, sequentially outputting a matched group of data in a row-by-row cycle manner according to the incidence relation between the characters and the corresponding group of corresponding data by inquiring the incidence relation table of the universal placeholder according to the setting format of the placeholder in each cell;

if the data storage device contains both the common placeholder and the group placeholder, the group placeholder sequentially outputs a matched group of data in a row cycle manner according to the incidence relation between the placeholder and the corresponding data; the general placeholders are used for outputting data according to the circulation times of the group of placeholders, and the corresponding unique data are repeated according to the row circulation in sequence.

In some embodiments, the first conversion module comprises:

the extracting unit is used for extracting a format object from the word style template; wherein, the objects with different formats have different object format information;

the dividing unit is used for dividing the word style template into at least one level of file blocks according to the format information of the format object;

and the conversion unit is used for converting the divided file blocks of at least one level into the extensible markup language format file according to the label information corresponding to each file block and a preset extensible markup language format library.

In certain embodiments, the first conversion module comprises:

the conversion submodule is used for converting the content part in the word style template into a first extensible markup language file with a preset format standard through a word structuring engine;

the extraction submodule is used for extracting the format file in the word style template;

and the supplement submodule is used for supplementing the format file to the first extensible markup language file and generating a second extensible markup language file.

In one embodiment, a computer device is proposed, the computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:

creating a word style template;

converting the word style template into an extensible markup language format file;

converting the extensible markup language format file into a freemarker file;

generating a freemarker template based on the freemarker file;

and outputting the freemarker template as a word file.

In one embodiment, the step performed by the processor of creating a word style template comprises: setting placeholders and establishing an association relation between the placeholders and data aiming at the word initialization template, editing the word initialization template in a mode of directly filling the placeholders, completing the setting of the template, and obtaining the word style template.

In one embodiment, the creating a word style template executed by the processor comprises:

setting a placeholder for marking the position of corresponding data in the word template;

establishing an incidence relation table matched with the placeholder; the incidence relation table is used for storing incidence relations between the placeholders and the corresponding data;

setting a word template according to user requirements, setting placeholders at corresponding positions in the word template, and completing creation of the personalized word template;

acquiring the personalized word template, analyzing the word template content by utilizing the POI to the read-write performance of the word file, and identifying a paragraph part and a table part in the template;

and according to different areas, carrying out distinguishing treatment on each placeholder in the areas.

In one embodiment, the distinguishing, according to the area, of the placeholders in the area performed by the processor includes:

if the paragraph part is processed, identifying the placeholder of the paragraph part according to the placeholder label, and calling a corresponding data from the database to directly replace the placeholder according to the incidence relation between the placeholder and the corresponding data by inquiring the incidence relation table of the universal placeholder;

and if the form part is processed, identifying the placeholder of the form part according to the placeholder label, and forming different data displays according to the placeholder types distributed in each cell by using the row unit to obtain the word style template.

In an embodiment, the identifying, performed by the processor, the form part placeholder according to the placeholder tag, and forming different data displays according to the placeholder types distributed in each cell in a row unit to obtain the word style template includes:

if all the cells are common placeholders, calling a unique datum from the database to directly replace the common placeholder according to the incidence relation between the placeholder and the corresponding datum by inquiring the incidence relation table of the common placeholder;

if all the cells are the group placeholders, sequentially outputting a matched group of data in a row-by-row cycle manner according to the incidence relation between the characters and the corresponding group of corresponding data by inquiring the incidence relation table of the universal placeholder according to the setting format of the placeholder in each cell;

if the data storage device contains both the common placeholder and the group placeholder, the group placeholder sequentially outputs a matched group of data in a row cycle manner according to the incidence relation between the placeholder and the corresponding data; the general placeholders are used for outputting data according to the circulation times of the group of placeholders, and the corresponding unique data are repeated according to the row circulation in sequence.

In one embodiment, the converting the word style template into an extensible markup language format file performed by the processor comprises:

extracting a format object from the word style template; wherein, the objects with different formats have different object format information;

dividing the word style template into at least one level of file blocks according to the format information of the format object;

and converting the divided file blocks of at least one level into extensible markup language format files according to the label information corresponding to each file block and a preset extensible markup language format library.

In one embodiment, the converting the word style template into an extensible markup language format file performed by the processor comprises:

converting the content part in the word style template into a first extensible markup language file with a preset format standard through a word structuring engine;

extracting a format file in the word style template;

and appending the format file to the first extensible markup language file to generate a second extensible markup language file.

Referring to fig. 9, the computer device 10 according to an embodiment of the present invention may include: the system comprises a processor 100, a memory 101, a bus 102 and a communication interface 103, wherein the processor 100, the communication interface 103 and the memory 101 are connected through the bus 102; the memory 101 stores a computer program that can be executed on the processor 100, and the processor 100 executes the computer program to perform the method provided by any of the foregoing embodiments of the present application.

The Memory 101 may include a high-speed Random Access Memory (RAM), and may also include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used.

The bus 102 may be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 101 is used for storing a program, and the processor 100 executes the program after receiving an execution instruction, and the method disclosed in any of the foregoing embodiments of the present application may be applied to the processor 100, or implemented by the processor 100.

Processor 100 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 100. The Processor 100 may be a general-purpose Processor, and may include a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101 and completes the steps of the method in combination with the hardware.

The computer device provided by the embodiment of the application and the method provided by the embodiment of the application have the same inventive concept and the same beneficial effects as the method adopted, operated or realized by the computer device.

In one embodiment, a storage medium is provided that stores computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of:

creating a word style template;

converting the word style template into an extensible markup language format file;

converting the extensible markup language format file into a freemarker file;

generating a freemarker template based on the freemarker file;

and outputting the freemarker template as a word file.

In one embodiment, the creating a word style template performed by the one or more processors comprises: setting placeholders and establishing an association relation between the placeholders and data aiming at the word initialization template, editing the word initialization template in a mode of directly filling the placeholders, completing the setting of the template, and obtaining the word style template.

In one embodiment, the creating a word style template executed by the one or more processors comprises:

setting a placeholder for marking the position of corresponding data in the word template;

establishing an incidence relation table matched with the placeholder; the incidence relation table is used for storing incidence relations between the placeholders and the corresponding data;

setting a word template according to user requirements, setting placeholders at corresponding positions in the word template, and completing creation of the personalized word template;

acquiring the personalized word template, analyzing the word template content by utilizing the POI to the read-write performance of the word file, and identifying a paragraph part and a table part in the template;

and according to different areas, carrying out distinguishing treatment on each placeholder in the areas.

In one embodiment, the distinguishing of placeholders in a region by region performed by the one or more processors comprises:

if the paragraph part is processed, identifying the placeholder of the paragraph part according to the placeholder label, and calling a corresponding data from the database to directly replace the placeholder according to the incidence relation between the placeholder and the corresponding data by inquiring the incidence relation table of the universal placeholder;

and if the form part is processed, identifying the placeholder of the form part according to the placeholder label, and forming different data displays according to the placeholder types distributed in each cell by using the row unit to obtain the word style template.

In one embodiment, the identifying, performed by the one or more processors, the form part placeholder according to the placeholder tag, and forming different data displays according to the placeholder types distributed in each cell in a row unit to obtain a word style template includes:

if all the cells are common placeholders, calling a unique datum from the database to directly replace the common placeholder according to the incidence relation between the placeholder and the corresponding datum by inquiring the incidence relation table of the common placeholder;

if all the cells are the group placeholders, sequentially outputting a matched group of data in a row-by-row cycle manner according to the incidence relation between the characters and the corresponding group of corresponding data by inquiring the incidence relation table of the universal placeholder according to the setting format of the placeholder in each cell;

if the data storage device contains both the common placeholder and the group placeholder, the group placeholder sequentially outputs a matched group of data in a row cycle manner according to the incidence relation between the placeholder and the corresponding data; the general placeholders are used for outputting data according to the circulation times of the group of placeholders, and the corresponding unique data are repeated according to the row circulation in sequence.

In one embodiment, the converting the word style template into an extensible markup language format file performed by the one or more processors comprises:

extracting a format object from the word style template; wherein, the objects with different formats have different object format information;

dividing the word style template into at least one level of file blocks according to the format information of the format object;

and converting the divided file blocks of at least one level into extensible markup language format files according to the label information corresponding to each file block and a preset extensible markup language format library.

In one embodiment, the converting the word style template into an extensible markup language format file performed by the one or more processors comprises:

converting the content part in the word style template into a first extensible markup language file with a preset format standard through a word structuring engine;

extracting a format file in the word style template;

and appending the format file to the first extensible markup language file to generate a second extensible markup language file.

It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the computer program is executed. Referring to fig. 10, a storage medium is shown as an optical disc 20, on which a computer program (i.e. a program product) is stored, which when executed by a processor, performs the method provided by any of the foregoing embodiments.

It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory, or other optical and magnetic storage media, which are not described in detail herein.

The storage medium provided by the above embodiment of the present application and the method provided by the embodiment of the present application have the same beneficial effects as the method adopted, operated or implemented by the application program stored in the storage medium.

The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.

The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

23页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种正则表达式转换方法、装置、设备及存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!