Table data conversion method, device and computer readable storage medium

By identifying and adding whitespace characters during the table data conversion process, the problem of inaccurate display of empty data during table data migration is solved, ensuring that the converted table data is consistent with the original table and improving the accuracy of data migration and synchronization.

CN116561062BActive Publication Date: 2026-04-21SHENZHEN HONGHE INNOVATION INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN HONGHE INNOVATION INFORMATION TECH CO LTD
Filing Date
2023-05-15
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

During the migration of tabular data, due to differences in software and operating systems, existing technologies cannot accurately restore empty data in the original tabular data, making the converted tabular data difficult to read and even affecting the work results.

Method used

By converting the source table string data into a first string array separated by whitespace characters, and adding empty strings to a second string array based on the number of whitespace characters between adjacent strings, the system ensures that empty data columns are displayed accurately in the target table.

Benefits of technology

It ensures the accuracy of table data conversion, avoids data field misalignment issues, and makes the converted table consistent with the original table, thereby improving the accuracy of data migration and synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116561062B_ABST
    Figure CN116561062B_ABST
Patent Text Reader

Abstract

This invention relates to the field of data conversion technology, providing a method, apparatus, and computer-readable storage medium for converting tabular data. The invention converts the current row of string data in the source table into a first string array separated by whitespace characters. All strings in the first string array are then written into a second string array. Based on the number of whitespace characters between adjacent strings in the first string array of the current row, empty strings are written at corresponding positions in the second string array to represent empty data columns in the source table data. This ensures that when the second string array, which represents empty data columns in the source table data, is input into the target table, the resulting table will not have misaligned data columns, making the tabular data conversion more accurate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data conversion technology, specifically to a method, apparatus, and computer-readable storage medium for converting tabular data. Background Technology

[0002] With the advancement of digital technology, people can achieve higher work efficiency and more accurate operation results in all aspects of their production and life through digitalization. For example, when faced with a large amount of data, people can easily manage and calculate the data by entering multiple data points into a table.

[0003] However, in some cases, tabular data needs to be migrated between different devices, software, or operating systems to adapt to complex and ever-changing job requirements. After the tabular data is migrated and converted, due to the differences in software and operating systems, it is often impossible to accurately restore the original position of the data in the original tabular data. In particular, when there is empty data in the original tabular data, the new tabular data obtained by migration and conversion often cannot correctly display the empty data in the original tabular data, making the migrated and converted tabular data difficult to read and even affecting the job. Summary of the Invention

[0004] Based on the above situation, the main objective of this invention is to provide a table data conversion method that can correctly identify and convert empty data in the original table data.

[0005] To achieve the above objectives, the technical solution adopted by the present invention is as follows:

[0006] Step S1: Obtain source table string data, which includes L rows of data, where L is a positive integer and L≥1;

[0007] Step S2: Convert the current row data of the source table string data into a first string array using whitespace as the separator. If the first character of the current row data is a whitespace character, then write an empty string into the first item of the first string array.

[0008] Step S3: Generate a second string array based on the current row data and the first string array. The second string array includes all strings in the first string array. If there are S adjacent whitespace characters before the n1th non-empty character in the current row data, S is a positive integer. If S≥2 and the S whitespace characters are consecutive whitespace characters, then (S-1) empty strings are written between the string to which the n1th non-empty character belongs and the string before it in the second string array.

[0009] Step S4: Input the second string array into the target table.

[0010] Preferably, step S3 includes:

[0011] Step S32: Write the first string from the first string array into the second string array;

[0012] Step S34, using the formula S = g k -j k-1 -g k-1 Calculate S, where g k j is the position index of the first character of the k-th string in the first string array within the current line of data. k-1 Let g be the length of the (k-1)th string in the first string array. k-1 Let be the position index of the first character of the (k-1)th item in the first string array within the current line of data. The first character of the kth item is the n1th non-empty character. k is a positive integer and its initial value is 2.

[0013] Step S36: Write (S-1) empty strings one by one as new end items into the second string array;

[0014] Step S38: Write the k-th string in the first string array as the new last item into the second string array;

[0015] Step S39: Set k to (k+1) and jump to step S34 until k = m, where m is the total number of strings contained in the first string array.

[0016] Preferably, before step S36, the method further includes:

[0017] Step S3601: Determine if S is greater than 1;

[0018] If so, proceed to step S36;

[0019] If not, proceed to step S38.

[0020] Preferably, step S34 includes:

