Method, device, equipment and medium for generating Word document by Java application

文档序号:8246 发布日期:2021-09-17 浏览:49次 中文

1. A method for generating Word documents by Java application is characterized in that the method is suitable for the Java application, and a Freemarker framework is integrated in the Java application, and the method comprises the following steps:

acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data;

acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed;

dividing the placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set;

acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set;

acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set;

and based on the Freemarker framework, generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set to obtain a target Word document.

2. The method for generating Word document by using Java application according to claim 1, wherein the step of obtaining the Word document generation request is preceded by the steps of:

acquiring a template generation request;

responding to the template generation request, and acquiring a Freemarker template identifier to be added, Word frame data to be added, Word style data to be added, a placeholder set to be added and a template object position data set to be processed, wherein the Word frame data to be added is Word frame data obtained based on Html, and the Word style data to be added is Word style data obtained based on CSS;

generating a static page according to the Freemarker template to be added, the Word frame data to be added, the Word style data to be added, the placeholder set to be added and the template object position data set to be processed to obtain a static page to be converted;

performing flt file format conversion on the static page to be converted to obtain a Freemarker template to be stored;

and updating the Freemarker template library according to the Freemarker template to be stored.

3. The method for generating Word document by using Java application according to claim 1, wherein the step of obtaining the picture database comprises:

obtaining a diagram placeholder from the non-plain text placeholder set to obtain a diagram placeholder set;

according to the service database, sequentially generating graphs and converting pictures for each graph placeholder in the graph placeholder set respectively to obtain a picture set to be stored;

and acquiring the picture database, and updating the picture database according to the picture set to be stored.

4. The method for generating Word documents by using Java applications according to claim 1, wherein the step of generating Word documents based on the FreeMarker framework according to the picture database, the target FreeMarker template identifier set, the target location configuration data, the first KV data pair set, and the second KV data pair set to obtain target Word documents includes:

acquiring a Freemarker template library based on the Freemarker framework, and constructing a document framework according to the Freemarker template library, the target Freemarker template identification set and the target position configuration data to obtain a flt file to be replaced;

and based on the Freemarker framework, generating a Word document according to the flt file to be replaced, the picture database, the first KV data pair set and the second KV data pair set to obtain the target Word document.

5. The method for generating Word documents by using Java applications according to claim 4, wherein the step of generating Word documents by using the Freemarker framework according to the flt file to be replaced, the picture database, the first KV data pair set and the second KV data pair set to obtain the target Word documents comprises:

on the basis of the Freemarker frame, replacing the placeholder in the flt file to be replaced according to the picture database, the first KV data pair set and the second KV data pair set to obtain a flt file to be converted;

and performing Word document format conversion on the flt file to be converted based on the Freemarker frame to obtain the target Word document.

6. The method for generating Word document by using Java application according to claim 1, wherein a Word-to-PDF plug-in is integrated in the Java application, and the Word-to-PDF plug-in is a plug-in obtained based on OpenOffice;

after the step of generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set based on the Freemarker frame to obtain a target Word document, the method further includes:

acquiring a PDF conversion request;

responding to the PDF conversion request, and sending the target Word document to the Word PDF conversion plug-in;

and performing PDF file format conversion on the target Word document based on the Word-to-PDF plug-in to obtain a target PDF document.

7. The method for generating Word document by using Java application according to claim 6, wherein the step of converting PDF file format of the target Word document based on the Word-to-PDF plug-in to obtain the target PDF document comprises:

acquiring a preset storage address;

adopting an Office document converter of the Word-to-PDF plug-in to convert the PDF file format of the target Word document to obtain the target PDF document;

and storing the target PDF document into a folder corresponding to the preset storage address.

8. An apparatus for generating Word documents by Java applications, the apparatus being adapted to Java applications, wherein FreeMarker framework is integrated in the Java applications, the apparatus comprising:

the device comprises a request acquisition module, a data processing module and a data processing module, wherein the request acquisition module is used for acquiring a Word document generation request which carries a target Freemarker template identification set and target position configuration data;

a to-be-processed placeholder set determining module, configured to obtain a placeholder from a template corresponding to the target Freemarker template identifier set, so as to obtain a to-be-processed placeholder set;

a placeholder dividing module for dividing the placeholders in the placeholder set to be processed according to placeholder types to obtain a plain text placeholder set and a non-plain text placeholder set;

the first KV data pair set determining module is used for acquiring a service database, and according to the service database, service data searching and KV data pair assembling are sequentially performed on each placeholder in the plain text placeholder set respectively to obtain a first KV data pair set;

the second KV data pair set determining module is used for acquiring a picture database, and sequentially performing picture identification searching and KV data pair assembling on each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set;

