CN113378535A - Method and system for generating docx format document based on freemarker - Google Patents

Method and system for generating docx format document based on freemarker Download PDF

Info

Publication number
CN113378535A
CN113378535A CN202110697779.7A CN202110697779A CN113378535A CN 113378535 A CN113378535 A CN 113378535A CN 202110697779 A CN202110697779 A CN 202110697779A CN 113378535 A CN113378535 A CN 113378535A
Authority
CN
China
Prior art keywords
document
generating
docx
freemarker
xml
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110697779.7A
Other languages
Chinese (zh)
Inventor
汤先伟
张华�
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Software Technology Co Ltd
Original Assignee
Inspur Software Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Software Technology Co Ltd filed Critical Inspur Software Technology Co Ltd
Priority to CN202110697779.7A priority Critical patent/CN113378535A/en
Publication of CN113378535A publication Critical patent/CN113378535A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/174Redundancy elimination performed by the file system
    • G06F16/1744Redundancy elimination performed by the file system using compression, e.g. sparse files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/80Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
    • G06F16/83Querying
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/80Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
    • G06F16/83Querying
    • G06F16/838Presentation of query results
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/149Adaptation of the text data for streaming purposes, e.g. Efficient XML Interchange [EXI] format

Abstract

The invention discloses a method and a system for generating docx format documents based on freemarker, and belongs to the technical field of document generation implementation. According to the method for generating the docx-format document based on freemarker, ftl template files are compiled according to document contents in docx, related contents are inquired from a database when the document is generated, an xml file is generated by using the freemarker, document pictures are generated at the same time, and the related contents are compressed to generate the docx document. According to the method for generating the docx-format document based on freemarker, rapid adjustment of the docx-format document can be realized only by modifying ftl template files, and the method has good popularization and application values.

Description

