Movatterモバイル変換


[0]ホーム

URL:


CN118607500A - Document report generation method and system based on data processing results and templates - Google Patents

Document report generation method and system based on data processing results and templates
Download PDF

Info

Publication number
CN118607500A
CN118607500ACN202410746798.8ACN202410746798ACN118607500ACN 118607500 ACN118607500 ACN 118607500ACN 202410746798 ACN202410746798 ACN 202410746798ACN 118607500 ACN118607500 ACN 118607500A
Authority
CN
China
Prior art keywords
data
template
document
rendering
file
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
CN202410746798.8A
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.)
Fujian Boss Software Co ltd
Original Assignee
Fujian Boss Software 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 Fujian Boss Software Co ltdfiledCriticalFujian Boss Software Co ltd
Priority to CN202410746798.8ApriorityCriticalpatent/CN118607500A/en
Publication of CN118607500ApublicationCriticalpatent/CN118607500A/en
Pendinglegal-statusCriticalCurrent

Links

Classifications

Landscapes

Abstract

Translated fromChinese

本发明公开了基于数据处理结果及模板的文档报告生成方法及系统,文档报告生成方法包括以下步骤:采集财政大数据平台的数据,保存作为动态数据;根据用户提交的文档渲染请求中对应的文档报告类型参数,从模板库中获取需要渲染的模板文件;通过poi解析提取所述模板文件中特定标记的内容作为指标的引用,并结合用户提交的变量,从所述动态数据中获取实时数据对模板文件进行渲染;对模板文件进行渲染具体为:枚举模板文件中所有的占位标签,根据占位标签从动态数据中获取数据对相应的占位标签进行渲染填充;将渲染完成的模板文件转换成pdf格式的文档报告并返回用户端。本发明能够快速生成大量高质量的文档报告并提高报告的准确性和可靠性。

The present invention discloses a document report generation method and system based on data processing results and templates. The document report generation method includes the following steps: collecting data from a financial big data platform and saving it as dynamic data; obtaining a template file to be rendered from a template library according to a document report type parameter corresponding to a document rendering request submitted by a user; extracting the content of a specific tag in the template file as a reference of an indicator through POI analysis, and obtaining real-time data from the dynamic data to render the template file in combination with variables submitted by the user; rendering the template file specifically includes: enumerating all placeholder tags in the template file, obtaining data from the dynamic data according to the placeholder tags to render and fill the corresponding placeholder tags; converting the rendered template file into a document report in PDF format and returning it to the user end. The present invention can quickly generate a large number of high-quality document reports and improve the accuracy and reliability of the reports.

Description

Translated fromChinese
基于数据处理结果及模板的文档报告生成方法及系统Document report generation method and system based on data processing results and templates

技术领域Technical Field

本发明属于文档生成技术领域,特别涉及基于数据处理结果及模板的文档报告生成方法及系统。The present invention belongs to the technical field of document generation, and in particular relates to a document report generation method and system based on data processing results and templates.

背景技术Background Art

在现代信息化社会中,各类报告和文档的生成是企业和其他组织日常工作中不可或缺的一部分。这些报告和文档不仅用于内部管理和决策,还用于对外发布和交流。然而,传统的文档生成方式通常依赖于人工操作,效率低下,容易出现错误,且难以保证实时性和准确性。目前的文档生成放在了用户本地进行,通过本地预装软件与远程服务请求数据和模板完成逻辑运算和文档生成。In the modern information society, the generation of various reports and documents is an indispensable part of the daily work of enterprises and other organizations. These reports and documents are not only used for internal management and decision-making, but also for external publishing and communication. However, traditional document generation methods usually rely on manual operations, which are inefficient, prone to errors, and difficult to ensure real-time and accuracy. Currently, document generation is performed locally by users, and logical operations and document generation are completed through local pre-installed software and remote service request data and templates.

如公开号为CN117034899A的中国发明专利申请公开了一种基于模板的文档生成装置、方法、设备及存储介质,其文档生成方法包括以下步骤:分别对与目标文档生成指令对应的业务数据和目标报告实例信息进行解析,以获取树形结构的目标报告目录信息和业务数据信息;接收报告实例解析模块输出的所述目标报告目录信息,并通过递归算法循环所述目标报告目录信息生成多个目标报告单目录节点信息;解析与所述目标报告单目录节点信息对应的各个组件信息,生成实体组件,并将所述业务数据信息转换成各个实体组件下的文档内容,组装所述文档内容,生成目标报告实例文档。For example, the Chinese invention patent application with publication number CN117034899A discloses a template-based document generation device, method, equipment and storage medium, and its document generation method includes the following steps: respectively parsing the business data and target report instance information corresponding to the target document generation instruction to obtain the target report directory information and business data information in a tree structure; receiving the target report directory information output by the report instance parsing module, and looping the target report directory information through a recursive algorithm to generate multiple target report single directory node information; parsing each component information corresponding to the target report single directory node information to generate entity components, and converting the business data information into document content under each entity component, assembling the document content, and generating a target report instance document.