and the target Word document determining module is used for generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set on the basis of the Freemarker frame to obtain a target Word document.

9. A computer device comprising a memory and a processor, the memory storing a computer program, wherein the processor implements the steps of the method of any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 7.

Background

Java (object oriented programming language) applications developed using Java technology are widely used, so that there is an increasing need to generate Word documents from web pages opened by Java applications. Since Microsoft does not have an interface for openly reading and writing a document in Microsoft Office (Office software suite) format to Java, an Apache poi (open source code function library of Apache software foundation) is traditionally adopted to generate a Word (Office software) document according to a webpage opened by Java application, but the method only supports generation of a simple Word document, when the Word document to be generated is relatively complex, a large amount of encoding and debugging styles are needed due to inclusion of various types of charts and pictures, and when the styles are relatively complex, the styles meeting requirements are difficult to debug.

Disclosure of Invention

The method, the device, the equipment and the medium for generating the Word document by the Java application aim at solving the technical problems that the Apache POI is adopted to generate the Word document according to the webpage opened by the Java application, a large amount of coding and debugging styles are needed for comparing the complicated Word document, and the debugging styles are difficult in the prior art.

In order to achieve the above object, the present application provides a method for generating a Word document by a Java application, the method is suitable for a Java application, and a freemaker framework is integrated in the Java application, and the method includes:

acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data;

acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed;

dividing the placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set;

acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set;

acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set;

and based on the Freemarker framework, generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set to obtain a target Word document.

Further, before the step of obtaining the Word document generation request, the method includes:

acquiring a template generation request;

responding to the template generation request, and acquiring a Freemarker template identifier to be added, Word frame data to be added, Word style data to be added, a placeholder set to be added and a template object position data set to be processed, wherein the Word frame data to be added is Word frame data obtained based on Html, and the Word style data to be added is Word style data obtained based on CSS;

generating a static page according to the Freemarker template to be added, the Word frame data to be added, the Word style data to be added, the placeholder set to be added and the template object position data set to be processed to obtain a static page to be converted;

performing flt file format conversion on the static page to be converted to obtain a Freemarker template to be stored;

and updating the Freemarker template library according to the Freemarker template to be stored.

Further, the step of obtaining the picture database includes:

obtaining a diagram placeholder from the non-plain text placeholder set to obtain a diagram placeholder set;

according to the service database, sequentially generating graphs and converting pictures for each graph placeholder in the graph placeholder set respectively to obtain a picture set to be stored;

and acquiring the picture database, and updating the picture database according to the picture set to be stored.

Further, the step of generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set based on the Freemarker frame to obtain a target Word document includes:

acquiring a Freemarker template library based on the Freemarker framework, and constructing a document framework according to the Freemarker template library, the target Freemarker template identification set and the target position configuration data to obtain a flt file to be replaced;

and based on the Freemarker framework, generating a Word document according to the flt file to be replaced, the picture database, the first KV data pair set and the second KV data pair set to obtain the target Word document.

Further, the step of generating a Word document according to the flt file to be replaced, the picture database, the first KV data pair set, and the second KV data pair set based on the FreeMarker frame to obtain the target Word document includes:

on the basis of the Freemarker frame, replacing the placeholder in the flt file to be replaced according to the picture database, the first KV data pair set and the second KV data pair set to obtain a flt file to be converted;

and performing Word document format conversion on the flt file to be converted based on the Freemarker frame to obtain the target Word document.

Furthermore, a Word-to-PDF plug-in is integrated in the Java application, wherein the Word-to-PDF plug-in is obtained based on OpenOffice;

after the step of generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set based on the Freemarker frame to obtain a target Word document, the method further includes:

acquiring a PDF conversion request;

responding to the PDF conversion request, and sending the target Word document to the Word PDF conversion plug-in;

and performing PDF file format conversion on the target Word document based on the Word-to-PDF plug-in to obtain a target PDF document.

Further, the step of performing PDF file format conversion on the target Word document based on the Word-to-PDF plug-in to obtain a target PDF document includes:

acquiring a preset storage address;

adopting an Office document converter of the Word-to-PDF plug-in to convert the PDF file format of the target Word document to obtain the target PDF document;

and storing the target PDF document into a folder corresponding to the preset storage address.

This application has still provided a Java application generates Word document device, the device is applicable to Java application, integrated Freemarker frame in the Java application, the device includes:

the device comprises a request acquisition module, a data processing module and a data processing module, wherein the request acquisition module is used for acquiring a Word document generation request which carries a target Freemarker template identification set and target position configuration data;

a to-be-processed placeholder set determining module, configured to obtain a placeholder from a template corresponding to the target Freemarker template identifier set, so as to obtain a to-be-processed placeholder set;