[0021] Step S341: Starting from the n2nd character of the current row of data, search for the first character of the kth item in the first string array to obtain the position index g. k The initial value of n2 is the sum of the length of the first non-empty string in the first string array and the number of whitespace characters S1 before the first non-empty character in the current row of data, plus 1.

[0022] Step S342, obtain g k-1 Where, when k=2, g k-1 =1, k>2 when g k-1 g obtained from the previous execution of step S341k ;

[0023] Step S343, obtain j k-1 And through the formula S=g k -j k-1 -g k-1 Calculate S;

[0024] Before step S39, the method also includes: step S3901, obtaining the length j of the k-th string in the first string array. k Let n2 be (n2+S+j k ).

[0025] Preferably, after step S1, the method further includes:

[0026] Step S110: Convert the source table string data into a third string array separated by newline characters. The third string array includes L strings. The characters in the e-th string in the third string array are the characters in the e-th row of the source table string data. e is a positive integer, 1≤e≤L.

[0027] Step S2 includes: Step S21, determining the e-th string in the third string array as the current row data, where the initial value of e is 1;

[0028] After step S39, the method further includes: step S3910, setting e to (e+1), resetting k to 2, and jumping to step S2.

[0029] Preferably, before step S110, the method further includes: converting the type of all newline characters contained in the source table string data to the target type.

[0030] Preferably, after step S3, the method further includes:

[0031] Step S310: Obtain the number of items in each of the generated second string arrays, and take the maximum value x.

[0032] Step S320: Generate a target table containing L rows and x columns of input boxes;

[0033] Step S4 includes: Step S41, inputting all the generated second string arrays into the input boxes of the target table, wherein each input box contains one string.

[0034] Preferably, step S3 includes: step S31, adding a row number identifier to each string in the second string array, wherein the row number is the row number of the row data corresponding to the second string array to which the string belongs;

[0035] Step S41 includes:

[0036] Step S411: Obtain the item number of each string in the current second string array;

[0037] Step S412: For each string in the current second string array, determine its row number L. i Item number x j Enter them into the Lth column of the target table respectively. i Line x j In the column input box, i and j are both positive integers, 1≤i≤L, 1≤i≤x.

[0038] This invention converts the current row of string data in the source table into a first string array separated by whitespace characters. All strings in the first string array are then written into a second string array. Based on the number of whitespace characters between two adjacent strings in the first string array in the current row, an empty string is written at the corresponding position in the second string array to represent empty data columns in the source table data. This ensures that when the second string array, which represents empty data columns in the source table data, is input into the target table, the target table will not have data column misalignment issues, making the table data conversion more accurate.

[0039] Other beneficial effects of the present invention will be explained in detail through the introduction of specific technical features and technical solutions in specific embodiments. Those skilled in the art should be able to understand the beneficial technical effects brought about by these technical features and technical solutions through the introduction of these technical features and technical solutions. Attached Figure Description

[0040] The preferred embodiments of the tabular data conversion method provided by the present invention will be described below with reference to the accompanying drawings. In the drawings:

[0041] Figure 1 This is a flowchart illustrating a preferred embodiment of the present invention;

[0042] Figure 2 This is a flowchart illustrating a preferred embodiment of a sub-step of step S3 of the present invention.

[0043] Figure 3 This is a flowchart illustrating a preferred embodiment of the steps preceding step S36 of the present invention.

[0044] Figure 4 This is a flowchart illustrating a preferred embodiment of a sub-step of step S34 of the present invention.

[0045] Figure 5 This is a flowchart illustrating a preferred embodiment of the steps following step S1 of the present invention.

[0046] Figure 6 This is a flowchart illustrating a preferred embodiment of the steps preceding step S110 of the present invention.

[0047] Figure 7 This is a flowchart illustrating a preferred embodiment of the steps following step S3 of the present invention.

[0048] Figure 8 This is a flowchart illustrating a preferred embodiment of a sub-step of step S3 of the present invention.

[0049] Figure 9 This is a schematic diagram of the structure of a tabular data conversion device according to an embodiment of the present invention. Detailed Implementation

[0050] The present invention is described below based on embodiments, but the present invention is not limited to these embodiments. In the following detailed description of the present invention, some specific details are described in detail, but well-known methods, processes, procedures, and elements are not described in detail in order to avoid obscuring the essence of the present invention.

[0051] Furthermore, those skilled in the art should understand that the accompanying drawings provided herein are for illustrative purposes only and are not necessarily drawn to scale.

[0052] Unless the context explicitly requires it, the words "comprising," "including," or similar terms throughout the specification and claims should be interpreted as encompassing rather than being exclusive or exhaustive; that is, meaning "including but not limited to."

