Data conversion method and device and data processing equipment
By creating XML templates and analyzing Excel data, dividing them into different parts, identifying and extracting styles and text data, the automation processing problems caused by the complexity of Excel table data are solved, the integration and unified management of Excel data and structured data are realized, and the efficiency of office automation is improved.
Patent Information
- Application Number
- CN202510184636.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-19
- Publication Date
- 2025-06-06
AI Technical Summary
The format of Excel table data is complex, which leads to cumbersome direct programming analysis and processing, and few automated processing methods, making it difficult to realize the integrated processing of multiple Excel table data and the centralized management of information appending to standardized databases.
By creating an XML template, including style and data parts, analyzing and dividing Excel data into title, header, table body and end data fragments, identifying and extracting the style and text data of each cell, and writing them to the corresponding parts of the XML template respectively.
It realizes the integration and unified management of Excel data and structured data, effectively bridges the difference between the two, ensures smooth connection of data conversion, and improves the efficiency of office automation.
Smart Images

Figure CN120104564A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data processing, and specifically relates to a data conversion method, a device and a data processing equipment. Background Art
[0002] Excel is widely used due to its convenience in data statistics and table printing. However, in actual office work, it is often necessary to integrate the data of multiple Excel tables, or with the improvement of office automation, the information in the tables needs to be appended to other standardized databases to achieve centralized data management.
[0003] However, since the Excel table data format is relatively complex, it is relatively cumbersome to directly parse and process these data through programming, and there are few related automated processing methods. Therefore, a data conversion method, device and data processing equipment are proposed. Summary of the invention
[0004] In order to solve the problems raised in the above background technology, the present invention provides the following technical solutions:
[0005] A data conversion method is provided, the method comprising:
[0006] Creating an XML template, wherein the XML template includes a style part and a data part;
[0007] The style part includes: title, header, body and footer style segments;
[0008] Acquire Excel data to be converted, analyze the Excel data to be converted, divide the Excel data to be converted into data segments corresponding to the style segments of the XML template, and acquire the divided data segments;
[0009] The divided data segments include: title, table header, table body and table footer data segments;
[0010] Identify and extract the style and text data corresponding to each cell in the divided data segments from the divided data segments;
[0011] The styles and text data corresponding to the cells of the title, header and footer data fragments are written into the style part of the XML template respectively; the styles corresponding to the cells of the table body data fragment are written into the style part of the XML template, and the text data corresponding to the table body data fragment are written into the data part of the XML template.
[0012] The specific steps to obtain the Excel data to be converted include:
[0013] Select the tool to load the Excel file according to the working environment and specify the target worksheet to be processed;
[0014] Extract the Excel data to be converted from the target worksheet;
[0015] Wherein, the Excel file contains at least one worksheet.
[0016] The Excel data to be converted includes a first row of data, a second row of data, block data and tail data, the first row of data is a title data segment, the second row of data is a table header data segment, the block data starts with the third row of data and the number of rows increases continuously, the block data is a table body data segment, the number of rows of the tail data is greater than the end of the block data, the length of the tail data is different from the length of the second row of data, and the tail data is a table footer data segment.
[0017] The Excel data to be converted is analyzed, and the Excel data to be converted is divided into data segments corresponding to the style segments of the XML template. The specific steps of obtaining the divided data segments include:
[0018] A pointer is created, the pointer points to the first row of data of the Excel data, the first row of data is divided into title data segments, the pointer moves back one unit and points to the second row of data, the second row of data is divided into table header data segments, the pointer continues to move back one unit, and the length of the pointed data row is judged, if the length is equal to the length of the second row of data, it is divided into table body data segments, if the length is not equal to the length of the second row of data, it is divided into table footer data segments.
[0019] The method of identifying and extracting the style and text data corresponding to each data segment from the divided data segments includes:
[0020] Use openpyxl to extract the cell style from the divided data fragments;
[0021] Use pandas to extract the text data of the cells from the divided data segments.
[0022] The present invention also provides a data conversion device, which is applied to a data processing device, and the device comprises:
[0023] A template creation module, used to create an XML template, wherein the XML template includes a style part and a data part; and
[0024] a first acquisition module, configured to acquire Excel data to be converted, analyze the Excel data to be converted, divide the Excel data to be converted into data segments corresponding to the style segments of the XML template, and acquire the divided data segments; and
[0025] A second acquisition module is used to identify and extract the style and text data corresponding to each cell in the data segment from the divided data segment; and
[0026] The writing module is used to write the styles and text data corresponding to the cells of the title, header and footer data fragments into the style part of the XML template respectively; write the styles corresponding to the cells of the table body data fragment into the style part of the XML template, and write the text data corresponding to the table body data fragment into the data part of the XML template.
[0027] The present invention also provides a data processing device, the data processing device comprising:
[0028] Memory;
[0029] Processor; and
[0030] A data conversion device, comprising the software function module as claimed in claim 6 which can be executed by the processor; the memory stores an Excel file containing at least one worksheet.
[0031] Compared with the prior art, the present invention has the following beneficial effects:
[0032] By analyzing the Excel data format and defining description specifications, an intermediate model was constructed using XML as a semi-structured data model, which achieved the integration and unified management of Excel data and structured data, thereby effectively bridging the gap between the two, ensuring smooth data conversion, and improving the efficiency of office automation. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0034] Figure 1 A flow chart of a data conversion method provided by an embodiment of the present invention;
[0035] Figure 2 This is a schematic diagram of an Excel file to be converted obtained according to an embodiment of the present invention;
[0036] Figure 3 A schematic diagram of converting Excel data into XML data according to an embodiment of the present invention; DETAILED DESCRIPTION
[0037] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0038] Depend on Figure 1 It is given that an embodiment of the present invention provides a data conversion method, the method comprising:
[0039] Step S1, creating an XML template, wherein the XML template includes a style part and a data part;
[0040] The style part includes: title, header, body and footer style segments;
[0041] Step S2, obtaining Excel data to be converted, analyzing the Excel data to be converted, dividing the Excel data to be converted into data segments corresponding to the style segments of the XML template, and obtaining the divided data segments;
[0042] The divided data segments include: title, table header, table body and table footer data segments;
[0043] Step S3, identifying and extracting the style and text data corresponding to each cell in the divided data segments;
[0044] Step S4, write the styles and text data corresponding to the cells of the title, header and footer data segments into the style part of the XML template respectively; write the styles corresponding to the cells of the table body data segment into the style part of the XML template, and write the text data corresponding to the table body data segment into the data part of the XML template.
[0045] In this embodiment, the specific steps of obtaining the Excel data to be converted include:
[0046] Step S21, select a tool to load the Excel file according to the working environment, and specify the target worksheet to be processed;
[0047] For example, the working environment can be Java or Python. In Java environment, you can use Apache POI library to load Excel files; in Python environment, you can use pandas library to load Excel files;
[0048] When loading the target worksheet, you can specify it by the index or name of the target worksheet.
[0049] Step S22, extracting the Excel data to be converted from the target worksheet;
[0050] Wherein, the Excel file contains at least one worksheet.
[0051] In this embodiment, the Excel data to be converted includes a first row of data, a second row of data, block data and tail data, the first row of data is a title data segment, the second row of data is a header data segment, the block data starts with the third row of data and the number of rows increases continuously, the block data is a table body data segment, the number of rows of the tail data is greater than the end of the block data, the length of the tail data is different from the length of the second row of data, and the tail data is a table footer data segment; wherein, there is only one row of data in the header data segment, the text data in each cell in the header data segment is represented as the attribute of the corresponding cell in the body data segment, each row of data in the body data segment is represented as an entity, and each cell in the data row is a specific parameter of the corresponding attribute.
[0052] In this embodiment, the Excel data to be converted is analyzed and divided into data segments corresponding to the style segments of the XML template. The specific steps of obtaining the divided data segments include:
[0053] Step S23, create a pointer, the pointer points to the first row of data of the Excel data, divide the first row of data into title data segments, the pointer moves back one unit and points to the second row of data, divides the second row of data into table header data segments, the pointer continues to move back one unit, and judges the length of the pointed data row, if the length is equal to the length of the second row of data, it is divided into table body data segments, if the length is not equal to the length of the second row of data, it is divided into table footer data segments.
[0054] In this embodiment, the method of identifying and extracting the style and text data corresponding to each data segment from the divided data segments includes:
[0055] Step S31, using openpyxl to extract the style of the cell from the divided data fragments;
[0056] Step S32: Use pandas to extract the text data of the cells from the divided data segments.
[0057] like Figure 2As shown, the target worksheet is obtained according to the index or name of the Excel file to be converted, and the obtained target worksheet is divided into title, header, body and footer data segments. The title provided in the table shown is the first row of data "employee information", the header is the second row of data "name, age, gender, department", the block data from the third to fifth rows is the body data segment, the length of the sixth row of data is not equal to the length of the body data segment, and the sixth row of data is divided into the footer data segment.
[0058] like Figure 3 As shown, when writing Excel data into the XML template, only the text data in each cell of the table body data fragment is written into the XML template to facilitate modification.
[0059] The present invention also provides a data processing device, the device comprising:
[0060] A template creation module, used to create an XML template, wherein the XML template includes a style part and a data part; and
[0061] a first acquisition module, configured to acquire Excel data to be converted, analyze the Excel data to be converted, divide the Excel data to be converted into data segments corresponding to the style segments of the XML template, and acquire the divided data segments; and
[0062] A second acquisition module is used to identify and extract the style and text data corresponding to each cell in the data segment from the divided data segment; and
[0063] The writing module is used to write the styles and text data corresponding to the cells of the title, header and footer data fragments into the style part of the XML template respectively; write the styles corresponding to the cells of the table body data fragment into the style part of the XML template, and write the text data corresponding to the table body data fragment into the data part of the XML template.
[0064] The present invention also provides a data processing device, the data processing device comprising:
[0065] Memory;
[0066] Processor; and
[0067] The data conversion device comprises a software function module as described above that can be executed by the processor; the memory stores an Excel file containing at least one worksheet.
[0068] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0069] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A data conversion method, characterized in that: The method comprises: Creating an XML template, wherein the XML template includes a style part and a data part; The style part includes: title, header, body and footer style segments; Acquire Excel data to be converted, analyze the Excel data to be converted, divide the Excel data to be converted into data segments corresponding to the style segments of the XML template, and acquire the divided data segments; The divided data segments include: title, table header, table body and table footer data segments; Identify and extract the style and text data corresponding to each cell in the divided data segments from the divided data segments; The styles and text data corresponding to the cells of the title, header and footer data fragments are written into the style part of the XML template respectively; the styles corresponding to the cells of the table body data fragment are written into the style part of the XML template, and the text data corresponding to the table body data fragment are written into the data part of the XML template.
2. The method according to claim 1, characterized in that: The specific steps to obtain the Excel data to be converted include: Select the tool to load the Excel file according to the working environment and specify the target worksheet to be processed; Extract the Excel data to be converted from the target worksheet; Wherein, the Excel file contains at least one worksheet.
3. The method according to claim 2, characterized in that: The Excel data to be converted includes a first row of data, a second row of data, block data and tail data, the first row of data is a title data segment, the second row of data is a table header data segment, the block data starts with the third row of data and the number of rows increases continuously, the block data is a table body data segment, the number of rows of the tail data is greater than the end of the block data, the length of the tail data is different from the length of the second row of data, and the tail data is a table footer data segment.
4. The method according to claim 3, characterized in that: The Excel data to be converted is analyzed, and the Excel data to be converted is divided into data segments corresponding to the style segments of the XML template. The specific steps of obtaining the divided data segments include: A pointer is created, the pointer points to the first row of data of the Excel data, the first row of data is divided into title data segments, the pointer moves back one unit and points to the second row of data, the second row of data is divided into table header data segments, the pointer continues to move back one unit, and the length of the pointed data row is judged, if the length is equal to the length of the second row of data, it is divided into table body data segments, if the length is not equal to the length of the second row of data, it is divided into table footer data segments.
5. The method according to claim 1, characterized in that: The method of identifying and extracting the style and text data corresponding to each data segment from the divided data segments includes: Use openpyxl to extract the cell style from the divided data fragments; Use pandas to extract the text data of the cells from the divided data segments.
6. A data conversion device, applied to a data processing device, characterized in that: The device comprises: A template creation module, used to create an XML template, wherein the XML template includes a style part and a data part; and a first acquisition module, configured to acquire Excel data to be converted, analyze the Excel data to be converted, divide the Excel data to be converted into data segments corresponding to the style segments of the XML template, and acquire the divided data segments; and A second acquisition module is used to identify and extract the style and text data corresponding to each cell in the data segment from the divided data segment; and The writing module is used to write the styles and text data corresponding to the cells of the title, header and footer data fragments into the style part of the XML template respectively; write the styles corresponding to the cells of the table body data fragment into the style part of the XML template, and write the text data corresponding to the table body data fragment into the data part of the XML template.
7. A data processing device, characterized in that: The data processing device comprises: Memory; Processor; and A data conversion device, comprising the software function module as claimed in claim 6 which can be executed by the processor; the memory stores an Excel file containing at least one worksheet.