a placeholder dividing module for dividing the placeholders in the placeholder set to be processed according to placeholder types to obtain a plain text placeholder set and a non-plain text placeholder set;

the first KV data pair set determining module is used for acquiring a service database, and according to the service database, service data searching and KV data pair assembling are sequentially performed on each placeholder in the plain text placeholder set respectively to obtain a first KV data pair set;

the second KV data pair set determining module is used for acquiring a picture database, and sequentially performing picture identification searching and KV data pair assembling on each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set;

and the target Word document determining module is used for generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set on the basis of the Freemarker frame to obtain a target Word document.

The present application further proposes a computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the steps of any of the above methods when executing the computer program.

The present application also proposes a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the steps of the method of any of the above.

The method, the device, the equipment and the medium for generating the Word document by the Java application are suitable for the Java application, a Freemarker framework is integrated in the Java application, and the method comprises the following steps: acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data; acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed; dividing placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set; acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set; acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set; based on the FreeMarker framework, according to the picture database, the target FreeMarker template identification set, the target position configuration data, the first KV data pair set and the second KV data pair set, the target Word document is obtained, so that the Word document is generated based on the FreeMarker template and the FreeMarker framework, a large amount of coding is not needed for specific contents, the style is not needed to be adjusted for the specific contents, and the template, the service data and the picture are decoupled, so that the method can better adapt to the change of the requirement.

Drawings

FIG. 1 is a flowchart illustrating a method for generating a Word document by a Java application according to an embodiment of the present application;

FIG. 2 is a block diagram schematically illustrating the structure of an apparatus for generating Word documents by Java application according to an embodiment of the present application;

fig. 3 is a block diagram illustrating a structure of a computer device according to an embodiment of the present application.

The implementation, functional features and advantages of the objectives of the present application will be further explained with reference to the accompanying drawings.

Detailed Description

In order to make the objects, technical solutions and advantages of the present application more apparent, the present application 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 present application and are not intended to limit the present application.

Referring to fig. 1, an embodiment of the present application provides a method for generating a Word document by a Java application, where the method is applied to the Java application, and a Freemarker framework is integrated in the Java application, and the method includes:

s1: acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data;

s2: acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed;

s3: dividing the placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set;

s4: acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set;

s5: acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set;

s6: and based on the Freemarker framework, generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set to obtain a target Word document.

The method is suitable for Java application, a Freemarker framework is integrated in the Java application, and the method comprises the following steps: acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data; acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed; dividing placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set; acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set; acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set; based on the FreeMarker framework, according to the picture database, the target FreeMarker template identification set, the target position configuration data, the first KV data pair set and the second KV data pair set, the target Word document is obtained, so that the Word document is generated based on the FreeMarker template and the FreeMarker framework, a large amount of coding is not needed for specific contents, the style is not needed to be adjusted for the specific contents, and the template, the service data and the picture are decoupled, so that the method can better adapt to the change of the requirement.

FreeMarker, a template engine, is a generic tool that is based on templates and data to be changed and used to generate output text (HTML web pages, emails, configuration files, source code, etc.).

The Java application is integrated with a Freemarker framework, so that the Java application can use a template engine of the Freemarker framework.

For S1, a Word document generation request input by the user may be obtained, a Word document generation request sent by the third-party application system may also be obtained, or a Word document generation request triggered by the application program according to a preset condition may also be obtained. For example, the preset condition is 7 o' clock per day, which is not limited in this example.

The Word document creation request is a request for creating a Word document from a web page in a Java application.

The target Freemarker template identifier set is a set of Freemarker template identifiers of Freemarker templates used for generating Word documents by the Word document generation request. The target Freemarker template identification set comprises one or more Freemarker template identifications. The Freemarker template identifier includes a template name, a template ID, and other data that uniquely identifies a Freemarker template.

The target position configuration data is position data of a Freemarker template corresponding to each Freemarker template identifier in the target Freemarker template identifier set when the Word document is generated.

The target location configuration data includes: the device comprises Freemarker template identifications and position data, wherein each Freemarker template identification corresponds to one position data.

It is to be understood that the target location configuration data may be a non-null value or a null value.

Optionally, when the target position configuration data is a null value, and the target Freemarker template identifier set includes a plurality of Freemarker template identifiers, the order of the Freemarker template identifiers in the target Freemarker template identifier set is used as position data of the Freemarker templates corresponding to each Freemarker template identifier in the target Freemarker template identifier set when a Word document is generated.

And for S2, acquiring a placeholder from each Freemarker template corresponding to the target Freemarker template identification set, and taking all acquired placeholders as a placeholder set to be processed.