[0053] In the description of this invention, it should be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this invention, unless otherwise stated, "a plurality of" means two or more.

[0054] With the development and progress of digital technology, people are increasingly relying on various easy-to-access data formats to manage and store large amounts of data. Among them, tabular data has the advantages of being easy to access and retrieve, easy to manage, and widely applicable. Therefore, many fields save data by inputting it into tables.

[0055] To adapt to scenarios involving collaborative operations of multiple devices in different fields, table data on one device often needs to be migrated or synchronized to another. When the operating systems or software environments of multiple devices are consistent, the migration and synchronization of table data is relatively convenient. However, in reality, it cannot be guaranteed that each operating device has a consistent operating system or software environment. Therefore, the inventors of this application have noticed that table data can be adapted to devices with different operating systems or software environments by converting the table data, thereby achieving the migration or synchronization of table data.

[0056] However, the inventors of this application discovered through research that when there is empty data in the tabular data to be converted, since the markers used to represent empty data and the markers used to represent the intervals between table columns are often blank characters, existing tabular data conversion methods only treat the blank characters in the tabular data as the intervals between table columns and directly convert the tabular data. They cannot take into account the situation where there is empty data in the tabular data. The new tabular data obtained after conversion may have the risk of data column misalignment. Therefore, there is an urgent need to develop a tabular data conversion method that can identify blank characters in tabular data and automatically add empty data to the data obtained after conversion.

[0057] Based on this, the inventors, through research, designed a table data conversion method. This method converts the current row of string data in the source table into a first string array separated by whitespace characters. All strings in the first string array are then written into a second string array. Furthermore, based on the number of whitespace characters between adjacent strings in the first string array of the current row, empty strings are written at corresponding positions in the second string array to represent empty data columns in the source table data. This ensures that when the second string array, which represents empty data columns in the source table data, is input into the target table, the resulting target table will not have misaligned data columns, making the table data conversion more accurate.

[0058] The table data conversion method disclosed in this application can be used, but is not limited to, for converting Excel table data. It can also be applied to converting table data in any other table format that needs to be converted. In this application embodiment, the method for converting Excel table data is used as an example for illustration.

[0059] In the embodiments of this application, a string refers to a sequence of characters composed of numbers, letters, underscores, or symbols, and is a data type used to represent text in programming languages. The length of a string is the number of characters that make up the string. Each space in a string occupies one unit of length, while an empty string does not occupy any length; that is, the length of an empty string is 0.

[0060] In the embodiments of this application, the array refers to an ordered sequence of elements, which can be composed of multiple strings or multiple arrays. An array is a form of organizing several elements of the same type in an ordered manner for the convenience of processing in program design. It can be understood that each element in the array has a position number for locating within the same array. For example, if there is an array Array = ["Zhang San", "Li Si", "Zhao Wu"], then in common computer languages, the position number of "Zhang San" is 0, the position number of "Li Si" is 1, and the position number of "Zhao Wu" is 2.

[0061] Figure 1 A flowchart illustrating a preferred embodiment of the present invention is shown. The method is executed by a tabular data conversion device, which may be, for example, a computer, a server, etc. Figure 1 As shown, the method includes the following steps:

[0062] Step S1: Obtain source table string data, which includes L rows of data, where L is a positive integer and L≥1.

[0063] In this step, the source table string data refers to the source code of the table data. For example, after copying the table data, the content in the clipboard obtained by the computer is the source table string data. Alternatively, the source table string data can be obtained by directly reading the code of the table data. This application embodiment does not impose any special limitations on the method of obtaining the source table string data. It is only necessary to ensure that the obtained source table string data can be automatically recognized as a table and displayed on specific software, such as an Excel spreadsheet.

[0064] For example, using an Excel spreadsheet:

[0065] Name age Telephone address Li Si 32 a certain city

[0066] The source table string data for the above table is: "Name / 1 Age / 1 Phone / 1 Address / 2 Li Si / 132 / 1 / 1 City". For ease of display and understanding, / 1 represents a whitespace character and / 2 represents a newline character in the description of this application's embodiments. In actual computer display, whitespace and newline characters may not be visible and thus have no practical effect. It is understood that when the table data has multiple rows, the resulting source table string data also has multiple rows and is represented as a single string in the text.

[0067] Step S2: Convert the current row data of the source table string data into a first string array separated by whitespace characters. If the first character of the current row data is a whitespace character, write an empty string into the first item of the first string array.