Method and system for generating docx format document based on freemarker
Technical Field
The invention relates to the technical field of document generation realization, and particularly provides a method and a system for generating docx format documents based on freemarker.
Background
In some service scenarios, a report document needs to be generated by combining actual production data according to a fixed format, a general implementation mode is a mode based on text variable replacement, a document needs to be replaced by traversing a text when being generated, then a poi is used for generating the document, and the document needs to be repackaged and compiled after the post-modification, which is inconvenient for maintenance and has no good implementation mode for generating pictures in the document. FreeMarker is a template engine 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 Template is written as Freemarker Template Language (FTL). It is a simple, proprietary language, not as sophisticated as PHP programming languages. In the template, attention may be paid to how the data is presented, and outside the template attention may be paid to what data is to be presented. In order to more flexibly realize generation of the docx document, facilitate later maintenance and realize the function of displaying pictures in the document, further improvement is needed.
Disclosure of Invention
The technical task of the invention is to provide a method for generating docx-format documents based on freemarker, which can realize the rapid adjustment of docx-format documents only by modifying ftl template files, aiming at the problems.
A further technical task of the present invention is to provide a system for generating docx-format documents based on freemarker.
In order to achieve the purpose, the invention provides the following technical scheme:
a method for generating docx-format documents based on freemarker includes compiling ftl template files according to document contents in docx, inquiring related contents from a database when documents are generated, generating xml files by using freemarker, generating document pictures at the same time, and compressing the related contents to generate the docx documents.
Preferably, the method for generating the docx format document based on freemarker comprises the following steps:
s1, manufacturing a template: acquiring document xml content, sorting document xml files, and compiling ftl template files;
s2, generating an xml file: inquiring data, decompressing the docx template and generating xml;
s3, generating a picture: inquiring data, rendering at the front end and generating at the back end;
s4, generating a document: the file is compressed.
Preferably, when the document xml content is acquired, the docx file is decompressed through the compression tool, and the document xml file in the docx file and the name of the picture to be generated are acquired.
Document. xml file collation: xml describes the content and format of the docx file by using xml language, so that the sentence is disconnected and needs to be sorted to make the content coherent.
Preferably, when the ftl template file is written, the content to be dynamically generated in the document xml file is replaced by a variable using a freemarker grammar, and the sentence to be judged is judged by using the freemarker grammar.
Preferably, the query data for generating the xml file is data to be displayed in a document, which is queried from a database, and the data type is Map or Json.
Decompressing the docx template: the docx template file is mainly used as a basic file for generating a new document after being decompressed, and provides other files except documents. And (3) generating xml: and (3) transmitting the inquired data into a ftl template through a specified ftl template, outputting by a freemarker to generate an xml file, wherein the position of the generated xml file is positioned under a word directory.
Inquiring data when generating the picture: and querying data needing to be shown in the document from the database, wherein the data type is Map. Front-end rendering: rendering into a chart using the queried data using Echarts, and acquiring content in the Base64 format. Back-end generation: when receiving the pictures in the Base64 format, the back end converts the Base64 into the pictures in the png format and stores the pictures in the word \ media directory.
A system for generating docx format documents based on freemarker comprises a template making module, an xml file generating module, a picture generating module and a document generating module, wherein the template making module is used for making the module, acquiring document xml contents, sorting document xml files and compiling ftl template files; the xml file generation module is used for generating an xml file, inquiring data, decompressing a docx template and generating the xml; the image generation module is used for generating images, inquiring data, rendering at the front end and generating at the rear end; the document generating module is used for generating a document and compressing the file.
Preferably, when the template making module obtains the document xml content, the docx file is decompressed through the compression tool, and the document xml file in the docx file and the name of the picture to be generated are obtained.
Preferably, when the template making module writes ftl a template file, the content to be dynamically generated in the document xml file is replaced by a variable using a freemarker grammar, and the sentence to be judged is judged using the freemarker grammar.
Preferably, the query data of the xml file generation template is data to be displayed in a document, which is queried from a database, and the data type is Map or Json.
Compared with the prior art, the method for generating the docx format document based on the freemarker has the following outstanding beneficial effects: the method for generating the docx-format document based on freemarker can flexibly realize generation of the docx document, is convenient for later maintenance, realizes the function of displaying pictures in the document, can realize rapid adjustment of the format of the docx document, and has good popularization and application values.
Detailed Description
The method and system for generating docx-format document based on freemarker of the present invention will be further described in detail with reference to the following embodiments.
Examples
According to the method for generating the docx-format document based on freemarker, ftl template files are compiled according to document contents in docx, related contents are inquired from a database when the document is generated, an xml file is generated by using the freemarker, document pictures are generated at the same time, and the related contents are compressed to generate the docx document.
The method for generating the docx format document based on the freemarker specifically comprises the following steps:
s1, manufacturing a template: obtaining document xml content, sorting document xml files, and compiling ftl template files.
Acquiring the xml content of the document: and decompressing the docx file through a compression tool (winrar, good compression and the like), and acquiring a document.
Document. xml file collation: xml describes the content and format of the docx file by using xml language, so that the sentence is disconnected and needs to be sorted to make the content coherent.
Writing ftl a template file: replacing contents needing to be dynamically generated in the document xml file by variables by using a freemarker grammar, and judging sentences needing to be judged by using the freemarker grammar.
S2, generating an xml file: and querying data, decompressing the docx template and generating xml.
And (3) inquiring data: and querying data needing to be shown in the document from the database, wherein the data is of a Map or Json type.
Decompressing the docx template: the docx template file is mainly used as a basic file for generating a new document after being decompressed, and provides other files except documents.
And (3) generating xml: and (3) transmitting the inquired data into a ftl template through a specified ftl template, outputting by a freemarker to generate an xml file, wherein the position of the generated xml file is positioned under a word directory.
S3, generating a picture: and querying data, rendering at the front end and generating at the back end.
And (3) inquiring data: and querying data needing to be shown in the document from the database, wherein the data type is Map.
Front-end rendering: rendering into a chart using the queried data using Echarts, and acquiring content in the Base64 format.
Back-end generation: when receiving the pictures in the Base64 format, the back end converts the Base64 into the pictures in the png format and stores the pictures in the word \ media directory.
S4, generating a document: the file is compressed.
And compressing all the files to generate a compressed file, and updating the suffix into docx.
The system for generating docx-format documents based on freemarker comprises a template making module, an xml file generating module, a picture generating module and a document generating module, wherein the template making module is used for making the module, acquiring the xml content of the documents, sorting document. The xml file generation module is used for generating an xml file, inquiring data, decompressing a docx template and generating the xml; the image generation module is used for generating images, inquiring data, rendering at the front end and generating at the rear end; the document generating module is used for generating a document and compressing the file.
The template making module obtains the contents of the document xml: and decompressing the docx file through a compression tool (winrar, good compression and the like), and acquiring a document. Document. xml file collation: xml describes the content and format of the docx file by using xml language, so that the sentence is disconnected and needs to be sorted to make the content coherent. Writing ftl a template file: replacing contents needing to be dynamically generated in the document xml file by variables by using a freemarker grammar, and judging sentences needing to be judged by using the freemarker grammar.
And inquiring data in an Xml file generation module: and querying data needing to be shown in the document from the database, wherein the data is of a Map or Json type. Decompressing the docx template: the docx template file is mainly used as a basic file for generating a new document after being decompressed, and provides other files except documents. And (3) generating xml: and (3) transmitting the inquired data into a ftl template through a specified ftl template, outputting by a freemarker to generate an xml file, wherein the position of the generated xml file is positioned under a word directory. Inquiring data in the picture generation module: and querying data needing to be shown in the document from the database, wherein the data type is Map. Front-end rendering: rendering into a chart using the queried data using Echarts, and acquiring content in the Base64 format. Back-end generation: when receiving the pictures in the Base64 format, the back end converts the Base64 into the pictures in the png format and stores the pictures in the word \ media directory.
In the document generation module, all files are compressed, and after the compressed files are generated, the suffix is updated to docx.