For S3, the placeholder types include: plain text placeholders and non-plain text placeholders. The non-plain text placeholder includes: picture placeholders and chart placeholders.

Wherein, the position corresponding to the plain text placeholder needs to be replaced by plain text data. The position corresponding to the picture placeholder needs to be replaced by a picture. The position corresponding to the chart placeholder needs to be replaced by a table or a picture generated by the table.

Dividing the placeholders in the placeholder set to be processed according to the type of the placeholder, taking all plain text placeholders as a plain text placeholder set, and taking all non-plain text placeholders as a non-plain text placeholder set.

For S4, the service database may be obtained from the database, or may be obtained from a third-party application system.

The business database includes: service data identification and service data. The service data identification may be a service data ID for uniquely identifying one service data. The traffic data may be a value of one field and one of a plurality of fields.

KV data pair, i.e. Key-Value data format.

Optionally, one placeholder is extracted from the plain text placeholder set to serve as a first plain text placeholder to be searched; searching a preset data identifier of a first plain text placeholder to be searched in a Freemarker template corresponding to the target Freemarker template identifier set in the service database, and taking service data corresponding to the service data identifier corresponding to the preset data identifier searched in the service database as first service data to be spliced; performing KV data pair assembly according to the first plain text placeholder to be searched and the first service data to be spliced to obtain a first KV data pair to be processed corresponding to the first plain text placeholder to be searched, wherein the first plain text placeholder to be searched is used as a Key of the first KV data pair to be processed, and the first service data to be spliced is used as Value of the first KV data pair to be processed; repeatedly executing the step of extracting one placeholder from the plain text placeholder set as a first plain text placeholder to be searched until the extraction of the placeholder in the plain text placeholder set is completed; and taking all the first KV data pairs to be processed as the first KV data pair set.

Optionally, acquiring placeholder configuration data; extracting a placeholder from the plain text placeholder set to serve as a plain text placeholder to be searched for secondly; searching the plain text placeholder to be searched in the placeholder configuration data to obtain a first personalized configuration searching result; when the first personalized configuration searching result is successful, taking a configuration data identifier corresponding to a placeholder identifier of the second plain text placeholder to be searched in the placeholder configuration data as a first data identifier to be searched; when the first personalized configuration searching result is failure, taking a preset data identifier of the second plain text placeholder to be searched in a Freemarker template corresponding to the target Freemarker template identifier set as the first data identifier to be searched; searching the first to-be-searched data identifier in the service database, and taking the service data corresponding to the service data identifier searched in the service database as second to-be-spliced service data; performing KV data pair assembly according to the second plain text placeholder to be searched and the second service data to be spliced to obtain a first KV data pair to be analyzed corresponding to the second plain text placeholder to be searched, wherein the second plain text placeholder to be searched is used as a Key of the first KV data pair to be analyzed, and the second service data to be spliced is used as a Value of the first KV data pair to be analyzed; repeatedly executing the step of extracting one placeholder from the plain text placeholder set as a plain text placeholder to be searched for secondly until the extraction of the placeholder in the plain text placeholder set is completed; and taking all the first KV data pairs to be analyzed as the first KV data pair set.

The placeholder configuration data includes: the device comprises placeholder identifiers and configuration data identifiers, wherein each placeholder identifier corresponds to one configuration data identifier. The placeholder identifier may be a placeholder name, a placeholder ID, or the like, of data that uniquely identifies a placeholder. The configuration data identifier may be a service data identifier or a picture identifier. The picture identifier may be a picture name, a picture ID, or the like, which uniquely identifies one picture.

For S5, the picture database may be obtained from a database, or may be obtained from a third-party application system.

The picture database includes: the picture identification and the picture, each picture identification corresponds to one picture.

Optionally, one placeholder is extracted from the non-plain text placeholder set to serve as a first non-plain text placeholder to be searched; searching a preset data identifier of a first non-plain text placeholder to be searched in a Freemarker template corresponding to the target Freemarker template identifier set in the picture database, and taking a picture identifier corresponding to the preset data identifier searched in the picture database as a first picture identifier to be spliced; performing KV data pair assembly according to the first to-be-searched non-plain text placeholder and the first to-be-spliced picture identifier to obtain a second to-be-processed KV data pair corresponding to the first to-be-searched non-plain text placeholder, wherein the first to-be-searched non-plain text placeholder is used as a Key of the second to-be-processed KV data pair, and the first to-be-spliced picture identifier is used as a Value of the second to-be-processed KV data pair; repeatedly executing the step of extracting one placeholder from the non-plain text placeholder set as a first non-plain text placeholder to be searched until the extraction of the placeholder in the non-plain text placeholder set is completed; and taking all the second KV data pairs to be processed as the second KV data pair set.