[0068] In this step, the current row data of the source table string data is converted into the first string array using whitespace as the separator. For example, if the current row data of the source table string data is "Name / 1 Age / 1 Phone / 1 Address", the first string array obtained by converting it with whitespace as the separator is: ["Name", "Age", "Phone", "Address"]. For another example, if the current row data of the source table string data is " / 132 / 1 City", the first string array obtained by converting it with whitespace as the separator is: ["", "32", "City"].

[0069] To achieve the aforementioned separation effect, this step can use the JavaScript `Split()` method to separate the source table string data. The array obtained after splitting the string using JavaScript's `Split()` method possesses the aforementioned characteristics. Alternatively, it can be achieved by splitting the source table string data before judging and processing it. For example, the current row data of the source table string data, " / 132 / 1 [city]", can be separated by spaces to obtain the first string array: ["32", "[city]]. Then, the first character of the current row data of the source table string data is judged. If it is a whitespace character, an empty string is written to the first item of the first string array. The final first string array is: ["", "32", "[city]". It is understood that various methods can be used to achieve the effect of separating and converting the current row data of the source table string data by spaces in this step. This application embodiment does not make any improvement to the data separation method, as long as the first string array obtained by conversion can meet the characteristics described in the example of this application embodiment.

[0070] It should be noted that the data splitting method described in this step does not take into account all whitespace characters in the current row of data. For example, if the current row of data corresponds to a row in the table:

[0071] Zhang San Li Si Zhao Wu

[0072] The current line of data is: " / 1 / 1 Zhang San / 1 Li Si / 1 / 1 / 1 Zhao Wu". After splitting the current line of data, the first string array obtained is: ["", "Zhang San", "Li Si", "Zhao Wu"].

[0073] Step S3: Generate a second string array according to the current row data and the first string array. The second string array includes all the strings in the first string array. When there are S whitespace characters adjacent to the n1-th non-empty character in the current row data, where S is a positive integer, if S≥2 and the S whitespace characters are consecutive, then (S - 1) empty strings are written between the string to which the n1-th non-empty character in the second string array belongs and its previous string.

[0074] In this step, the method of generating the second string array is as follows. For example, the current row data is: " / 1Zhang San / 1 / 1 / 1Li Si / 1Zhao Wu", and the first string array is: ["", "Zhang San", "Li Si", "Zhao Wu"]. At this time, all the strings included in the first string array are directly written into the second string array, resulting in: ["", "Zhang San", "Li Si", "Zhao Wu"]. Calculate the number S1 of whitespace characters adjacent to the first non-empty character in the current row data, and S1 = 1. Since S1 is less than 2, it can be determined that there is no empty data column between the first column and the second column in the table corresponding to the source table string data, that is, there is no empty data between the first string and the second string in the second string array, and no processing is required. Then calculate the number S2 of whitespace characters between the second string "Zhang San" and the third string "Li Si" in the first string array corresponding to the characters in the current row data. It can be seen that S2 = 3. Since S2≥2, it indicates that there is an empty data column between the second column and the third column in the table corresponding to the source table string data, that is, there is empty data between the second string and the third string in the second string array. Then (S2 - 1) empty strings are written between "Zhang San" and "Li Si" in the second string array, resulting in the second string array: ["", "Zhang San", "", "", "Li Si", "Zhao Wu"]. At this time, continue to calculate the number S3 of whitespace characters between the third string "Li Si" and the fourth string "Zhao Wu" in the first string array corresponding to the characters in the current row data. It can be seen that S3 = 1. Since S3 is less than 2, it can be determined that there is no empty data column between the third column and the fourth column in the table corresponding to the source table string data, that is, there is no empty data between the third string and the fourth string in the second string array, and no processing is required. At this time, the empty data between all adjacent strings in the first string array has been judged, and the finally generated second string array is: ["", "Zhang San", "", "", "Li Si", "Zhao Wu"].

[0075] It should be noted that the purpose of generating the second string array in this step is to obtain a group of arrays that can correctly reflect the data column status in the original table corresponding to the source table string data, with empty strings at the correct positions to correspond to the empty data columns in the original table.

[0076] Step S4: Input the second string array into the target table.

[0077] Since the second string array obtained in step S3 is an array that correctly reflects the state of the data columns in the original table corresponding to the source table string data, when using the second string array for table data migration or synchronization, the data in the second string array can be sequentially input into the new table to ensure that the new table is consistent with the table corresponding to the source table string data, without any data column misalignment. In some table generation methods, the data in the second string array can also be directly used as the data columns in the table to generate a new table. Those skilled in the art are familiar with and understand the method of generating tables based on the data in the array, and will not be elaborated further here.