Claims (9)

1. A method for generating docx format documents based on freemarker is characterized in that: compiling ftl template files according to the document contents in the docx, inquiring related contents from the database when generating the document, generating an xml file by using a freemaker, generating a document picture at the same time, and compressing the related contents to generate the docx document.
2. The method of freemarker-based generation of docx-format documents according to claim 1, characterized in that: the method comprises the following steps:
s1, manufacturing a template: acquiring document xml content, sorting document xml files, and compiling ftl template files;
s2, generating an xml file: inquiring data, decompressing the docx template and generating xml;
s3, generating a picture: inquiring data, rendering at the front end and generating at the back end;
s4, generating a document: the file is compressed.
3. The method of freemarker-based generation of docx-format documents according to claim 2, characterized in that: and when the document xml content is obtained, decompressing the docx file through a compression tool, and obtaining the document xml file in the docx file and the name of the picture to be generated.
4. A method of producing a docx-format document based on freemarker according to claim 3, characterized in that: when the ftl template file is written, replacing the content to be dynamically generated in the document xml file by using a freemarker grammar to form variables, and judging the sentence to be judged by using the freemarker grammar.
5. The method of freemarker-based generation of docx-format documents according to claim 4, characterized in that: and the query data for generating the xml file is data which needs to be displayed in the document and is queried from a database, and the data type is Map or Json.
6. A system for generating docx format documents based on freemarker is characterized in that: the system comprises a template making module, an xml file generating module, a picture generating module and a document generating module, wherein the template making module is used for making the module, acquiring document xml content, sorting document.xml files and compiling ftl template files; the xml file generation module is used for generating an xml file, inquiring data, decompressing a docx template and generating the xml; the image generation module is used for generating images, inquiring data, rendering at the front end and generating at the rear end; the document generating module is used for generating a document and compressing the file.
7. The freemarker-based docx format document generation system of claim 6, wherein: and when the template making module acquires the document xml content, decompressing the docx file through the compression tool, and acquiring the document xml file in the docx file and the name of the picture to be generated.
8. The freemarker-based docx format document generation system of claim 7, wherein: when the template making module writes ftl template files, the content to be dynamically generated in document xml files is replaced by variables by using a freemarker grammar, and sentences to be judged are judged by using the freemarker grammar.
9. The freemarker-based docx format document generation system of claim 8, wherein: the query data of the xml file generation template is data which needs to be displayed in a document and is queried from a database, and the data type is Map or Json.
CN202110697779.7A 2021-06-23 2021-06-23 Method and system for generating docx format document based on freemarker Pending CN113378535A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110697779.7A CN113378535A (en) 2021-06-23 2021-06-23 Method and system for generating docx format document based on freemarker

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110697779.7A CN113378535A (en) 2021-06-23 2021-06-23 Method and system for generating docx format document based on freemarker