Optionally, acquiring placeholder configuration data; extracting a placeholder from the non-plain text placeholder set to serve as a second non-plain text placeholder to be searched; searching the second non-plain text placeholder to be searched in the placeholder configuration data to obtain a second personalized configuration searching result; when the second personalized configuration searching result is successful, taking the configuration data identifier corresponding to the placeholder identifier of the second to-be-searched non-plain text placeholder in the placeholder configuration data as a second to-be-searched data identifier; when the second personalized configuration search result is failure, taking a preset data identifier of the second to-be-searched non-plain text placeholder in a Freemarker template corresponding to the target Freemarker template identifier set as the second to-be-searched data identifier; searching the second data identifier to be searched in the picture database, and taking the picture identifier searched in the picture database as a second picture identifier to be spliced; assembling the KV data pair according to the second to-be-searched non-plain text placeholder and the second to-be-spliced picture identifier to obtain a second to-be-analyzed KV data pair corresponding to the second to-be-searched non-plain text placeholder, wherein the second to-be-searched non-plain text placeholder is used as a Key of the second to-be-analyzed KV data pair, and the second to-be-spliced picture identifier is used as a Value of the second to-be-analyzed KV data pair; repeatedly executing the step of extracting one placeholder from the non-plain text placeholder set as a second to-be-searched non-plain text placeholder until the extraction of the placeholder in the non-plain text placeholder set is completed; and taking all the second KV data pairs to be analyzed as the second KV data pair set.

For S6, based on the template engine corresponding to the Freemarker framework, performing placeholder replacement and Word document generation according to the picture database, the target Freemarker template identifier set, the target location configuration data, the first KV data pair set and the second KV data pair set, and taking the generated Word document as the target Word document.

In one embodiment, before the step of obtaining a Word document generation request, the method includes:

s11: acquiring a template generation request;

s12: responding to the template generation request, and acquiring a Freemarker template identifier to be added, Word frame data to be added, Word style data to be added, a placeholder set to be added and a template object position data set to be processed, wherein the Word frame data to be added is Word frame data obtained based on Html, and the Word style data to be added is Word style data obtained based on CSS;

s13: generating a static page according to the Freemarker template to be added, the Word frame data to be added, the Word style data to be added, the placeholder set to be added and the template object position data set to be processed to obtain a static page to be converted;

s14: performing flt file format conversion on the static page to be converted to obtain a Freemarker template to be stored;

s15: and updating the Freemarker template library according to the Freemarker template to be stored.

According to the method, the static page is generated firstly, then flt file format conversion is carried out on the static page, and the file in the flt file format obtained through conversion is used as the Freemarker template to be stored, so that the Freemarker template is generated based on the Html and the CSS, and a foundation is provided for generating the Word document based on the Freemarker template and the Freemarker frame; through setting up the placeholder at Freemarker template, make template and service data and picture decoupling, make the change of the adaptation demand that this application can be better.

For S11, a template generation request input by the user may be acquired, and a template generation request sent by the third-party application system may also be acquired.

A template generation request, i.e., a request to generate a Freemarker template.

For S12, in response to the template generation request, the Freemarker template identifier to be added, the Word frame data to be added, the Word style data to be added, the placeholder set to be added, and the template object position data set to be processed, which are input by the user, may be obtained, and the Freemarker template identifier to be added, the Word frame data to be added, the Word style data to be added, the placeholder set to be added, and the template object position data set to be processed may also be obtained from a third-party application system.

The Word frame data to be added is Word frame data developed by adopting Html (hypertext markup language). Word framework data includes: text blocks and text block configuration data. Text content and pictures can be added into the text blocks. The text block configuration data is content data of each text block, and the content data does not include a placeholder.

The Word style data to be added is Word style data developed by adopting CSS (cascading style sheet). Word style data includes, but is not limited to: text style and picture style. Text styles include, but are not limited to: text outline level, text alignment, text font, and text background color. Picture styles include, but are not limited to: the picture alignment mode, whether the picture frame is included, the picture height and the picture width.

And the Freemarker template identifier to be added is also the Freemarker template identifier.

One or more placeholders are included in the set of placeholders to be added. The specific character of the placeholder can be set according to needs, and is not limited herein.

The template object position data set to be processed is position data of each object in the Word frame data to be added, the Word style data to be added and the placeholder set to be added. For example, a text block may be an object.

For S13, the template object position data set to be processed is adopted, static pages are generated according to the Word frame data to be added, the Word style data to be added and the placeholder set to be added, the generated static pages are used as the static pages to be converted, and the FreeMarker template marks to be added are used as the page marks of the static pages to be converted.