[0078] By using steps S1 to S4 above, empty strings are written at the corresponding positions in the second string array to represent empty data columns in the source table data. This ensures that when the second string array, which represents the empty data columns in the source table data, is input into the target table, the target table will not have the problem of misaligned data columns, making the conversion of table data more accurate.

[0079] Please see Figure 2 , Figure 2 This is a flowchart illustrating a preferred embodiment of a sub-step of step S3 of the present invention. For example... Figure 2 As shown, in some embodiments of this application, step S3 includes:

[0080] Step S32: Write the first string in the first string array into the second string array.

[0081] In this step, if the first item in the current row of the source table string data is a blank character, it means that the first item in the original table corresponding to the current row of the source table string data must be an empty data column. At this time, the first item of the first string array obtained in step S2 is also an empty string. Therefore, directly writing the first item of the string in the first string array into the second string array can make the first item of the second string array accurately reflect the data column situation of the original table. If the first item in the current row of the source table string data is not a blank character, then the first item of the first string array obtained in step S2 is the first item of the data column of the original table corresponding to the source table string data. At this time, directly writing the first item of the string in the first string array into the second string array can also make the first item of the second string array accurately reflect the data column situation of the original table. Therefore, in step S32, the first item of the string in the first string array can be left unprocessed and directly written as the first item of the second string array.

[0082] Step S34: Calculate S through the formula S = g k - j k-1 - g k-1 where g k is the position serial number of the 1st character of the k-th string in the first string array in the current row data, j k-1 is the length of the (k - 1)-th string in the first string array, g k-1 is the position serial number of the 1st character of the (k - 1)-th string in the first string array in the current row data, the 1st character of the k-th string is the n1-th non-empty character, k is a positive integer and the initial value of k is 2;

[0083] Step S36: Write (S - 1) empty strings one by one as new end items into the second string array;

[0084] No content here, seems like a placeholder Step S38: Write the k-th string in the first string array as a new end item into the second string array.

[0085] In steps S34 to S38, for example, the original table corresponding to the current row data of the source table string data is:

[0086] Zhang San Li Si

[0087] The current row data of the source table string data is: "Zhang San / 1 / 1 / 1 / 1Li Si", the first string array obtained after separation in step S2 is: ["Zhang San", "Li Si"], at this time the second string array obtained after step S32 is: ["Zhang San"], at this time in step S34, k = 2, g k is the position serial number of the 1st character of "Li Si" in the first string array in the current row data, and g k is obtained as 7, j k-1 is the length of the 1st string "Zhang San" in the first string array, and j k-1 is obtained as 2, g k-1 is the position serial number of the 1st character of "Zhang San" in the first string array in the current row data, and g k-1 is obtained as 1, at this time calculate S = g k - j k-1 - g k-1 = 7 - 2 - 1 = 4, then in step S36, write (S - 1) = 4 - 1 = 3 empty strings one by one as new end items into the second string array, at this time the obtained second string array is: ["Zhang San", "", "", ""], then in step S38, write the k-th string "Li Si" in the first string array as a new end item into the second string array, and the obtained second string array is: ["Zhang San", "", "", "", "Li Si"].

[0088] In this context, writing a string as a new last item to the second string array refers to taking advantage of the ordered arrangement of elements in the array to write the string to the end of the array, so that the elements in the array can be arranged in the order they were written. In programming languages, this can be directly implemented through function methods, such as the push() method in JavaScript for writing to an array. When implementing the embodiments provided in this application using different programming languages ​​or software, different methods can be used to achieve the effects described in the embodiments of this application. The embodiments of this application do not impose any special limitations on the specific method of writing to the array.

[0089] Step S39: Set k to (k+1) and jump to step S34 until k = m, where m is the total number of strings contained in the first string array.

[0090] The purpose of this step is to ensure that the number of whitespace characters between each data item in the first string array can be calculated, so that the generated second string array will not miss any empty strings corresponding to empty data columns in the original table.

[0091] It should be noted that the acquisition of various data in step S34 can be performed in advance before executing step S34. In particular, some data in step S34 can be acquired by directly calling historical data retained from the previous execution.

[0092] By writing the first string from the first string array into the second string array, calculating the number of whitespace characters between each string starting from the second item in the first string array, and writing (S-1) empty strings into the second string before writing each string starting from the second item in the first string array into the second string array, the ordered nature of the array can be utilized to ensure that the position of each string in the final second string array corresponds one-to-one with the data column in the original table corresponding to the string data in the source table.

