CN114237753A - Method for inserting multiple attachments into word file based on freemark - Google Patents

Method for inserting multiple attachments into word file based on freemark Download PDF

Info

Publication number
CN114237753A
CN114237753A CN202111565536.4A CN202111565536A CN114237753A CN 114237753 A CN114237753 A CN 114237753A CN 202111565536 A CN202111565536 A CN 202111565536A CN 114237753 A CN114237753 A CN 114237753A
Authority
CN
China
Prior art keywords
file
word
attachment
freemark
test
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.)
Granted
Application number
CN202111565536.4A
Other languages
Chinese (zh)
Other versions
CN114237753B (en
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.)
China Telecom Fufu Information Technology Co Ltd
Original Assignee
China Telecom Fufu Information 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 China Telecom Fufu Information Technology Co Ltd filed Critical China Telecom Fufu Information Technology Co Ltd
Priority to CN202111565536.4A priority Critical patent/CN114237753B/en
Publication of CN114237753A publication Critical patent/CN114237753A/en
Application granted granted Critical
Publication of CN114237753B publication Critical patent/CN114237753B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons
    • 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/151Transformation
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Document Processing Apparatus (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method for inserting multiple attachments into a word file based on freemark, wherein positions of the word where the attachments need to be inserted are respectively replaced by occupational signs, then the word is stored in an xml format through office software, and finally the file stored in the xml format is formatted and then the suffix name of the file is modified to ftl. Adding corresponding label data at the corresponding position of the ftl template according to the file type in the attachment parameter set; the attachment is then diverted to base64 data to replace the placeholder of ftl template. The invention satisfies the accessory insertion effect under various types and scenes.

Description

Method for inserting multiple attachments into word file based on freemark
Technical Field
The invention relates to the technical field of java application, in particular to a method for inserting multiple attachments into a word file based on freemark.
Background
Existing freemark template engine techniques insert attachment hyperlinks into templates through code. Data mode encoded by inserting accessory base 64: firstly, according to the number and the type of the inserted attachments, manually inserting empty files of corresponding types at specified positions in a word file template in advance, storing the word file in an xml format, then finding out the positions of Base64 data corresponding to the inserted attachments, deleting Base64 data corresponding to the corresponding files, replacing the Base with $ { } placeholders, and finally storing template files in a ftl format. And reading the accessory to be inserted through Java, converting the accessory to be inserted into a Base64 code, finally replacing the $ {. X } placeholder with a value of the Base64 code of the accessory through a freemark template engine, and finally generating a word file.
However, the method of inserting hyperlinks requires that a large number of files are generated when the word file and the attachment are stored in the same directory; it is also necessary to package the file and all attachments into a compressed package when downloading the file. And the generation of the template file is complicated and needs too much manual intervention. First, a template file is created, and a file of a corresponding type is inserted in advance by finding a position corresponding to the inserted attachment. And manually saved in word xml format. The saved xml-formatted file also needs to be manually formatted. The corresponding data is deleted and replaced with placeholders. If the generated word file has a place where the attachment needs to be inserted circularly, or the number and type of the inserted attachments are unknown, the failure is easily caused. And if the operation is improper slightly, the generated word file is damaged when being opened.
Disclosure of Invention
The invention aims to provide a method for inserting multi-attachment into a word file based on freemark.
The technical scheme adopted by the invention is as follows:
a method for inserting multi-attachment into a word file based on freemark comprises the following steps:
step 1, obtaining a word file to be inserted, converting the word file into an xml format file, and renaming the word file as a test.
Step 2, scanning the number and the position information of $ { attacheFile _ File Path } in the test.xml file through codes to confirm the attachment information,
step 3, scanning each attachment based on the file name of the attachment information to acquire the file type of the corresponding attachment;
adding xml basic data of the corresponding file type at the corresponding position of the test.xml file according to the number of the attachments and the file type;
step 5, changing the suffix name of the test.xml file into a test.ftl file for standby;
and 6, creating a wordparam map to read each attachment file and respectively convert the attachment files into base64 encoded data to be used as values, calling a process method provided by a freemark jar package to scan a test. ftl file, and replacing the placeholder with the corresponding value to generate a word document when the placeholder of $ { key } is scanned.
Further, savefile provided by spiral doc. jar is called in step 1 to save the word file as test.
Further, in step 3, the actual file type is determined according to the first characters in the file stream of the attachment information.
Further, in step 4, the representation forms of the various types of files in the word document are collected and analyzed in advance, and basic data are generated.
Further, in step 4, Id numbering processing of the Relationship node is performed, and then corresponding xml basic data is added at a corresponding position according to the number of attachments and the file type.
Further, in step 6, the attachment is read by using the attacheFile _ file path as a key.
Further, the method comprises a step 7 of packaging the analysis processing procedures from the step 1 to the step 6 into a jar package, introducing the jar package into a program to call a provided method, and transmitting a word file path needing to insert a file, so that the insertion of the attachment is automatically completed and a word document is output.
The invention adopts the technical scheme that the positions of the word, which need to be inserted into the attachments, are respectively replaced by the occupation characters, then the word is saved into the xml format through the office software, and finally the suffix name of the modified file is ftl after the file saved into the xml format is formatted. Adding corresponding label data at the corresponding position of the ftl template according to the file type in the attachment parameter set; the attachment is then migrated to base64 data to replace the placeholders of ftl templates, satisfying the attachment insertion effect in various types and scenarios. And finally the presentation in the word is comparable to a person manually inserting an attachment into a word file. In java development, functional requirements of various task reports are frequently met, and word file reports are required to be finally generated for reporting. And various data may be required to be displayed while generating the report, if the data size is large, the data is exported to an excel file, and the excel file is finally inserted into a word file. In addition, the data information can be generated circularly according to different modules and the like, so that the method is more convenient in such a situation. The invention has the advantages of more convenient use and avoidance of complex manual processing process. Background art during the use process, a large amount of manual processing needs to be carried out on the template. And the background art cannot achieve the desired effect under some specific scenarios.
Drawings
The invention is described in further detail below with reference to the accompanying drawings and the detailed description;
FIG. 1 is a schematic diagram of an architecture of a method for inserting multiple attachments into a word file based on freemark according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application.
As shown in FIG. 1, the invention discloses a method for inserting multi-attachments into a word file based on freemark, which comprises the following steps:
step 1, obtaining a word file to be inserted, converting the word file into an xml format file, and renaming the word file as a test.
Step 2, scanning the number and the position information of $ { attacheFile _ File Path } in the test.xml file through codes to confirm the attachment information,
step 3, scanning each attachment based on the file name of the attachment information to acquire the file type of the corresponding attachment;
adding xml basic data of the corresponding file type at the corresponding position of the test.xml file according to the number of the attachments and the file type;
step 5, changing the suffix name of the test.xml file into a test.ftl file for standby;
and 6, creating a wordparam map to read each attachment file and respectively convert the attachment files into base64 encoded data to be used as values, calling a process method provided by a freemark jar package to scan a test. ftl file, and replacing the placeholder with the corresponding value to generate a word document when the placeholder of $ { key } is scanned.
Specifically, the generation code is as follows:
// generating word
File outFile = new File ("output File path");
Writer out = null;
FileOutputStream fos = new FileOutputStream(outFile);
Writer out = new OutputStreamWriter(fos, "UTF-8");
template.process(wordParamsMap,out);
further, savefile provided by spiral doc. jar is called in step 1 to save the word file as test. Specifically, the execution code is as follows:
// load Word test document
Document doc = new Document();
doc.loadFromFile("text.docx");
Method for transferring to xml document
doc.saveToFile("test.xml.",FileFormat.Word_Xml);
doc.dispose();
Further, in step 3, the actual file type is determined according to the first characters in the file stream of the attachment information.
Further, in step 4, the representation forms of the various types of files in the word document are collected and analyzed in advance, and basic data are generated. For example: the variant form of excel is:
<pkg:part pkg:name="/word/embeddings/oleObject1.bin" pkg:contentType="application/vnd.openxmlformats-officedocument.oleObject">
<pkg:binaryData>
base64 encoded data, here an excel file
</pkg:binaryData>
</pkg:part>
The image picture is represented in the form that:
<pkg:part pkg:name="/word/media/image1.emf" pkg:contentType="image/x-emf">
<pkg:binaryData>
here base64 encoded data for a picture
</pkg:binaryData>
</pkg:part>
Further, in step 4, Id numbering processing of the Relationship node is performed, and then corresponding xml basic data is added at a corresponding position according to the number of attachments and the file type.
Further, in step 6, the attachment is read by using the attacheFile _ file path as a key.
Further, the method comprises a step 7 of packaging the analysis processing procedures from the step 1 to the step 6 into a jar package, introducing the jar package into a program to call a provided method, and transmitting a word file path needing to insert a file, so that the insertion of the attachment is automatically completed and a word document is output.
The invention adopts the technical scheme that the positions of the word, which need to be inserted into the attachments, are respectively replaced by the occupation characters, then the word is saved into the xml format through the office software, and finally the suffix name of the modified file is ftl after the file saved into the xml format is formatted. Adding corresponding label data at the corresponding position of the ftl template according to the file type in the attachment parameter set; the attachment is then migrated to base64 data to replace the placeholders of ftl templates, satisfying the attachment insertion effect in various types and scenarios. And finally the presentation in the word is comparable to a person manually inserting an attachment into a word file. In java development, functional requirements of various task reports are frequently met, and word file reports are required to be finally generated for reporting. And various data may be required to be displayed while generating the report, if the data size is large, the data is exported to an excel file, and the excel file is finally inserted into a word file. In addition, the data information can be generated circularly according to different modules and the like, so that the method is more convenient in such a situation. The invention has the advantages of more convenient use and avoidance of complex manual processing process. Background art during the use process, a large amount of manual processing needs to be carried out on the template. And the background art cannot achieve the desired effect under some specific scenarios.
It is to be understood that the embodiments described are only a few embodiments of the present application and not all embodiments. The embodiments and features of the embodiments in the present application may be combined with each other without conflict. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the detailed description of the embodiments of the present application is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.

Claims (7)

1. A method for inserting multiple attachments into a word file based on freemark is characterized in that: which comprises the following steps:
step 1, obtaining a word file to be inserted, converting the word file into an xml format file, and renaming the word file as a test.
Step 2, scanning the number and the position information of $ { attacheFile _ File Path } in the test.xml file through codes to confirm the attachment information,
step 3, scanning each attachment based on the file name of the attachment information to acquire the file type of the corresponding attachment;
adding xml basic data of the corresponding file type at the corresponding position of the test.xml file according to the number of the attachments and the file type;
step 5, changing the suffix name of the test.xml file into a test.ftl file for standby;
and 6, creating a wordparam map to read each attachment file and respectively convert the attachment files into base64 encoded data to be used as values, calling a process method provided by a freemark jar package to scan a test. ftl file, and replacing the placeholder with the corresponding value to generate a word document when the placeholder of $ { key } is scanned.
2. The method for inserting multi-attachment into a word file based on freemark according to claim 1, characterized in that: and calling saveToFile provided by Spire doc. jar in the step 1 to save the word file as test.
3. The method for inserting multi-attachment into a word file based on freemark according to claim 1, characterized in that: and 3, judging the real file type according to the first characters in the file stream of the attachment information.
4. The method for inserting multi-attachment into a word file based on freemark according to claim 1, characterized in that: and 4, collecting and analyzing the expression forms of the files of various types in the word document in advance and generating basic data.
5. The method for inserting multi-attachment into a word file based on freemark according to claim 1, characterized in that: and 4, carrying out Id numbering processing on the Relationship node, and adding corresponding xml basic data at a corresponding position according to the number of the attachments and the file type.
6. The method for inserting multi-attachment into a word file based on freemark according to claim 1, characterized in that: in step 6, the attachment is read by using the attacheFile _ file path as a key word.
7. The method for inserting multi-attachment into a word file based on freemark according to claim 1, characterized in that: step 7, packaging the analysis processing procedures from step 1 to step 6 into a jar packet, introducing the jar packet into a program to call a provided method, transmitting a word file path needing to insert a file, automatically completing the insertion of an attachment and outputting a word document.
CN202111565536.4A 2021-12-20 2021-12-20 Method for inserting multiple attachments into word file based on freemark Active CN114237753B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111565536.4A CN114237753B (en) 2021-12-20 2021-12-20 Method for inserting multiple attachments into word file based on freemark

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111565536.4A CN114237753B (en) 2021-12-20 2021-12-20 Method for inserting multiple attachments into word file based on freemark

Publications (2)

Publication Number Publication Date
CN114237753A true CN114237753A (en) 2022-03-25
CN114237753B CN114237753B (en) 2023-06-16

Family

ID=80759608

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111565536.4A Active CN114237753B (en) 2021-12-20 2021-12-20 Method for inserting multiple attachments into word file based on freemark

Country Status (1)

Country Link
CN (1) CN114237753B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060143556A1 (en) * 2004-12-23 2006-06-29 Oracle International Corporation Flexible electronic document that receives data insertion from one or more data sources
CN102612689A (en) * 2009-10-28 2012-07-25 雅虎公司 Mechanism for adding content from a search to a document or message
CN103324616A (en) * 2012-03-20 2013-09-25 国际商业机器公司 Method and computer equipment for adding attachment to electronic message
CN103324625A (en) * 2012-03-21 2013-09-25 宇龙计算机通信科技(深圳)有限公司 Method for inserting network resource and communication terminal thereof

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060143556A1 (en) * 2004-12-23 2006-06-29 Oracle International Corporation Flexible electronic document that receives data insertion from one or more data sources
CN102612689A (en) * 2009-10-28 2012-07-25 雅虎公司 Mechanism for adding content from a search to a document or message
CN103324616A (en) * 2012-03-20 2013-09-25 国际商业机器公司 Method and computer equipment for adding attachment to electronic message
CN103324625A (en) * 2012-03-21 2013-09-25 宇龙计算机通信科技(深圳)有限公司 Method for inserting network resource and communication terminal thereof

Also Published As

Publication number Publication date
CN114237753B (en) 2023-06-16

Similar Documents

Publication Publication Date Title
CN111767254B (en) Multi-file reading device and method based on format data stream file technology
CN108595389B (en) Method for converting Word document into txt plain text document
CN110737630B (en) Method and device for processing electronic archive file, computer equipment and storage medium
CN110474836A (en) A kind of email template generation method, calculates equipment and medium at device
CN101118558B (en) Converting method and apparatus for resource file
CN101430684A (en) Method and apparatus for mutual conversion between Chinese work office software document and documents with other format
CN105975446A (en) Method and system for displaying word document content by modules in mobile phone terminal
CN112016290A (en) Automatic document typesetting method, device, equipment and storage medium
CN108664546B (en) XML data structure conversion method and device
CN102387120B (en) File transmission method and network transmission system
CN115630618A (en) Intelligent scene editing method, system, equipment and medium for PDF document
CN116521621A (en) Data processing method and device, electronic equipment and storage medium
CN114489950A (en) Component adapting method and device, electronic equipment and storage medium
CN1808428A (en) Information searching criteria presentation and editing system and method
CN114237753B (en) Method for inserting multiple attachments into word file based on freemark
CN104378362A (en) Method and device for carrying out conversion of message interfaces
CN113779953B (en) Automatic document generation method and system
CN112650600B (en) Method, device and computer equipment for pushing message content
CN111143450B (en) Method and device for importing data
CN109509467B (en) Code generation method and device
CN110196965B (en) Method and device for converting XML (extensive Makeup language) file into Word file
CN101470737A (en) File type conversion system and method for changing file format
CN111522815A (en) Method for warehousing enterprise basic information
CN111523294A (en) PDF file-based comment separation processing method and device
KR100250978B1 (en) Method for converting autocad drawing to infomap drawing

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
GR01 Patent grant
GR01 Patent grant