Method and device for converting Excel document into Word document and medium
This method uses Python to process Excel document data and generate Word documents, solving the problems of long processing time and low efficiency in traditional methods, and achieving efficient document conversion and standardized Word test document generation.
Patent Information
- Application Number
- CN202511097077.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-06
- Publication Date
- 2025-11-07
AI Technical Summary
Traditional methods for converting Excel documents to Word documents are time-consuming and inefficient, especially when the Excel document has many data fields and the Word template changes frequently. This requires reselecting the data source and redefining the template, which increases the conversion time and workload.
This program uses Python to extract data from an Excel test document into memory, assembles the list structure data according to preset rules, selects the corresponding Word template to populate the data, and generates a Word test document through a template engine and loop control tags.
It simplifies complex document conversion tasks, saves time in writing test documents, improves work efficiency, and standardizes Word test documents.
Smart Images

Figure CN120911409A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of software testing, and particularly relates to an Excel document to Word document conversion method, device and medium. BACKGROUND
[0002] In the field of software testing, when testers understand and analyze software requirement specifications, extract test points, write test cases and execute test cases, they use Excel to compile test case elements such as requirement name, case number, case title, module, importance level, precondition, test data, operation steps and expected result, and finally output test case electronic documents. The current method is simple and efficient. In the process of software test document generation, Excel and Word are the most commonly used bearing methods. Excel is used to write test cases, and Word is used to write software test instructions, software test records and software test reports. Among them, the Word-related test documents are in formal written form. In this process, the Excel document needs to be converted into a specific form of Word document according to certain rules and requirements.
[0003] The traditional method of converting Excel documents to Word documents is to use the "mail merge" function in Microsoft Office Word to fill in Excel data to the Word template to complete the conversion. This method is relatively easy to complete for Excel to Word document conversion with fixed templates and simple data fields. However, when the number of data fields in the Excel document increases and the Word template frequently changes, the data source needs to be reselected and the template needs to be redefined every time the conversion is generated, and the conversion time will gradually increase. For the converted Word document, the tester needs to carry out format modification and document integration. If the number of test cases is large, this work will consume a lot of time, and the required Word test document cannot be generated at one time, and the efficiency needs to be improved. SUMMARY
[0004] In order to solve the problem of long time consumption and low efficiency of the traditional Excel document to Word document conversion method, the application provides an Excel document to Word document conversion method, device and medium. The data in the Excel test document is extracted into the memory by using Python, and then the list structure data of different types of test documents is assembled according to the preset rules, and the corresponding Word template is selected to fill in the data to complete the conversion and generation of the Word test document, solving the problems of long time consumption, large workload and low efficiency of the traditional conversion method.
[0005] The application is implemented by the following technical solutions: An Excel document to Word document conversion method, comprising: Judge whether the user selects the generated Word test document type, if so, continue to execute the subsequent steps, otherwise prompt and end the process; Judge whether the user selects the Excel test document, if so, continue to execute the subsequent steps, otherwise prompt and end the process; Judge whether the Excel test document passes the verification, if so, continue to execute the subsequent steps, otherwise prompt and end the process; Load and encapsulate the Excel test document data using Python to generate Excel test case list structure data corresponding to different Word test document types; Select the corresponding Word template according to the selected Word test document type; Write the Excel test case list structure data of the corresponding type into the selected Word template through the template engine; Through logical and loop control tags, batch and repeated processing data and Word templates are generated to generate the final Word test document.
[0006] In some embodiments, the Word test document type includes: software test description document, software test record document, software test report document; the user can select one or more Word test document types.
[0007] In some embodiments, the verification process of the Excel test document includes: Load the standard test case Excel document first line field defined in advance and stored in the Python dictionary into the memory; Judge whether the selected Excel test document is an Excel document, if so, continue to execute the subsequent steps, otherwise the verification fails and a prompt is given; Read the first line field of the Excel test document using the Python third-party library xlrd; Compare the first line field of the Excel test document with the first line field of the standard test case Excel document, if they are the same, the verification is successful, and the subsequent steps are executed, if they are not the same, the verification fails and a prompt is given.
[0008] In some embodiments, during the process of reading the first line field of the Excel test document, if the Excel test document has multiple worksheets, all worksheets are traversed to read their first line fields, and the first line fields of the Excel test document are stored in the form of list nested dictionary.
[0009] In some embodiments, the process of loading and encapsulating the Excel test document data includes: According to the selected Word test document type, it is judged whether to read the Excel test document name; The Python third-party library xlrd is used to open the Excel test document and name it as a workbook, and all sheet names in the workbook are obtained and stored in a list; All sheet name list data is traversed to obtain single sheet data named table, and row data in the table is obtained one by one; The obtained row data is counted and packaged according to the corresponding Word test document type data structure, and stored in a Python data structure in the form of Json.
[0010] In some embodiments, the judgment of whether to read the Excel test document name according to the selected Word test document type comprises: If the selected is a software test record document or a software test report document, the Excel test document name is read, and the related software data is extracted from the Excel test document, and if the selected is a software test specification document, the Excel test document name is not read.
[0011] In some embodiments, the fixed format and content in the Word template are customized as needed; In the Word template, the repeated format and content are marked using Jinja2 syntax template tags, the template tags include data tags and control tags, the data tags obtain data in the Excel test document in the form of variables, and the control tags control logic and loop.
[0012] In some embodiments, the writing of the Excel test case list structure data of the corresponding type into the selected Word template by the template engine comprises: The Python DocxTemplate class is used to read the custom format Word template marked by the Jinja2 syntax template tag by the template engine and write the Excel test case list structure data of the corresponding type.
[0013] In a second aspect, the present application provides an electronic device, comprising a memory and a processor, the memory stores a computer program, and the processor executes the computer program to realize any one of the embodiments of the above-mentioned Excel document to Word document conversion method.
[0014] In a third aspect, the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize any one of the embodiments of the above-mentioned Excel document to Word document conversion method.
[0015] The application provides an Excel document to Word document conversion method, which fills data in an Excel test case document into a Word template according to certain rules, i.e., associates the data in the Excel test case document to the Word test document, and integrates and counts the data in the generated test report document, thereby simplifying complex document conversion work, solving the problem of manually writing a Word test document in current software testing work, saving the time for writing a test document, improving work efficiency, and standardizing the Word test document.
[0016] Correspondingly, the electronic device and the computer readable storage medium provided by the application also have the same technical effects. BRIEF DESCRIPTION OF DRAWINGS
[0017] The accompanying drawings, which are included to provide a further understanding of the embodiments of the application and constitute a part of the application, illustrate embodiments of the application and are used to explain the principle of the application. In the drawings: Figure 1 The method flowchart provided by the embodiments of the application; Figure 2 The Excel test document verification flowchart of the embodiments of the application; Figure 3 The Excel test document data loading and packaging flowchart of the embodiments of the application; Figure 4 The Excel document to Word document conversion program interface diagram of the embodiments of the application; Figure 5 The test case diagram of a certain software; Figure 6 The data structure diagram corresponding to the software test specification document; Figure 7 The data structure diagram corresponding to the software test record document; Figure 8 The data structure diagram corresponding to the software test report document; Figure 9 The Word template diagram corresponding to the software test specification document; Figure 10 The Word template diagram corresponding to the software test record document; Figure 11 The Word template diagram corresponding to the software test report document; Figure 12 The generated software test specification document diagram; Figure 13 The generated software test record document diagram; Figure 14 a generated software test report document; Figure 15 a device principle block diagram proposed by an embodiment of the present application; Figure 16 a system architecture schematic diagram proposed by an embodiment of the present application; Figure 17 an electronic device schematic diagram proposed by an embodiment of the present application; Figure 18 a computer readable storage medium schematic diagram proposed by an embodiment of the present application; Corresponding component names: 200 - device, 201 - first selection unit, 202 - second selection unit, 203 - verification unit, 204 - loading packaging unit, 205 - selection unit, 206 - data writing unit, 207 - generation unit, 300 - system, 301 - input device, 302 - output device, 303 - processor A, 304 - memory A, 400 - electronic device, 410 - memory B, 420 - processor B, 411 - computer program A, 500 - computer readable storage medium, 511 - computer program B. DETAILED DESCRIPTION
[0018] Hereinafter, the term "include" or "may include" used in various embodiments of the present application indicates the existence of the invented function, operation, or element, and does not limit addition of one or more functions, operations, or elements. Also, as used in various embodiments of the present application, the term "include", "have", and their conjugates merely indicate the presence of specific features, numbers, steps, operations, elements, components, or combinations thereof, and should not be construed as excluding the presence or possibility of addition of one or more other features, numbers, steps, operations, elements, components, or combinations thereof.
[0019] In various embodiments of the present application, the expression "or" or "at least one of A or / and B" includes any combination of the listed terms or all combinations thereof. For example, the expression "A or B" or "at least one of A or / and B" can include A, can include B, or can include both A and B.
[0020] The expressions used in the various embodiments of the present application, such as "first", "second", etc., can modify various constituent elements in the various embodiments, but can not limit the corresponding constituent elements. For example, the above expressions do not limit the order and / or importance of the elements. The above expressions are only for the purpose of distinguishing one element from other elements. For example, the first user device and the second user device indicate different user devices, although both are user devices. For example, without departing from the scope of the various embodiments of the present application, a first element can be referred to as a second element, and similarly, a second element can also be referred to as a first element.
[0021] It should be noted that if a description connects one constituent element to another constituent element, the first constituent element can be directly connected to the second constituent element, and a third constituent element can be connected between the first constituent element and the second constituent element. Conversely, when one constituent element is directly connected to another constituent element, it can be understood that there is no third constituent element between the first constituent element and the second constituent element.
[0022] The terms used in the various embodiments of the present application are only for the purpose of describing specific embodiments and are not intended to limit the various embodiments of the present application. As used herein, the singular form is intended to include the plural form, unless the context clearly indicates otherwise. Unless otherwise defined, all terms used herein, including technical terms and scientific terms, have the same meaning as commonly understood by those skilled in the art to which the various embodiments of the present application belong. The terms such as those defined in a generally used dictionary will be interpreted as having the same meaning as the context in the relevant technical field and will not be interpreted as having an idealized or overly formal meaning, unless clearly defined in the various embodiments of the present application.
[0023] In order to make the purposes, technical solutions and advantages of the present application clearer, further detailed description of the present application is made below in combination with embodiments and drawings, the illustrative embodiments of the present application and their descriptions are only for the purpose of explaining the present application, and do not limit the present application.
[0024] When the number of data fields in the Excel document increases and the Word template frequently changes, the traditional method of converting the Excel document to the Word document generates a data source that needs to be reselected and a template that needs to be redefined each time, resulting in increased conversion time, increased workload, and low efficiency. To this end, the embodiments of the present application propose a method for converting an Excel document to a Word document based on Python, which can efficiently convert an Excel test document to a Word test document.
[0025] As shown in Figure 1 The method proposed by the embodiments of the present application includes the following steps: Step 1, determine whether the user selects the generated Word test document type, if so continue to execute the subsequent steps, otherwise prompt and end the process; Wherein the Word test document type includes: software test description document, software test record document, software test report document, can select to generate one or more test document types; Step 2, determine whether the user selects Excel test document, if so continue to execute the subsequent steps, otherwise prompt and end the process; Step 3, determine whether the Excel test document is verified, if so continue to execute the subsequent steps, otherwise prompt and end the process; This step is mainly to prevent the user from selecting non-software test case Excel document or non-standard test case Excel document; Step 4, using Python to load and encapsulate Excel test document data to generate corresponding different Excel test case list structure data of Word test document type; Step 5, according to the selected Word test document type to select the corresponding Word template; Step 6, write the corresponding type of Excel test case list structure data into the Word template through the template engine; Step 7, through the logic and loop control label, batch, repeat processing data and Word template to generate the final Word test document; Word test document includes one or more of software test description document, software test record document, software test report document.
[0026] Further, in step 3 of the embodiments of the present application, the Excel test document verification process is as shown in Figure 2 , including: The program automatically loads the first line field of the standard test case Excel document predefined and stored in the Python dictionary into the memory after running; Determine whether the selected Excel test document is an Excel document, if not, the verification fails and prompts; Otherwise continue to execute the subsequent steps; In this step, it can be determined whether the selected Excel test document name ends with xls or xlsx suffix, if so, it indicates that the selected Excel test document is an Excel document, otherwise it indicates that the selected Excel test document is not an Excel document; Read the first line field of the Excel test document using the Python third-party library xlrd, if there are multiple sheets, traverse the multiple sheets to read the first line field, and store the first line field of the Excel test document in the form of list nested dictionary; The first line field of the Excel test document is compared with the first line field of the standard test case Excel document. If there is a difference (i.e. there is a difference as long as one column field is different), the check fails and a prompt is given. If they are the same (i.e. each column field is the same), the check is successful, and the subsequent steps are continued.
[0027] Further, step 4 of the embodiment of the application uses the Python third-party library xlrd to extract data in the Excel test document to the memory, and then assembles the list data according to the preset rules according to the type of the Word test document, which is generally a list of nested dictionary structures, so as to generate Excel test case list structure data corresponding to different Word test document types. Wherein, the specific process of loading and packaging Excel test document data is as shown in Figure 3 , which includes: According to the selected Word test document type, it is judged whether to read the Excel test document name. If the selected is the software test record document or the software test report document, the Excel test document name is read, and the related software data is extracted from the Excel test document. If the selected is the software test specification document, the Excel test document name is not read; The Python third-party library xlrd is used to open the Excel test document and name it as a workbook, and all sheet names in the workbook are obtained and stored in a list; Iterate through all the sheet name list data to get single sheet data named table, and get row data in the table one by one; The obtained row data is counted and packaged according to the corresponding Word test document type data structure, and is stored in the Python data structure in the form of list nested dictionary, dictionary nested list (i.e. in the form of Json).
[0028] Further, in step 5 of the embodiment of the application, the Word templates corresponding to different Word test document types have been defined before the program is executed, wherein the custom templates are specifically: In the Word template, the fixed format and content are customized according to needs; In the Word template, the repeated format and content can be marked using Jinja2 syntax template tags. The template tags include data tags and control tags. The data tags obtain data in the Excel document in the form of variables, and the control tags can control logic and loops, including paragraph control and table row control in the Word document. Among them, the data tags are: {{data_tag}} represents a variable; the control tags are: {{%p ctrl_tag%}} represents a paragraph control tag, and {{%tr ctrl_tag%}} represents a Word table row control tag.
[0029] Further, in step 6 of the embodiment of the application, the Python DocxTemplate class reads the custom format Word template marked with Jinja2 syntax template and writes the corresponding type of software test document memory data using the template engine, and the specific process is as follows: Define the output file name, usually defined as: software name + test XX document, for example, XXX software test specification document; Call the DocxTemplate class to write the corresponding type of Excel test case list structure data into the selected Word template using the template engine.
[0030] Further, in step 7 of the embodiment of the application, the tags in the Word template have control tags and data tags. The fixed and repeated paragraph format and table content in the Word test document can be output to the Word document according to the specified logic through the definition of the control tags, so that the same type of data can output the corresponding title and content to the Word document in a loop. Specifically, the Excel test case list structure data can be referenced, and the control tags such as: “{%pfor sheet in sheets%}”, “{{sheet.testType}}”, “{%pend for%}” are used to output the second-level title: function test, interface test and performance test; for example: “{%pfor table in sheet.tables%}”, “{{table.module}}”, “{%pend for%}” are used to output the third-level title: login, registration, etc.; for example: “{%pfor row in table.rows%}”, “{{row.title}}”, “{%pend for%}” are used to output the fourth-level title: username error, password error and login success, etc.
[0031] By referencing the Excel test case list structure data, the data tags “{{row title}}”, “{{row.no}}” and the like can be used to write the corresponding case information in the Excel document into the Word document.
[0032] The method for converting an Excel document into a Word document based on Python provided by the embodiments of the present application simplifies the complex document conversion work, solves the problem of manually writing a Word test document in the current software testing work, saves the time for writing a test document, and improves the work efficiency. The method is implemented by customizing an Excel test case and a Word template, wherein the Excel test case and the Word test document template are customized according to the company or industry standard, the data in the Excel test case document is sequentially filled into the Word template according to a certain rule, that is, the data of the Excel test case document is associated to the Word test document, and the data is integrated and counted in the generated test report document, thereby improving the work efficiency of software testing engineers and standardizing the specific format of the Word test document. Because Python has the cross-platform running feature, the program product developed based on the method can be deployed on operating systems such as Windows, MacOS and Linux.
[0033] In order to further illustrate the above method provided by the embodiments of the present application, the embodiments of the present application take a work scenario of generating a software test document as an example, Figure 4 The program interface diagram of the Excel document to Word document is shown, and the detailed operation of the program for converting the Excel test case into a Word test document is as follows: (1) Select the type of the Word test document to be generated, which has four options, namely: all, software test specification document, software test record document, and software test report document. All three types of documents can be generated, or a certain type of document can be generated. When generating, the program will enter data according to the software test document template rules corresponding to different document types.
[0034] (2) Excel test case path, that is, select the test case Excel document of the corresponding software, as shown in Figure 5 The test case diagram of a certain software is shown. The Excel document includes three worksheets of function test, interface test and performance test, and the table header fields in each worksheet are the same, which are: requirement name, requirement identifier, case number, case title, module, importance level, precondition, test data, operation steps, expected result, actual result, and pass or fail.
[0035] (3) The path for storing the Word test document, that is, the file address for storing the converted Word test document.
[0036] (4) Start generating, that is, start the conversion program to convert the Excel test document into a Word test document, and the related information produced is displayed in the interface text box.
[0037] Take generating all software test documents as an example, the specific conversion process is as follows: Step one, select all, that is, all software test document types.
[0038] Step two, select XXX Co., Ltd_Java_XXX software (v1.0.0) test case.xlsx.
[0039] Step three, Excel document verification, this step is mainly to prevent users from selecting non-software test case Excel documents or non-standard test case Excel documents. The specific verification process is shown in steps 3 and Figure 2 above, which will not be repeated here.
[0040] Step four, load Excel document data and complete data encapsulation, and the data structure diagram after encapsulation is as follows: the data structure corresponding to the software test description document is shown in Figure 6 , the data structure corresponding to the software test record document is shown in Figure 7 , and the data structure corresponding to the software test report document is shown in Figure 8 . Among them, tetsType represents the test type, tables represent the row data set of a single sheet page, module represents the module, rows represent the row data corresponding to the module, and row represents a single test case data. The Excel document data loading and encapsulation process is shown in steps 4 and Figure 3 above, which will not be repeated here.
[0041] Step five, the Word template (customized according to different test document types) is prefabricated in the specified directory of the software program, and the corresponding Word template is automatically selected according to the selected Word test document type. This step will loop all test document types to take out the corresponding Word template, in which the Word template corresponding to the software test description document is shown in Figure 9 , the Word template corresponding to the software test record document is shown in Figure 10 , and the Word template corresponding to the software test report document is shown in Figure 11 .
[0042] Step six, according to the Excel test case list structure data stored in the memory, the DocxTemplate class of the Python third-party library docxtpl reads the custom format Word template marked with Jinja2 syntax and writes Excel data using the template engine. Loop to generate all types of test documents.
[0043] Step seven, after writing data into each template, through logical and loop control tags, batch and repeated processing is performed to finally complete the generation of all software test documents. Among them, the generated software test description document is shown in Figure 12As shown, the generated software test record document is as shown in Figure 13 As shown, the generated software test report document is as shown in Figure 14 As shown.
[0044] Based on the same technical concept, the embodiment of the present application also proposes an apparatus for converting Excel document to Word document based on Python, as shown in Figure 15 The apparatus 200 comprises: A first selection unit 201 is configured to select a type of Word test document to be generated. The type of Word test document includes: software test description document, software test record document, and software test report document. One or more types of test documents can be selected to be generated.
[0045] A second selection unit 202 is configured to select an Excel test document, i.e., test case Excel document, after selecting the type of Word test document.
[0046] A verification unit 203 is configured to verify the selected Excel test document. The specific verification process is as shown in steps 3 and Figure 2 As shown, details are not repeated here.
[0047] A loading and packaging unit 204 is configured to load and package the Excel test document data by using Python to generate Excel test case list structure data corresponding to different types of Word test documents. The specific loading and packaging process is as shown in steps 4 and Figure 3 As shown, details are not repeated here.
[0048] A selection unit 205 is configured to select a corresponding Word template according to the selected type of Word test document. The Word target customization manner is as shown in step 5, and details are not repeated here.
[0049] A data writing unit 206 is configured to write the Excel test case list structure data of the corresponding type into the Word template by using a template engine. The specific writing process is as shown in step 6, and details are not repeated here.
[0050] In addition, a generation unit 207 is configured to generate the final Word test document by using logic and loop control tags to process data and the Word template in batches and repeatedly; the Word test document includes one or more of the software test description document, the software test record document, and the software test report document.
[0051] Based on the same technical concept, the embodiment of the present application also proposes a system for converting Excel document to Word document based on Python, as shown in Figure 16 The system 300 comprises: The input device 301, the output device 302, the processor A 303 and the memory A 304; wherein the number of the processor A 303 and the memory A 304 can be one or more, Figure 16 The input device 301, the output device 302, the processor A 303 and the memory A 304 can be connected through a bus or other means, Figure 16 The input device 301, the output device 302, the processor A 303 and the memory A 304 can be connected through a bus or other means,
[0052] The processor A 303 is configured to execute the following steps by calling the operation instructions stored in the memory A 304: Determine whether the user selects the generated Word test document type, if yes, continue to execute the subsequent steps, otherwise prompt and end the process; wherein the Word test document type includes: software test description document, software test record document, software test report document, and one or more test document types can be selected to be generated; Determine whether the user selects the Excel test document, if yes, continue to execute the subsequent steps, otherwise prompt and end the process; Determine whether the Excel test document passes the verification, if yes, continue to execute the subsequent steps, otherwise prompt and end the process; this step is mainly to prevent the user from selecting non-software test case Excel document or non-standard test case Excel document; The Excel test document data is loaded and encapsulated by using Python to generate the Excel test case list structure data corresponding to different Word test document types; According to the selected Word test document type, the corresponding Word template is selected; The Excel test case list structure data of the corresponding type is written into the Word template through the template engine; Through logical and loop control tags, batch and repeated processing data and Word templates are generated to generate the final Word test document; the Word test document includes one or more of the software test description document, the software test record document and the software test report document.
[0053] Optionally, the processor A 303 is further configured to execute any one of the embodiments in the above method by calling the operation instructions stored in the memory A 304.
[0054] Based on the same technical concept, the embodiments of the present application also propose an electronic device, such as Figure 17As shown, the electronic device 400 comprises a memory B 410, a processor B 420, and a computer program A 411 stored on the memory B 410 and executable on the processor B 420, and the processor B 420 implements the following steps when executing the computer program A 411: It is judged whether the user selects the generated Word test document type, if yes, the subsequent steps are executed, otherwise, a prompt is given and the process is ended; wherein the Word test document type includes: software test description document, software test record document, software test report document, and one or more test document types can be selected to be generated; It is judged whether the user selects the Excel test document, if yes, the subsequent steps are executed, otherwise, a prompt is given and the process is ended; It is judged whether the Excel test document passes the verification, if yes, the subsequent steps are executed, otherwise, a prompt is given and the process is ended; this step is mainly to prevent the user from selecting a non-software test case Excel document or a non-standard test case Excel document; The Excel test document data is loaded and encapsulated by using Python to generate the Excel test case list structure data corresponding to different Word test document types; According to the selected Word test document type, the corresponding Word template is selected; The Excel test case list structure data of the corresponding type is written into the Word template through the template engine; Through logical and loop control tags, batch and repeated processing data and the Word template are processed to generate the final Word test document; the Word test document includes one or more of the software test description document, the software test record document, and the software test report document.
[0055] Optionally, the processor B 420 executes the computer program A 411, and any implementation in the corresponding embodiments of the above method can be implemented.
[0056] It should be noted that the electronic device proposed in the embodiments of the present application is a device used to implement the above method, and therefore based on the above method proposed in the embodiments of the present application, those skilled in the art can understand the specific implementation of the electronic device of the embodiments of the present application and its various forms, and therefore the specific implementation of the electronic device for implementing the above method is not introduced in detail here, as long as the electronic device used by those skilled in the art to implement the above method belongs to the scope of protection of the present application.
[0057] Based on the same technical concept, the embodiments of the present application also propose a computer readable storage medium, such as Figure 18As shown, the computer readable storage medium 500 stores a computer program B 511, which, when executed by the processor, implements the following steps: It is judged whether the user selects the generated Word test document type, if yes, the subsequent steps are executed, otherwise, the user is prompted and the process is ended; wherein the Word test document type includes: software test description document, software test record document, software test report document, one or more test document types can be selected to generate; It is judged whether the user selects the Excel test document, if yes, the subsequent steps are executed, otherwise, the user is prompted and the process is ended; It is judged whether the Excel test document passes the verification, if yes, the subsequent steps are executed, otherwise, the user is prompted and the process is ended; this step is mainly to prevent the user from selecting non-software test case Excel document or non-standard test case Excel document; The Python is used to load and encapsulate the Excel test document data to generate the corresponding Excel test case list structure data of different Word test document types; According to the selected Word test document type, the corresponding Word template is selected; The corresponding type of Excel test case list structure data is written into the Word template through the template engine; Through the logic and loop control label, the final Word test document is generated by batch processing data and the Word template; the Word test document includes one or more of software test description document, software test record document, and software test report document.
[0058] Optionally, the computer program B 511 executed by the processor can implement any of the embodiments of the above-mentioned method.
[0059] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.
[0060] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can adopt a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer usable program code.
[0061] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flow or blocks Figure 1 one or more flow or blocks
[0062] These computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture including instructions which implement the function specified in the flowchart block or blocks. Figure 1 one or more flow or blocks Figure 1 one or more flow or blocks
[0063] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flow or blocks Figure 1 one or more flow or blocks
[0064] The above description is only specific implementation of the present application, and is not intended to limit the protection scope of the present application, and any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for converting an Excel document to a Word document, characterized in that, Comprise: Determine whether the user selects the generated Word test document type, if so continue to execute the subsequent steps, otherwise prompt and end the process; Determine whether the user selects the Excel test document, if so continue to execute the subsequent steps, otherwise prompt and end the process; Determine whether the Excel test document passes the verification, if so continue to execute the subsequent steps, otherwise prompt and end the process; Use Python to load and encapsulate the Excel test document data to generate the corresponding Excel test case list structure data for different Word test document types; According to the selected Word test document type, select the corresponding Word template; Through the template engine, write the corresponding type of Excel test case list structure data into the selected Word template; Through logical and loop control tags, batch and repeat processing data and Word templates to generate the final Word test document.
2. The method for converting an Excel document to a Word document according to claim 1, wherein, The Word test document type includes: software test description document, software test record document, software test report document; the user can select one or more Word test document types.
3. The method for converting Excel document to Word document according to claim 1, characterized in that, The verification process of the Excel test document includes: Load the standard test case Excel document first line field defined in advance and stored in the Python dictionary into the memory; Determine whether the selected Excel test document is an Excel document, if so continue to execute the subsequent steps, otherwise the verification fails and prompts; Use Python third-party library xlrd to read the first line field of the Excel test document; Compare the first line field of the Excel test document with the first line field of the standard test case Excel document, if they are the same, the verification is successful, and the subsequent steps are executed, if they are not the same, the verification fails and prompts.
4. The method for converting an Excel document to a Word document according to claim 3, wherein, During the reading of the first line field of the Excel test document, if the Excel test document has multiple worksheets, traverse all the worksheets to read their first line fields, and store the first line fields of the Excel test document in the form of list nested dictionary.
5. The method for converting Excel document to Word document according to any one of claims 1-4, characterized in that, The process of loading and encapsulating the Excel test document data includes: According to the selected Word test document type, determine whether to read the Excel test document name; Use Python third-party library xlrd to open the Excel test document and name it as a workbook, get all the worksheet names in the workbook and store them in a list; Traverse all the worksheet name list data to get single worksheet data named table, and get the row data in the table one by one; According to the corresponding Word test document type data structure, count and encapsulate the obtained row data, and store it in the Python data structure in the form of Json.
6. The method for converting an Excel document to a Word document according to claim 5, wherein, The determination of whether to read the Excel test document name according to the selected Word test document type includes: If the selected document is a software test record document or a software test report document, the Excel test document name is read and relevant software data is extracted from the Excel test document; if the selected document is a software test specification document, the Excel test document name is not read.
7. The method for converting an Excel document to a Word document according to claim 5, wherein, In the Word template, fixed formats and contents are customized as needed. In the Word template, repeated formats and contents are marked using Jinja2 syntax template tags, which include data tags and control tags, the data tags obtain data in the Excel test document in the form of variables, and the control tags control logic and loops.
8. The method for converting an Excel document to a Word document according to claim 5, wherein, The template engine writes the corresponding type of Excel test case list structure data into the selected Word template, including: The Python DocxTemplate class is used to read the customized format Word template marked with Jinja2 syntax template tags using a template engine and write the corresponding type of Excel test case list structure data. 9.An electronic device comprising a memory and a processor, the memory storing a computer program, wherein, The processor executes the computer program to implement the method for converting an Excel document to a Word document according to any one of claims 1-8.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the method for converting an Excel document to a Word document according to any one of claims 1-8.