[0093] Please see Figure 3 , Figure 3 This is a flowchart illustrating a preferred embodiment of the steps preceding step S36 of the present invention. Figure 3 As shown, in some embodiments of this application, before step S36, the following steps are also included:

[0094] Step S3601: Determine if S is greater than 1;

[0095] If the determination is yes, then proceed to step S36;

[0096] If the determination is negative, proceed to step S38.

[0097] In Excel spreadsheets, even when there are no empty data columns between two data columns, a whitespace character will still be present between the corresponding strings in the source table string data to indicate separation. Therefore, if the calculated number of whitespace characters S is not greater than 1, it means that there is no need to add empty strings to the second string array. Thus, we can skip the step of writing (S-1) empty strings and directly calculate the number of whitespace characters S before the next string. This avoids the runtime error that may occur in some programming languages ​​when the number of empty strings written is 0, and also saves some computing resources.

[0098] Please see Figure 4 , Figure 4 This is a flowchart illustrating a preferred embodiment of a sub-step of step S34 of the present invention. Figure 4 As shown, in some embodiments of this application, step S34 includes:

[0099] Step S341: Starting from the n2nd character of the current row of data, search for the first character of the kth item in the first string array to obtain the position index g. k The initial value of n2 is the sum of the length of the first non-empty string in the first string array and the number of whitespace characters S1 before the first non-empty character in the current row of data, plus 1.

[0100] Step S342: Obtain g k-1 Where, when k=2, g k-1 =1, k>2 when g k-1 g obtained from the previous execution of step S341 k ;

[0101] Step S343: Obtain j k-1 And through the formula S=g k -j k-1 -g k-1 Calculate S;

[0102] Before step S39, the following are also included:

[0103] Step S3901: Obtain the length j of the k-th string in the first string array. k Let n2 be (n2+S+j k ).

[0104] In steps S341 to S343 and step S3901, for example, if the current row of the source table string data is "Zhang San / 1 Li Si / 1 Li Hua", and the first string array obtained by separation is "Zhang San", "Li Si", "Li Hua"], then when k=3, if we directly search for the first character of the kth item in the first string array from the current row data, the obtained position number gk The value of 4 is incorrect. What is actually being found is the position of the first character of the second item in the first string array within the current row of data. This could lead to errors in subsequent calculations and affect the accuracy of the table data conversion.

[0105] By setting n2, and ensuring that the position number g is determined each time, k The search starts from the n2th character in the current line of data, and in each loop, n2 is incremented by the length j of the previous string. k-1 The number of whitespace characters S calculated earlier allows for skipping characters already searched in the current row of data during each search. This avoids inaccurate search results due to duplicate characters in the current row of data, thus improving the applicability and accuracy of the table data conversion method provided in this application embodiment when converting tables with duplicate data.

[0106] Please see Figure 5 , Figure 5 This is a flowchart illustrating a preferred embodiment of the steps following step S1 of the present invention. Figure 5 As shown, in some embodiments of this application, after step S1, the following steps are further included:

[0107] Step S110: Convert the source table string data into a third string array separated by newline characters. The third string array includes L strings, and the characters in the e-th string in the third string array are the characters in the e-th row of the source table string data. e is a positive integer, 1≤e≤L.

[0108] Step S2 includes:

[0109] Step S21: Determine the e-th string in the third string array as the current row data, where the initial value of e is 1;

[0110] After step S39, the following is also included:

[0111] Step S3910: Set e to (e+1), reset k to 2, and jump to step S2.

[0112] The source table string data is converted into a third string array by separating it with newline characters, so that each item in the third string array represents a row of data from the source table string data. Then, by setting a loop jump, when there are multiple rows of data in the source string data, the table data conversion can be performed on each row of the source table string data containing multiple rows of data in turn.

[0113] Please see Figure 6 , Figure 6This is a flowchart illustrating a preferred embodiment of the steps preceding step S110 of the present invention. Figure 6 As shown, in some embodiments of this application, before step S110, the following steps are further included:

[0114] Step S1101: Convert the type of all newline characters contained in the source table string data to the target type.

[0115] In step S110, when converting the source table string data into a third string array using newline characters as delimiters, the form of newline characters may differ in different operating systems, which in turn affects the form of the newline characters required for the delimiting operation. For example, in Linux systems, the newline character is \n (0x0A), in MAC systems, it is \r (0x0D), and in Windows systems, it is \r\n (0x0D, 0x0A). If the newline character form is specified incorrectly during the delimiting operation, the delimiting may be incorrect. Therefore, by pre-converting all possible newline character types to the same type, it can be ensured that the conversion of the source table string data into a third string array using newline characters as delimiters is less likely to cause delimiting errors due to incorrectly specified newline character types.