随着大数据技术的发展,需要通过集成和分析各种数据资源并生成报表或者文档以方便工作,财政大数据平台等数据源能够提供丰富的、实时更新的数据信息。如何利用这些动态数据,结合用户的具体需求,高效、准确地生成各类文档报告,成为一个亟待解决的问题。财政大数据平台治理产生的数据需要能够生成综合的分析报告,这些分析报告不再是静态的文档,而是可以交互的多维数据展示。对于丰富、实时更新的财政大数据平台等数据源,需要快速生成大量高质量的文档报告,并保证报告的准确性和可靠性,上述技术方案的应用效果不佳。With the development of big data technology, it is necessary to integrate and analyze various data resources and generate reports or documents to facilitate work. Data sources such as the financial big data platform can provide rich, real-time updated data information. How to use these dynamic data, combined with the specific needs of users, to efficiently and accurately generate various document reports has become an urgent problem to be solved. The data generated by the financial big data platform governance needs to be able to generate comprehensive analysis reports. These analysis reports are no longer static documents, but interactive multi-dimensional data displays. For rich, real-time updated data sources such as the financial big data platform, it is necessary to quickly generate a large number of high-quality document reports and ensure the accuracy and reliability of the reports. The application effect of the above technical solutions is not good.

发明内容Summary of the invention

本发明提供基于数据处理结果及模板的文档报告生成方法及系统,旨在解决现有技术不适用于实时更新的数据源的问题。The present invention provides a document report generation method and system based on data processing results and templates, aiming to solve the problem that the prior art is not suitable for real-time updated data sources.

为解决上述技术问题,本发明提出的文档报告生成方法包括以下步骤:In order to solve the above technical problems, the document report generation method proposed in the present invention comprises the following steps:

S1:采集财政大数据平台的数据,保存作为动态数据;S1: Collect data from the financial big data platform and save it as dynamic data;

S2:根据用户提交的文档渲染请求中对应的文档报告类型参数,从模板库中获取需要渲染的模板文件;S2: Obtain the template file to be rendered from the template library according to the document report type parameter corresponding to the document rendering request submitted by the user;

S3:通过poi解析提取所述模板文件中特定标记的内容作为指标的引用,并结合用户提交的变量,从所述动态数据中获取实时数据对模板文件进行渲染;S3: extracting the content of the specific mark in the template file as the reference of the indicator through poi parsing, and obtaining real-time data from the dynamic data to render the template file in combination with the variables submitted by the user;

对模板文件进行渲染具体为:枚举模板文件中所有的占位标签,根据占位标签从动态数据中获取数据对相应的占位标签进行渲染填充;Rendering the template file specifically includes: enumerating all placeholder tags in the template file, obtaining data from dynamic data according to the placeholder tags, and rendering and filling the corresponding placeholder tags;

S4:将渲染完成的模板文件转换成pdf格式的文档报告并返回用户端。S4: Convert the rendered template file into a document report in PDF format and return it to the user end.

优选地,还包括步骤S5:保存步骤S4转换生成的pdf文件。Preferably, the method further comprises step S5: saving the pdf file generated by conversion in step S4.

优选地,所述数据大数据平台包括指标层,所述指标层中包括数据库,所述数据库用于保存经数据治理处理后的财政大数据。Preferably, the data big data platform includes an indicator layer, and the indicator layer includes a database, and the database is used to store financial big data after data governance processing.

优选地,所述动态数据的格式为json或数据库。Preferably, the format of the dynamic data is json or database.

优选地,所述模板库接收的模板包括html文件及docx文档,接收的模板类型为docx文档时,则直接获取作为模板文件保存;接收的模板类型为html文件时,则读取预先配置的图表配置,将html文件转换为docx文档作为模板文件保存。Preferably, the templates received by the template library include html files and docx documents. When the received template type is a docx document, it is directly obtained and saved as a template file; when the received template type is an html file, the pre-configured chart configuration is read, and the html file is converted into a docx document and saved as a template file.

优选地,所述占位标签包括文本标签及图表标签。Preferably, the placeholder label includes a text label and a graphic label.

优选地,渲染所述文本标签时,根据标签从实时数据中获取对应的文本内容,使用所述文本内容替换对应的文本标签。Preferably, when rendering the text label, corresponding text content is obtained from real-time data according to the label, and the corresponding text label is replaced with the text content.

优选地,所述图表标签在渲染时,首先查询图表配置,然后使用poi清空标签的段落,添加新的空段落,继续用poi根据读取到的配置和数据插入图表结构。Preferably, when rendering, the chart tag first queries the chart configuration, then uses poi to clear the paragraphs of the tag, adds a new empty paragraph, and continues to use poi to insert the chart structure according to the read configuration and data.

相应的,本发明还提出基于数据处理结果及模板的文档报告生成系统,所述系统执行上述的文档报告生成方法,包括服务端和用户端;Correspondingly, the present invention also proposes a document report generation system based on data processing results and templates, wherein the system executes the above-mentioned document report generation method, and comprises a server and a user;

服务端进一步包括:The server further includes:

数据采集模块,用于采集财政大数据平台的数据,并对数据进行治理后保存至数据库模块;The data collection module is used to collect data from the financial big data platform and save the data to the database module after data management;

存储模块,所述存储模块接收并保存docx格式的模板文件及pdf格式的文档报告;A storage module, the storage module receives and saves the template file in docx format and the document report in pdf format;

数据库模块,所述数据库模块保存有经数据治理处理后的财政大数据,用于文档渲染时提供动态数据;A database module, which stores financial big data after data governance and is used to provide dynamic data when rendering documents;

文档渲染模块,根据用户渲染参数从存储模块中获取模板文件以及从数据库模块中获取渲染参数对应的实时数据,使用实时数据对模板文件进行渲染生成pdf格式的文档报告;The document rendering module obtains the template file from the storage module and the real-time data corresponding to the rendering parameters from the database module according to the user rendering parameters, and uses the real-time data to render the template file to generate a document report in PDF format;

用户端进一步包括:The user terminal further comprises:

用户交互模块,用于向用户提供交互界面,构建用户渲染参数提交至文档渲染模块,还用于向用户展示渲染完成的文档报告。The user interaction module is used to provide an interactive interface to the user, construct user rendering parameters and submit them to the document rendering module, and also to display the rendered document report to the user.

优选地,所述文档报告生成系统还包括文件转换模块,用于接收html格式的模板后转换为docx文档格式的模板文件,提交至存储模块进行保存。Preferably, the document report generation system further comprises a file conversion module, which is used for receiving a template in html format and converting it into a template file in docx document format, and submitting it to the storage module for storage.

与现有技术相比,本发明具有以下技术效果:Compared with the prior art, the present invention has the following technical effects:

1.本发明提出的文档报告生成方法通过预定义的模板和数据进行文档的渲染,能够方便的对治理成果完成文档化的产出,通过自动化流程,减少了手动操作的时间和错误,能够快速生成大量高质量的文档报告,通过POI解析和数据填充,确保每个占位标签都能被正确的数据填充,避免了手动数据输入可能带来的错误,提高报告的准确性和可靠性。1. The document report generation method proposed in the present invention renders documents through predefined templates and data, which can conveniently complete the documented output of governance results. Through automated processes, it reduces the time and errors of manual operations, and can quickly generate a large number of high-quality document reports. Through POI parsing and data filling, it ensures that each placeholder tag can be filled with correct data, avoiding errors that may be caused by manual data input, and improving the accuracy and reliability of the report.

2.本发明提出的文档报告生成方法通过采集财政大数据平台的数据,确保报告中的数据是最新的,能够反映当前的实际情况,获取最新的财政数据生成实时报告。2. The document report generation method proposed in the present invention collects data from the financial big data platform to ensure that the data in the report is the latest and can reflect the current actual situation, and obtains the latest financial data to generate a real-time report.

3.本发明提出的文档报告生成方法可以根据用户提交的报告类型选择合适的模板,满足不同类型报告的需求,提高文档生成的灵活性和适应性,提高文档的定制化能力。3. The document report generation method proposed in the present invention can select a suitable template according to the report type submitted by the user, meet the needs of different types of reports, improve the flexibility and adaptability of document generation, and improve the customization capability of the document.

4.本发明提出的文档报告生成系统包括服务端和用户端,服务端进一步包括数据采集模块、存储模块、数据库模块、文档渲染模块,用户端进一步包括用户交互模块;将服务渲染全部集中到服务端,在线提交渲染请求后,所有渲染操作都在服务端渲染完成,不再需要安装本地客户端,生成的文档在服务端进行维护,使用维护便捷;同时模板和逻辑表达式统一存储,可方便快捷地进行更新维护。4. The document report generation system proposed in the present invention includes a server and a user end. The server further includes a data acquisition module, a storage module, a database module, and a document rendering module. The user end further includes a user interaction module. All service renderings are concentrated on the server. After the rendering request is submitted online, all rendering operations are completed on the server. There is no need to install a local client. The generated documents are maintained on the server, which is convenient to use and maintain. At the same time, templates and logical expressions are stored in a unified manner, which can be updated and maintained conveniently and quickly.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

图1是本发明所述生成方法的流程示意图;FIG1 is a schematic flow chart of the generation method of the present invention;

图2是本发明实施例所述指标层返回结果示意图;FIG2 is a schematic diagram of the indicator layer return result according to an embodiment of the present invention;

图3是本发明实施例所述模板文件中占位标签示意图;FIG3 is a schematic diagram of a placeholder tag in a template file according to an embodiment of the present invention;

图4是本发明实施例所述渲染完成的文档报告示意图。FIG. 4 is a schematic diagram of a document report after rendering according to an embodiment of the present invention.

具体实施方式DETAILED DESCRIPTION

为使本发明的目的、技术方案和优点更加清楚,下面将结合本申请具体实施例,并参照附图,对本发明的技术方案进行清楚、完整地描述。In order to make the objectives, technical solutions and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in combination with specific embodiments of the present application and with reference to the accompanying drawings.