And S14, performing flt file format conversion on the static page to be converted, and taking the file in the flt file format obtained through conversion as a Freemarker template to be stored.

The flt file format is an openflight file of the VEGA prime, and is a file for generating a terrain.

And for S15, updating the Freemarker template to be stored into a Freemarker template library according to the Freemarker template identifier to be added corresponding to the Freemarker template to be stored.

The Freemarker template library includes: a set of Freemarker template identifications and a set of Freemarker templates.

In an embodiment, the step of obtaining the picture database includes:

s51: obtaining a diagram placeholder from the non-plain text placeholder set to obtain a diagram placeholder set;

s52: according to the service database, sequentially generating graphs and converting pictures for each graph placeholder in the graph placeholder set respectively to obtain a picture set to be stored;

s53: and acquiring the picture database, and updating the picture database according to the picture set to be stored.

According to the method and the device, chart generation and picture conversion are sequentially carried out on the chart placeholder, so that support is provided for generating the Word document by adopting pictures subsequently.

For S51, a chart placeholder is obtained from the non-plain text placeholder collection, and all obtained chart placeholders are taken as a chart placeholder collection.

For S52, extracting a placeholder from the chart placeholder set as a first chart placeholder to be searched; searching a preset data identifier of a first chart placeholder to be searched in a Freemarker template corresponding to the target Freemarker template identifier set in the service database, and taking service data corresponding to the service data identifier searched in the service database as service data of a first chart to be generated; generating a chart according to the service data of the first chart to be generated by adopting a chart generating plug-in unit to obtain a first chart to be converted; performing picture conversion according to the first chart to be converted to obtain a first picture to be stored; repeatedly executing the step of extracting one placeholder from the chart placeholder set as a first chart placeholder to be searched until the extraction of the placeholder in the chart placeholder set is completed; and taking all the first pictures to be stored as the picture sets to be stored.

Optionally, acquiring placeholder configuration data; extracting a placeholder from the chart placeholder set to serve as a second chart placeholder to be searched; searching the chart placeholder to be searched in the placeholder configuration data to obtain a third personalized configuration searching result; when the third personalized configuration searching result is successful, taking the configuration data identifier corresponding to the placeholder identifier of the second chart placeholder to be searched in the placeholder configuration data as a third data identifier to be searched; when the third personalized configuration search result is failure, taking a preset data identifier of the second chart placeholder to be searched in a Freemarker template corresponding to the target Freemarker template identifier set as the third data identifier to be searched; searching the third data identifier to be searched in the service database, and taking the service data corresponding to the service data identifier searched in the service database as the service data of a second chart to be generated; generating a chart according to the service data of the second chart to be generated by adopting a chart generating plug-in unit to obtain a second chart to be converted; performing picture conversion according to the second chart to be converted to obtain a second picture to be stored; repeatedly executing the step of extracting one placeholder from the chart placeholder set as a second chart placeholder to be searched until the extraction of the placeholder in the chart placeholder set is completed; and taking all the second pictures to be stored as the picture set to be stored.

The chart generation plug-in may generate a table and a chart according to the service data, and specific implementation steps are not described herein.

And S53, acquiring the picture database, and updating the picture set to be stored into the picture database.

In an embodiment, the step of generating a Word document according to the picture database, the target FreeMarker template identifier set, the target position configuration data, the first KV data pair set, and the second KV data pair set based on the FreeMarker frame to obtain a target Word document includes:

s61: acquiring a Freemarker template library based on the Freemarker framework, and constructing a document framework according to the Freemarker template library, the target Freemarker template identification set and the target position configuration data to obtain a flt file to be replaced;

s62: and based on the Freemarker framework, generating a Word document according to the flt file to be replaced, the picture database, the first KV data pair set and the second KV data pair set to obtain the target Word document.

According to the method, the document frame is firstly built based on the Freemarker framework, then the Word document is generated, so that the Word document is generated based on the Freemarker template and the Freemarker framework, a large amount of codes do not need to be carried out on specific contents, and the style does not need to be adjusted on the specific contents.

For S61, based on the FreeMarker framework, a FreeMarker template library may be obtained from a database, or may be obtained from a third-party application system.

And based on the template engine corresponding to the Freemarker framework, constructing a document framework according to the Freemarker template library and the target Freemarker set by adopting the target position configuration data, and taking the constructed file in the flt file format as the flt file to be replaced.

For S62, based on a template engine corresponding to the Freemarker frame, replacing placeholders in the flt file to be replaced according to the picture database, the first KV data pair set and the second KV data pair set, performing Word document format conversion on the flt file to be replaced after replacement is completed, and taking the file in the Word document format obtained through conversion as the target Word document.

The Word document format includes: DOC,. DOCX.