[0116] Please see Figure 7 , Figure 7 This is a flowchart illustrating a preferred embodiment of the steps following step S3 of the present invention. Figure 7 As shown, in some embodiments of this application, after step S3, the following step is further included:

[0117] Step S310: Obtain the number of items in each of the generated second string arrays, and take the maximum value x; Step S320: Generate a target table containing L rows × x columns of input boxes;

[0118] Step S4 includes:

[0119] Step S41: Input all the generated second string arrays into the input boxes of the target table, where each input box contains one string.

[0120] In step S310, the maximum value x of the number of items contained in the second string array can be understood as the number of columns in the original table corresponding to the source table string data.

[0121] By obtaining the number of items in each second string array and taking its maximum value x, a target table with L rows and x columns of input boxes is generated. All second string arrays are then input into the input boxes of the target table. This ensures that the number of data columns in the newly generated table is consistent with the original table, allowing the table data to maintain a high degree of consistency with the original table after conversion.

[0122] Please see Figure 8 , Figure 8 This is a flowchart illustrating a preferred embodiment of a sub-step of step S3 of the present invention. For example... Figure 8 As shown, in some embodiments of this application, step S3 includes:

[0123] Step S31: Add a row number identifier to each string in the second string array, where the row number is the row number of the second string array to which the string belongs;

[0124] Step S41 includes:

[0125] Step S411: Obtain the item number of each string in the current second string array;

[0126] Step S412: For each string in the current second string array, determine its row number L. i Item number x j Enter them into the Lth column of the target table respectively. i Line x j In the column input box, i and j are both positive integers, 1≤i≤L, 1≤i≤x.

[0127] By adding a row number identifier to each string in the second string array and obtaining the item number of each string in the current second string array, the row number and item number are entered into the target table to correspond to the row and column of the target table. This ensures that the converted table data is in the same position as the original table, making the table data conversion more accurate and further avoiding unexpected misalignment of table data columns.

[0128] According to another aspect of the embodiments of this application, a tabular data conversion device is provided. Please refer to [link / reference needed] for details. Figure 9 , Figure 9 The diagram illustrates the structure of a tabular data conversion device according to an embodiment of the present invention. The specific embodiments of this application do not limit the specific implementation of the tabular data conversion device.

[0129] The table data conversion device may include: processor 902 and memory 906.

[0130] The memory 906 is used to store executable instructions 910, which cause the processor 902 to perform the relevant steps as described in the above-described table data conversion method embodiment.

[0131] Specifically, the executable instructions 910 may include program code, which includes a computer program.

[0132] The processor 902 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application. The tabular data conversion device includes one or more processors, which may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.

[0133] Memory 906 is used to store executable instructions 910. Memory 906 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.

[0134] In one embodiment, a communication interface 904 and a communication bus 908 may also be included.

[0135] The processor 902, memory 906, and communication interface 904 communicate with each other through the communication bus 908.

[0136] In addition, the present invention provides a computer-readable storage medium for performing tabular data conversion, such as a chip, optical disc, etc., wherein an executable program is stored on the computer-readable storage medium, which, when executed, implements the tabular data conversion method as described in any of the above claims.

[0137] It should be noted that the computer-readable storage medium described in the embodiments of this disclosure is not limited to the embodiments given above. For example, it can also be an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In the embodiments of this disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0138] It will be understood by those skilled in the art that the above-described preferred solutions can be freely combined and superimposed without conflict. The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings; for example, two consecutively indicated blocks may actually be executed substantially in parallel, or sometimes in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions. The numbering of each step in this document is for ease of explanation and reference only and is not intended to limit the order of execution. The specific execution order is determined by the technology itself, and those skilled in the art can determine various permissible and reasonable orders based on the technology itself.

[0139] It should be noted that the use of step numbers (letters or numbers) to refer to certain specific method steps in this invention is merely for the purpose of convenience and brevity in description, and is by no means intended to restrict the order of these method steps. Those skilled in the art will understand that the order of the relevant method steps should be determined by the technology itself and should not be unduly restricted by the existence of step numbers. Those skilled in the art can determine various permissible and reasonable orderings of steps based on the technology itself.

[0140] Those skilled in the art will understand that, without conflict, the above-mentioned preferred solutions can be freely combined and superimposed.

[0141] It should be understood that the above embodiments are merely exemplary and not restrictive. Various obvious or equivalent modifications or substitutions that can be made by those skilled in the art regarding the above details without departing from the basic principles of the present invention will be included within the scope of the claims of the present invention.