实施例一Embodiment 1

如图1所示,本实施例为基于数据处理结果及模板的文档报告生成方法,包括以下步骤:As shown in FIG1 , this embodiment is a document report generation method based on data processing results and templates, comprising the following steps:

S1:采集财政大数据平台的数据,保存作为动态数据。S1: Collect data from the financial big data platform and save it as dynamic data.

所述数据大数据平台包括指标层,所述指标层中包括数据库,所述数据库用于保存经数据治理处理后的财政大数据。本实施例的指标层是指财政数据在治理后能直接提供给大屏、文档等直接引用的结果的逻辑分层概念。这些治理的结果会保存进指标层的库中,指标层的库结构就是普通的二维表。指标层对外提供指标接口,指标接口通过接收参数将参数先通过模板引擎替换sql语句中的变量,实现动态的查询治理结果数据。一个指标层的库结构示例如某地的库款余额预测数据,为一个二维表结构,其字段包括MOF_DIV_CODE(指财政区划代码)、MOF_DIV_NAME(指财政区划名称)、日期、真实值、预测值、偏差,其中包括若干记录,组成一段时间范围内的库款余额动态数据。The data big data platform includes an indicator layer, and the indicator layer includes a database, and the database is used to store financial big data after data governance processing. The indicator layer of this embodiment refers to the logical hierarchical concept of the results that financial data can be directly provided to large screens, documents, etc. for direct reference after governance. These governance results will be saved in the library of the indicator layer, and the library structure of the indicator layer is an ordinary two-dimensional table. The indicator layer provides an indicator interface to the outside, and the indicator interface replaces the parameters in the SQL statement through the template engine by receiving parameters to achieve dynamic query governance result data. An example of the library structure of an indicator layer is the forecast data of the treasury balance in a certain place, which is a two-dimensional table structure, and its fields include MOF_DIV_CODE (referring to the fiscal division code), MOF_DIV_NAME (referring to the fiscal division name), date, actual value, forecast value, deviation, including a number of records, which constitute the dynamic data of the treasury balance within a period of time.

在本实施例中,动态数据是通过sql从指标层的库中查询出来的结果,查询结果使用json格式或数据库进行保存,本实施例的一个指标层查询返回结果如图2所示。In this embodiment, the dynamic data is the result of querying from the library of the indicator layer through SQL, and the query result is saved in JSON format or database. An indicator layer query return result of this embodiment is shown in Figure 2.

在本发明的其他实施例中,动态数据使用数据库表保存,且根据一定周期从财政大数据平台更新。In other embodiments of the present invention, dynamic data is stored using a database table and updated from the financial big data platform according to a certain period.

具体的,在本实施例中,指标层提供指标接口,指标接口提供的服务区别于渲染服务,指标接口可以和渲染服务处于同一逻辑结构中,也可以不在同一逻辑结构中,它向外暴露http接口为其他服务提供查询指标数据的接口。Specifically, in this embodiment, the indicator layer provides an indicator interface. The service provided by the indicator interface is different from the rendering service. The indicator interface can be in the same logical structure as the rendering service or not. It exposes an http interface to provide an interface for other services to query indicator data.

S2:根据用户提交的文档渲染请求中对应的文档报告类型参数,从模板库中获取需要渲染的模板文件。S2: According to the document report type parameter corresponding to the document rendering request submitted by the user, the template file to be rendered is obtained from the template library.

在本实施例中,用户前期创建的模板文件类型包括docx文档及html文件,因此,模板库接收的模板类型为docx文档时,则直接获取作为模板文件保存;接收的模板类型为html文件时,则读取预先配置的图表配置,将html文件转换为docx文档作为模板文件保存。将html文件转换为docx文档后,还将转换生成的docx文档保存至模板库中。后续使用该类型模板时,便可直接使用模板库中的docx文档,而不再需要读取html文件并转换为docx文档。In this embodiment, the template file types created by the user in the early stage include docx documents and html files. Therefore, when the template type received by the template library is a docx document, it is directly obtained and saved as a template file; when the template type received is an html file, the pre-configured chart configuration is read, and the html file is converted into a docx document and saved as a template file. After converting the html file to a docx document, the converted docx document is also saved in the template library. When using this type of template later, the docx document in the template library can be directly used without reading the html file and converting it into a docx document.

由于前端引入的图表是js动态绘制的,无法直接转换为word中的图表。因此,在对html文件进行转换时,首先将html文件分离成文本性内容元素和图表配置信息两部分,然后将文本性元素转换为docx模板保存,图表配置信息则保存至图表配置信息库;所述图表配置信息用于后续渲染时根据该图表配置信息对图表部分进行渲染。单独提取出的图表配置信息在渲染时用poi按照配置信息添加指定的元素、样式和数据。Since the chart introduced by the front end is dynamically drawn by js, it cannot be directly converted into a chart in word. Therefore, when converting the HTML file, the HTML file is first separated into two parts: text content elements and chart configuration information, and then the text elements are converted into docx templates and saved, and the chart configuration information is saved to the chart configuration information library; the chart configuration information is used for subsequent rendering to render the chart part according to the chart configuration information. When rendering, the separately extracted chart configuration information uses poi to add the specified elements, styles and data according to the configuration information.