In an embodiment, the step of generating a Word document according to the flt file to be replaced, the picture database, the first KV data pair set, and the second KV data pair set based on the FreeMarker frame to obtain the target Word document includes:

s621: on the basis of the Freemarker frame, replacing the placeholder in the flt file to be replaced according to the picture database, the first KV data pair set and the second KV data pair set to obtain a flt file to be converted;

s622: and performing Word document format conversion on the flt file to be converted based on the Freemarker frame to obtain the target Word document.

In this embodiment, based on the Freemarker framework, the placeholder in the flt file to be replaced is replaced and the format of the Word document is converted according to the first KV data pair set and the second KV data pair set, so that the Word document is generated based on the Freemarker template and the Freemarker framework, and a large amount of coding and style adjustment for specific content are not required.

For S621, based on a FreeMarkate Template class (Template writing class) of a Template engine corresponding to the FreeMarker frame, replacing the placeholder in the flt file to be replaced with the Value of the first KV data pair set, acquiring a picture from the picture database with the Value of the second KV data pair set, replacing the placeholder in the flt file to be replaced with the acquired picture, and taking the flt file to be replaced after replacement as the flt file to be converted.

And for S622, performing Word document format conversion on the flt file to be converted based on a template method of a template engine corresponding to the Freemarker frame, and taking the file in the Word document format obtained through conversion as the target Word document.

In one embodiment, a Word-to-PDF plug-in is integrated in the Java application, where the Word-to-PDF plug-in is a plug-in obtained based on OpenOffice;

after the step of generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set based on the Freemarker frame to obtain a target Word document, the method further includes:

s7: acquiring a PDF conversion request;

s8: responding to the PDF conversion request, and sending the target Word document to the Word PDF conversion plug-in;

s9: and performing PDF file format conversion on the target Word document based on the Word-to-PDF plug-in to obtain a target PDF document.

Since microsoft does not have an interface for converting a Java open Word document format into a PDF file format, when converting according to a Word document by using an Apache POI, part of content is lost, a picture position is changed, and a picture is overlapped with a character, in order to solve these problems, in the embodiment, a plug-in obtained based on OpenOffice is used to convert a Word document into a PDF file format, and OpenOffice has excellent support for decoding and transcoding of Word, thereby improving accuracy of PDF conversion.

OpenOffice is a set of cross-platform office software suite that can be executed on operating systems such as Windows, Linux, MacOS X (X11), Solaris, and the like.

For S7, a PDF conversion request input by the user may be acquired, or a PDF conversion request sent by a third-party application system may be acquired.

A convert PDF request, i.e., a request to convert a Word document format to a PDF file format.

PDF, an abbreviation of Portable Document Format, means Portable Document Format.

And for S8, responding to the PDF conversion request, converting the target Word document into a file stream, and sending the file stream obtained by conversion to the Word PDF conversion plug-in.

And S9, decoding the target Word document based on the Word-to-PDF plug-in, transcoding the decoded data in a PDF file format, and taking the transcoded PDF file in the PDF file format as the target PDF document.

In an embodiment, the step of performing PDF file format conversion on the target Word document based on the Word-to-PDF plug-in to obtain a target PDF document includes:

s91: acquiring a preset storage address;

s92: adopting an Office document converter of the Word-to-PDF plug-in to convert the PDF file format of the target Word document to obtain the target PDF document;

s93: and storing the target PDF document into a folder corresponding to the preset storage address.

In this embodiment, the Office document converter of the Word-to-PDF plug-in is used to convert the PDF file format, and because the Word-to-PDF plug-in is a plug-in obtained based on OpenOffice, OpenOffice has an excellent support for Word decoding and transcoding, thereby improving accuracy of PDF conversion.

For S91, a preset storage address input by the user may be acquired.

The preset storage address is a link address of a folder in which the target PDF document is stored.

And S92, decoding the target Word document and transcoding the PDF file format by adopting the Office document converter of the Word-to-PDF plug-in, and taking the PDF file format obtained by transcoding as the target PDF document.

Office document converter, i.e., Office DocumentConverter.

With reference to fig. 2, the present application also proposes a device for generating Word documents by Java applications, said device being suitable for Java applications, wherein a freemaker framework is integrated in said Java applications, said device comprising:

the device comprises a request acquisition module 100, a processing module and a processing module, wherein the request acquisition module 100 is used for acquiring a Word document generation request, and the Word document generation request carries a target Freemarker template identification set and target position configuration data;

a to-be-processed placeholder set determining module 200, configured to obtain a placeholder from a template corresponding to the target Freemarker template set, so as to obtain a to-be-processed placeholder set;

a placeholder dividing module 300, configured to divide the placeholders in the to-be-processed placeholder set according to placeholder types to obtain a plain text placeholder set and a non-plain text placeholder set;