Publications (1)

Publication Number Publication Date
CN113378535A true CN113378535A (en) 2021-09-10

Family

ID=77578592

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110697779.7A Pending CN113378535A (en) 2021-06-23 2021-06-23 Method and system for generating docx format document based on freemarker

Country Status (1)

Country Link
CN (1) CN113378535A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113760826A (en) * 2021-09-28 2021-12-07 浙江艾凯普计算机系统服务有限公司 Electronic component laboratory report generation method and detection device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111046635A (en) * 2019-12-13 2020-04-21 深圳前海环融联易信息科技服务有限公司 Method and device for manufacturing freemarker template, computer equipment and storage medium
CN111062187A (en) * 2019-11-27 2020-04-24 北京计算机技术及应用研究所 Structured parsing method and system for docx format document
CN111950247A (en) * 2020-07-08 2020-11-17 北京明略软件系统有限公司 Configuration-based Word document generation method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111062187A (en) * 2019-11-27 2020-04-24 北京计算机技术及应用研究所 Structured parsing method and system for docx format document
CN111046635A (en) * 2019-12-13 2020-04-21 深圳前海环融联易信息科技服务有限公司 Method and device for manufacturing freemarker template, computer equipment and storage medium
CN111950247A (en) * 2020-07-08 2020-11-17 北京明略软件系统有限公司 Configuration-based Word document generation method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
LSY_CSDN_: "freemarker基于docx格式创建模板导出带图片word文件", 《CSDN》 *
如何做一个漂亮的小姐姐: "如何使用freemarker生成doc、docx文档", 《CSDN》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113760826A (en) * 2021-09-28 2021-12-07 浙江艾凯普计算机系统服务有限公司 Electronic component laboratory report generation method and detection device

Similar Documents

Publication Publication Date Title
CN111325626B (en) Account checking data pushing method and device
EP1513074A2 (en) Apparatus and method for generating reusable composite components during dynamic document construction
CN101436142B (en) Set-top box starting-up picture changing method
US8411956B2 (en) Associating optical character recognition text data with source images
US20110271246A1 (en) Software development support tool
CN113378535A (en) Method and system for generating docx format document based on freemarker
CN109766085B (en) Method and device for processing enumeration type codes
CN109710250B (en) Visualization engine system and method for constructing user interface
CN110737630B (en) Method and device for processing electronic archive file, computer equipment and storage medium
CN101211352A (en) Electronic dictionary data update system and its method
CN111221735A (en) System for automatically generating service interaction test script
CN110737629A (en) method and system for archiving electronic files
CN104820962A (en) Method for generating and printing watermarks capable of replacing manual signatures
CN110569488A (en) modular template WORD generation method based on XML (extensive markup language)
KR20080107440A (en) Document processor and re-aggregator
CN115136256A (en) Information processing method, information processing apparatus, information processing program, and recording medium
CN111581462A (en) Method for inputting information by voice and terminal equipment
CN113703755A (en) Code generation method and code generation device
US20210097358A1 (en) Smart page decoding system including linearization for viewing and printing
CN116303359A (en) Method for realizing multi-type document export of database structure
CN113779953B (en) Automatic document generation method and system
CN115841095A (en) Document establishing method, system, medium and equipment
CN111310434B (en) Text generation method and device, electronic equipment and storage medium
CN110232182B (en) Semantic recognition method and device and voice dialogue system
CN113536767A (en) Data processing method, device, equipment, medium and computer program product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20210910

RJ01 Rejection of invention patent application after publication