在本发明的一些实施例中,可使用Pandoc、Mammoth、Aspose.Words等库或工具将html文件转换为docx文档。在本发明的其他实施例中,还可通过BeautifulSoup库及python-docx库来实现,使用python-docx库来创建和操作docx文档,然后使用BeautifulSoup库来解析html文件,再根据html内容的结构,逐一将内容添加到docx文档中。In some embodiments of the present invention, the html file can be converted into a docx document using libraries or tools such as Pandoc, Mammoth, Aspose.Words, etc. In other embodiments of the present invention, it can also be implemented by using the BeautifulSoup library and the python-docx library, using the python-docx library to create and operate the docx document, and then using the BeautifulSoup library to parse the html file, and then adding the content to the docx document one by one according to the structure of the html content.

S3:通过poi解析提取所述模板文件中特定标记的内容作为指标的引用,并结合用户提交的变量,从所述动态数据中获取实时数据对模板文件进行渲染;对模板文件进行渲染具体为:枚举模板文件中所有的占位标签,根据占位标签从动态数据中获取数据对相应的占位标签进行渲染填充。S3: extracting the content of specific tags in the template file as a reference to the indicator through poi parsing, and obtaining real-time data from the dynamic data to render the template file in combination with the variables submitted by the user; rendering the template file specifically includes: enumerating all placeholder tags in the template file, obtaining data from the dynamic data according to the placeholder tags, and rendering and filling the corresponding placeholder tags.

上述poi指基于OOXML、OLE2标准的Apache POI,Apache POI是用Java编写的免费开源的跨平台的Java API,Apache POI提供API给Java程序对Microsoft Office格式档案读和写的功能。POI为“Poor Obfuscation Implementation”的首字母缩写,意为“简洁版的模糊实现”。The above poi refers to Apache POI based on OOXML and OLE2 standards. Apache POI is a free, open source, cross-platform Java API written in Java. Apache POI provides APIs for Java programs to read and write Microsoft Office format files. POI is the acronym for "Poor Obfuscation Implementation", which means "a simplified version of fuzzy implementation".