a first KV data pair set determining module 400, configured to acquire a service database, and sequentially perform service data search and KV data pair assembly on each placeholder in the plain text placeholder set according to the service database, to obtain a first KV data pair set;

a second KV data pair set determining module 500, configured to obtain a picture database, and sequentially perform, according to the picture database, picture identifier lookup and KV data pair assembly for each placeholder in the non-plain text placeholder set, to obtain a second KV data pair set;

and a target Word document determining module 600, configured to perform Word document generation according to the picture database, the target freemaker template identifier set, the target position configuration data, the first KV data pair set, and the second KV data pair set based on the freemaker frame, so as to obtain a target Word document.

The method is suitable for Java application, a Freemarker framework is integrated in the Java application, and the method comprises the following steps: acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data; acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed; dividing placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set; acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set; acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set; based on the FreeMarker framework, according to the picture database, the target FreeMarker template identification set, the target position configuration data, the first KV data pair set and the second KV data pair set, the target Word document is obtained, so that the Word document is generated based on the FreeMarker template and the FreeMarker framework, a large amount of coding is not needed for specific contents, the style is not needed to be adjusted for the specific contents, and the template, the service data and the picture are decoupled, so that the method can better adapt to the change of the requirement.

Referring to fig. 3, a computer device, which may be a server and whose internal structure may be as shown in fig. 3, is also provided in the embodiment of the present application. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the computer designed processor is used to provide computational and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer equipment is used for storing data such as a method for generating Word documents by using Java applications and the like. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a method for generating Word documents by a Java application. The method for generating the Word document by the Java application is suitable for the Java application, a Freemarker framework is integrated in the Java application, and the method comprises the following steps: acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data; acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed; dividing the placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set; acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set; acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set; and based on the Freemarker framework, generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set to obtain a target Word document.

The method is suitable for Java application, a Freemarker framework is integrated in the Java application, and the method comprises the following steps: acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data; acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed; dividing placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set; acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set; acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set; based on the FreeMarker framework, according to the picture database, the target FreeMarker template identification set, the target position configuration data, the first KV data pair set and the second KV data pair set, the target Word document is obtained, so that the Word document is generated based on the FreeMarker template and the FreeMarker framework, a large amount of coding is not needed for specific contents, the style is not needed to be adjusted for the specific contents, and the template, the service data and the picture are decoupled, so that the method can better adapt to the change of the requirement.

An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a method for generating a Word document by a Java application, where the method is suitable for the Java application, and a Freemarker framework is integrated in the Java application, and the method includes: acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data; acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed; dividing the placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set; acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set; acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set; and based on the Freemarker framework, generating a Word document according to the picture database, the target Freemarker template identifier set, the target position configuration data, the first KV data pair set and the second KV data pair set to obtain a target Word document.

The method for generating the Word document by the executed Java application is suitable for the Java application, a Freemarker framework is integrated in the Java application, and the method comprises the following steps: acquiring a Word document generation request, wherein the Word document generation request carries a target Freemarker template identification set and target position configuration data; acquiring a placeholder from a template corresponding to the target Freemarker template identifier set to obtain a placeholder set to be processed; dividing placeholders in the placeholder set to be processed according to the type of the placeholder to obtain a plain text placeholder set and a non-plain text placeholder set; acquiring a service database, and sequentially searching service data and assembling KV data pairs aiming at each placeholder in the plain text placeholder set according to the service database to obtain a first KV data pair set; acquiring a picture database, and sequentially searching picture identifiers and assembling KV data pairs aiming at each placeholder in the non-plain text placeholder set according to the picture database to obtain a second KV data pair set; based on the FreeMarker framework, according to the picture database, the target FreeMarker template identification set, the target position configuration data, the first KV data pair set and the second KV data pair set, the target Word document is obtained, so that the Word document is generated based on the FreeMarker template and the FreeMarker framework, a large amount of coding is not needed for specific contents, the style is not needed to be adjusted for the specific contents, and the template, the service data and the picture are decoupled, so that the method can better adapt to the change of the requirement.

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 hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium provided herein and used in the examples may include non-volatile and/or volatile memory. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), double-rate SDRAM (SSRSDRAM), Enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and bus dynamic RAM (RDRAM).

It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, apparatus, article, or method. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, apparatus, article, or method that includes the element.

The above description is only a preferred embodiment of the present application, and not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings of the present application, or which are directly or indirectly applied to other related technical fields, are also included in the scope of the present application.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:基于GEP的区块链数据编解码方法、装置、设备及介质

网友询问留言

已有0条留言

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

精彩留言,会给你点赞!