Claims

1. A method for converting tabular data, characterized in that, include: Step S1: Obtain source table string data, which includes L rows of data, where L is a positive integer and L≥1; Step S2: Convert the current row data of the source table string data into a first string array using whitespace as the separator. If the first character of the current row data is a whitespace character, then write an empty string into the first item of the first string array. Step S3: Generate a second string array based on the current row data and the first string array. The second string array includes all strings in the first string array. When there are S adjacent whitespace characters before the n1th non-empty character in the current row data, S is a positive integer. If S≥2 and the S whitespace characters are consecutive whitespace characters, then (S-1) empty strings are written between the string to which the n1th non-empty character belongs and the string preceding it in the second string array. The n1th non-empty character is the first character of the kth string in the first string array. Step S4: Input the second string array into the target table.

2. The tabular data conversion method according to claim 1, characterized in that, Step S3 includes: Step S32: Write the first string in the first string array into the second string array; Step S34, using the formula S=g k - j k-1 -g k-1 Calculate S, where g k Let j be the position index of the first character of the k-th string in the first string array within the current row of data. k-1 g is the length of the (k-1)th string in the first string array. k-1 Let k be the position index of the first character of the (k-1)th string in the first string array in the current row of data, where the first character of the kth string is the n1th non-empty character, k is a positive integer and the initial value of k is 2; Step S36: Write (S-1) empty strings one by one as new end items into the second string array; Step S38: Write the k-th string in the first string array as the new last item into the second string array; Step S39: Set k to (k+1) and jump to step S34 until k=m, where m is the total number of strings contained in the first string array.

3. The tabular data conversion method according to claim 2, characterized in that, Before step S36, the method further includes: Step S3601: Determine if S is greater than 1; If so, proceed to step S36; If not, proceed to step S38.

4. The tabular data conversion method according to claim 2, characterized in that, Step S34 includes: Step S341: Starting from the n2nd character of the current row of data, search for the first character of the kth item in the first string array to obtain the position number g. k The initial value of n2 is the sum of the length of the first non-empty string in the first string array and the number of whitespace characters S1 before the first non-empty character in the current row of data, plus 1. Step S342, obtain g k-1 Where, when k=2, g k-1 When =1, k>2, g k-1 g obtained from the previous execution of step S341 k ; Step S343, obtain j k-1 And through the formula S=g k - j k-1 -g k-1 Calculate S; Before step S39, the method further includes: step S3901, obtaining the length j of the k-th string in the first string array. k Let n2 be (n2+S+j k ).

5. The tabular data conversion method according to claim 2, characterized in that, After step S1, the method further includes: Step S110: Convert the source table string data into a third string array separated by newline characters, wherein the third string array includes L strings, and the characters in the e-th string of the third string array are the characters in the e-th row of the source table string data, where e is a positive integer, 1≤e≤L; Step S2 includes: Step S21, determining the e-th string in the third string array as the current row data, wherein the initial value of e is 1; After step S39, the method further includes: step S3910, setting e to (e+1), resetting k to 2, and jumping to step S2.

6. The tabular data conversion method according to claim 5, characterized in that, Before step S110, the method further includes: converting the type of all newline characters contained in the source table string data to the target type.

7. The tabular data conversion method according to claim 1, characterized in that, After step S3, the method further includes: Step S310: Obtain the number of items in each of the generated second string arrays, and take the maximum value x. Step S320: Generate the target table containing L rows × x columns of input boxes; Step S4 includes: Step S41, inputting all the generated second string arrays into the input boxes of the target table, wherein each input box contains one string.

8. The tabular data conversion method according to claim 7, characterized in that, Step S3 includes: Step S31: Add a row number identifier to each string in the second string array, wherein the row number is the row number of the row data corresponding to the second string array to which the string belongs; Step S41 includes: Step S411: Obtain the item number of each string in the current second string array; Step S412: For each string in the current second string array, determine its row number L. i Item number x j Enter them into the Lth column of the target table respectively. i Line x j In the column input box, i and j are both positive integers, 1≤i≤L, 1≤i≤x.

9. A tabular data conversion device, characterized in that, include: A processor and a memory, the memory being used to store executable instructions, characterized in that the executable instructions cause the processor to perform operations of the tabular data conversion method as described in any one of claims 1-8.

10. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program is executed, it performs the operation of the tabular data conversion method as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Table conversion method and device, computer equipment and storage medium

    CN112036124A

  • Code conversion

    US10461772B1