所述占位标签包括文本标签及图表标签。如图3所示,为本实施例所述文本标签类型的占位标签示意图,其中以“{{”开头并以“}}”结尾的字符串即为占位标签,如图3所示的“{{_3}}”、“{{_5}”、“{{_6}}”、“{{_7}}”、“{{_8}}”、“{{_9}}”、“{{_10}}”、“{{_11}}”。The placeholder label includes a text label and a chart label. As shown in FIG3 , it is a schematic diagram of a placeholder label of the text label type described in this embodiment, wherein a string starting with “{{” and ending with “}}” is a placeholder label, such as “{{_3}}”, “{{_5}”, “{{_6}}”, “{{_7}}”, “{{_8}}”, “{{_9}}”, “{{_10}}”, and “{{_11}}” as shown in FIG3 .

在本实施例中,“{{”和“}}”之间可以是数字、字母、汉字、点、下划线构成的标签。具体的,后台接口在接受到渲染请求以后,通过解析渲染请求中的参数在模板库中找到需要渲染的模板文件,读取模板文件的内容以后,通过正则表达式提取文件中的标签,遍历这些标签内容提取出所引用的指标名称。例如“{{文字样式.标题1}}”,这个标签就是文字类型的标签,“文字样式.标题1”就是指标名称,对应于数据库表保存的动态数据,引用的实际数据是名为“文字样式”这个指标层的sql查询结果中的“标题1”列对应的动态数据。将提取的指标名称和用户提交的参数一起发送给指标接口;指标接口接收到请求以后,通过参数查询到指定指标的sql和其中变量的默认值,用请求中携带的参数覆盖变量的默认值后和sql文本交由模板引擎计算出最终的sql结果,执行这个结果sql获取所需要的实时数据返回给文档渲染模块。In this embodiment, the tags between "{{" and "}}" can be numbers, letters, Chinese characters, dots, and underscores. Specifically, after receiving the rendering request, the background interface finds the template file to be rendered in the template library by parsing the parameters in the rendering request, and after reading the content of the template file, extracts the tags in the file through regular expressions, and traverses these tag contents to extract the referenced indicator name. For example, "{{Text Style.Title 1}}", this tag is a text type tag, and "Text Style.Title 1" is the indicator name, which corresponds to the dynamic data stored in the database table. The actual data referenced is the dynamic data corresponding to the "Title 1" column in the sql query result of the indicator layer named "Text Style". The extracted indicator name is sent to the indicator interface together with the parameters submitted by the user; after receiving the request, the indicator interface queries the sql of the specified indicator and the default values of the variables therein through the parameters, and after overwriting the default values of the variables with the parameters carried in the request, the template engine calculates the final sql result with the sql text, executes this result sql to obtain the required real-time data and returns it to the document rendering module.

对应于json格式的动态数据,在渲染时将json格式的动态数据转换为map结构,使用从标签内容中提取出的指标名称及键名在map数据中进行匹配,将匹配后的值填充至对应的标签上。Corresponding to the dynamic data in json format, the dynamic data in json format is converted into a map structure during rendering, the indicator name and key name extracted from the tag content are used to match in the map data, and the matched value is filled into the corresponding tag.

渲染所述文本标签时,根据标签从实时数据中获取对应的文本内容,使用所述文本内容替换对应的文本标签。如图3中的“{{_3}}”指的是地区名,因此根据用户发送的渲染请求中对应的地区名或地区代码,在动态数据中检索出对应的地区名称,使用检索到的地区名称替换“{{_3}}”,生成如“山东省”、“四川省”、“临沂市”等具体地区名称;其他标签如“{{_5}”、“{{_6}}”、“{{_7}}”、“{{_8}}”、“{{_9}}”、“{{_10}}”、“{{_11}}”,也分别从动态数据中获取对应的实时数据进行替换填充,最终形成如图4所示渲染结果。When rendering the text label, the corresponding text content is obtained from the real-time data according to the label, and the corresponding text label is replaced with the text content. As shown in Figure 3, "{{_3}}" refers to the region name, so according to the corresponding region name or region code in the rendering request sent by the user, the corresponding region name is retrieved in the dynamic data, and the retrieved region name is used to replace "{{_3}}" to generate specific region names such as "Shandong Province", "Sichuan Province", "Linyi City", etc.; other labels such as "{{_5}", "{{_6}}", "{{_7}}", "{{_8}}", "{{_9}}", "{{_10}}", "{{_11}}" also obtain the corresponding real-time data from the dynamic data for replacement and filling, and finally form the rendering result shown in Figure 4.

所述图表标签在渲染时,首先查询图表配置,然后使用poi清空标签的段落,添加新的空段落,继续用poi根据读取到的配置和数据插入图表结构。When rendering, the chart tag first queries the chart configuration, then uses poi to clear the paragraphs of the tag, adds a new empty paragraph, and continues to use poi to insert the chart structure according to the read configuration and data.

查询图标配置时,首先构建sql查询得到的二维表数据,通过配置横纵坐标、颜色、图例等配置后生成图表。首先读取数据,将数据存储在内存中,例如一个List<Map<String,String>>,每个Map表示一行数据。然后读取图表配置,图表配置文件可以是JSON、XML等格式的配置文件,使用相应的库读取配置文件,例如使用Gson或Jackson库读取JSON文件。再将图表配置存储在一个专用的配置类中,例如ChartConfig类,包含图表的标题、轴标签、横纵坐标、颜色、图例等信息。接着使用Apache POI库的XWPFDocument类打开docx文档,读取现有文档内容,遍历文档中的所有段落,查找包含特定图表标签的段落,找到包含标签的段落后,清空其内容,以便后续插入新内容。在清空的段落位置插入新的段落,可以创建一个新的XWPFParagraph。根据数据创建图表的数据源,例如条形图的类别和数值数据,根据配置文件设置图表的标题、轴标签等,将创建好的图表插入到新段落中。最后使用XWPFDocument类的write方法将文档保存到指定路径。如图3、4所示,图3中的图表为模板文件中的模板图表,经过渲染被替换为图4所示的图表。When querying the icon configuration, first build the two-dimensional table data obtained by the SQL query, and generate the chart by configuring the horizontal and vertical coordinates, colors, legends and other configurations. First read the data and store the data in memory, such as a List<Map<String,String>>, where each Map represents a row of data. Then read the chart configuration. The chart configuration file can be a configuration file in JSON, XML and other formats. Use the corresponding library to read the configuration file, such as using the Gson or Jackson library to read the JSON file. Then store the chart configuration in a dedicated configuration class, such as the ChartConfig class, which contains the chart title, axis labels, horizontal and vertical coordinates, colors, legends and other information. Then use the XWPFDocument class of the Apache POI library to open the docx document, read the existing document content, traverse all paragraphs in the document, find the paragraph containing the specific chart tag, and after finding the paragraph containing the tag, clear its content so that new content can be inserted later. Insert a new paragraph at the position of the cleared paragraph to create a new XWPFParagraph. Create a data source for the chart based on the data, such as the category and numerical data of the bar chart, set the chart title, axis labels, etc. according to the configuration file, and insert the created chart into a new paragraph. Finally, use the write method of the XWPFDocument class to save the document to the specified path. As shown in Figures 3 and 4, the chart in Figure 3 is a template chart in the template file, which is replaced by the chart shown in Figure 4 after rendering.

S4:将渲染完成的模板文件转换成pdf格式的文档报告并返回用户端,生成的PDF文档格式具有良好的兼容性和稳定性,方便存档和分享。S4: Convert the rendered template file into a document report in PDF format and return it to the user. The generated PDF document format has good compatibility and stability, which is convenient for archiving and sharing.

在本发明的其他实施例中,文档报告生成方法还包括步骤S5:保存步骤S4转换生成的pdf文件至文件服务器完成归档操作,归档生成文件到文件服务器方便在线管理。In other embodiments of the present invention, the document report generation method further includes step S5: saving the pdf file converted and generated in step S4 to a file server to complete the archiving operation, and archiving the generated file to the file server facilitates online management.

实施例二Embodiment 2

基于数据处理结果及模板的文档报告生成系统,所述系统执行如实施例一所述的文档报告生成方法,包括服务端和用户端。A document report generation system based on data processing results and templates, wherein the system executes the document report generation method as described in the first embodiment, includes a server and a user.

服务端进一步包括:The server further includes:

数据采集模块,用于采集财政大数据平台的数据,并对数据进行治理后保存至数据库模块;所述数据大数据平台包括指标层,所述指标层中包括数据库,所述数据库用于保存经数据治理处理后的财政大数据。本实施例的指标层是指财政数据在治理后能直接提供给大屏、文档等直接引用的结果的逻辑分层概念。这些治理的结果会保存进指标层的库中,指标层的库结构就是普通的二维表。指标层对外提供指标接口,指标接口通过接收参数将参数先通过模板引擎替换sql语句中的变量,实现动态的查询治理结果数据。The data collection module is used to collect data from the financial big data platform, and save the data to the database module after data governance; the data big data platform includes an indicator layer, and the indicator layer includes a database, and the database is used to save the financial big data after data governance. The indicator layer of this embodiment refers to the logical hierarchical concept of the results that financial data can be directly provided to large screens, documents, etc. for direct reference after governance. These governance results will be saved in the library of the indicator layer, and the library structure of the indicator layer is an ordinary two-dimensional table. The indicator layer provides an indicator interface to the outside world. The indicator interface receives parameters and replaces the parameters with variables in the sql statement through the template engine to realize dynamic query governance result data.

存储模块,所述存储模块接收并保存docx格式的模板文件及pdf格式的文档报告,对pdf格式的文档报告进行存储归档,方便在线管理。A storage module receives and saves template files in docx format and document reports in pdf format, and stores and archives document reports in pdf format to facilitate online management.

由于用户提交的模板文件包括html文件及docx文档,由于存储模块只是保存docx格式的模板文件,因此需要人工介入将html文件保存转换为docx文档后提交到存储模块进行保存。在本发明的一个优选实施例中,还设置有一文件转换模块,用于接收html格式的模板后转换为docx文档格式的模板文件,提交至存储模块进行保存,用户可提交html格式或docx格式的模板,由文件转换模块进行识别,若用户提交的模板为docx格式,则直接提交至存储模块进行保存,若用户提交的模板为html格式,则调用相应的库对html格式文件进行转换,转换为docx格式后提交至存储模块进行保存。Since the template files submitted by the user include html files and docx documents, and since the storage module only saves template files in docx format, manual intervention is required to save and convert the html files into docx documents and then submit them to the storage module for storage. In a preferred embodiment of the present invention, a file conversion module is also provided, which is used to receive a template in html format and convert it into a template file in docx document format, and submit it to the storage module for storage. The user can submit a template in html format or docx format, which will be identified by the file conversion module. If the template submitted by the user is in docx format, it will be directly submitted to the storage module for storage. If the template submitted by the user is in html format, the corresponding library will be called to convert the html format file, and after converting it to docx format, it will be submitted to the storage module for storage.

数据库模块,所述数据库模块保存有经数据治理处理后的财政大数据,用于文档渲染时提供动态数据。The database module stores financial big data that has been processed by data governance and is used to provide dynamic data when rendering documents.

文档渲染模块,根据用户渲染参数从存储模块中获取模板文件以及从数据库模块中获取渲染参数对应的实时数据,使用实时数据对模板文件进行渲染生成pdf格式的文档报告。具体的,文档渲染模块通过poi解析提取所述模板文件中特定标记的内容作为指标的引用,并结合用户提交的变量,从所述动态数据中获取实时数据对模板文件进行渲染;对模板文件进行渲染具体为:枚举模板文件中所有的占位标签,根据占位标签从动态数据中获取数据对相应的占位标签进行渲染填充。The document rendering module obtains the template file from the storage module and the real-time data corresponding to the rendering parameters from the database module according to the user rendering parameters, and uses the real-time data to render the template file to generate a document report in PDF format. Specifically, the document rendering module extracts the content of the specific mark in the template file as the reference of the indicator through poi analysis, and obtains the real-time data from the dynamic data to render the template file in combination with the variables submitted by the user; the rendering of the template file is specifically as follows: enumerate all the placeholder tags in the template file, obtain data from the dynamic data according to the placeholder tags, and render and fill the corresponding placeholder tags.

用户端进一步包括:The user terminal further comprises:

用户交互模块,用于向用户提供交互界面,构建用户渲染参数提交至文档渲染模块,还用于向用户展示渲染完成的文档报告;用户在用户交互模块中请求文件渲染时,可选择模板类型、获取数据的起止时间、地区等参数。其中模板类型参数用于文档渲染模块从存储模块中选择对应的模板文件,获取数据的起止时间及地区参数则用于文档渲染模块从数据库模块中获取对应的实时数据。The user interaction module is used to provide an interactive interface for users, construct user rendering parameters and submit them to the document rendering module, and also to show the rendered document report to users; when users request file rendering in the user interaction module, they can select parameters such as template type, start and end time of data acquisition, and region. The template type parameter is used by the document rendering module to select the corresponding template file from the storage module, and the start and end time and region parameters of data acquisition are used by the document rendering module to obtain the corresponding real-time data from the database module.

在本发明的一个优选实施例中,所述用户交互界面为浏览器页面,采用完全的B/S架构,去除本地生成的客户端,方便用户生成文件,具有良好的用户体验。In a preferred embodiment of the present invention, the user interaction interface is a browser page, which adopts a complete B/S architecture, removes the locally generated client, facilitates users to generate files, and has a good user experience.

以上所述的仅是本发明的优选实施方式,应当指出,对于本领域的普通技术人员来说,在不脱离本发明创造构思的前提下,还可以做出若干变形和改进,这些都属于本发明的保护范围。The above is only a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several modifications and improvements without departing from the inventive concept of the present invention, which all fall within the protection scope of the present invention.

Claims (10)

CN202410746798.8A2024-06-112024-06-11 Document report generation method and system based on data processing results and templatesPendingCN118607500A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202410746798.8ACN118607500A (en)2024-06-112024-06-11 Document report generation method and system based on data processing results and templates

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202410746798.8ACN118607500A (en)2024-06-112024-06-11 Document report generation method and system based on data processing results and templates

Publications (1)

Publication NumberPublication Date
CN118607500Atrue CN118607500A (en)2024-09-06

Family

ID=92562779

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202410746798.8APendingCN118607500A (en)2024-06-112024-06-11 Document report generation method and system based on data processing results and templates

Country Status (1)

CountryLink
CN (1)CN118607500A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US20040221233A1 (en)*2003-04-292004-11-04David ThielenSystems and methods for report design and generation
CN109657215A (en)*2018-09-272019-04-19深圳壹账通智能科技有限公司Document structure tree method, equipment, storage medium and device based on template
CN116227454A (en)*2023-02-282023-06-06易方达基金管理有限公司Universal automatic report generation method and system
CN117131851A (en)*2023-08-282023-11-28福建博思软件股份有限公司 A method to automatically generate a text version of the report
CN117271004A (en)*2023-10-112023-12-22建信金融科技有限责任公司Document report generation method, device, equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US20040221233A1 (en)*2003-04-292004-11-04David ThielenSystems and methods for report design and generation
CN109657215A (en)*2018-09-272019-04-19深圳壹账通智能科技有限公司Document structure tree method, equipment, storage medium and device based on template
CN116227454A (en)*2023-02-282023-06-06易方达基金管理有限公司Universal automatic report generation method and system
CN117131851A (en)*2023-08-282023-11-28福建博思软件股份有限公司 A method to automatically generate a text version of the report
CN117271004A (en)*2023-10-112023-12-22建信金融科技有限责任公司Document report generation method, device, equipment and storage medium

Similar Documents

PublicationPublication DateTitle
CN111178027B (en)Report generation system and method based on online creation template and online specified data
CN111259303B (en)System and method for automatically generating front-end page of WEB information system
US11423042B2 (en)Extracting information from unstructured documents using natural language processing and conversion of unstructured documents into structured documents
US8479093B2 (en)Metamodel-based automatic report generation
US7720885B2 (en)Generating a word-processing document from database content
US11392753B2 (en)Navigating unstructured documents using structured documents including information extracted from unstructured documents
CN108762743A (en)Data table operation code generation method and device
CN103530407A (en)Method and device for generating rich text document
CN107220274A (en)One kind visualization data-interface fairground implementation method
WO2007081017A1 (en)Document processor
CN110347878A (en)A kind of data fusion method of regulation engine driving
CN110308907B (en)Data conversion method and device, storage medium and electronic equipment
CN115934716A (en)Method for importing Excel table data into database based on metadata definition and implementation
CN118466956B (en)Front-end interface generation method based on data standard
CN111796803B (en)Template report generation method based on multi-stage container restocking
CN111930965B (en)Method and system for constructing ontology structure of knowledge graph
CN118607500A (en) Document report generation method and system based on data processing results and templates
CN116303641B (en)Laboratory report management method supporting multi-data source visual configuration
CN117744616A (en) Report generation method, device, electronic equipment and storage medium
JP2024090145A (en) Document data generation device, control method for document data generation device, and document data generation program
CN111767703B (en)Form data acquisition method, device and system
CN115186632A (en) Text production method, device, electronic device and storage medium
CN115859933A (en)Digital certificate service development system and method
CN116522892B (en)Automatic generation method and generation system of report template
KR100307314B1 (en)Method for viewing informap drawing using object representation

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination

[8]ページ先頭

©2009-2025 Movatter.jp