Method for accessing data in table by script language, readable storage medium and computer program product
By defining the data structure in a table and generating a script file, the problem that the script language cannot directly parse the reference types in the table data structure is solved, and efficient and flexible data processing and development process optimization are achieved.
Patent Information
- Application Number
- CN202510295692.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-13
- Publication Date
- 2025-06-27
AI Technical Summary
Existing scripting languages do not support direct parsing of reference types when reading table data structures, resulting in developers needing to manually reconstruct relationships, increasing development complexity and time cost.
By defining the data structure in a table, a script language-based data type and data information script file is generated, and a script language is implemented to access table data. The method includes defining data structures, adding data information, generating script files and executing script programs to support the parsing and use of reference types.
It significantly improves the flexibility and scalability of tabular data, reduces coding pressure for developers, reduces costs, improves development efficiency, and supports the direct definition and use of complex data structures.
Smart Images

Figure CN120215899A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of data processing and software development. Specifically, it relates to a method for a scripting language to access data in a table, a readable storage medium, and a computer program product. Background Art
[0002] In the fields of data processing and software development, the traditional approach is usually to store data in a table and export this data into a specific file format for program code to load and run. These exported data are often regarded as batch data sources, and the program reads this data to execute corresponding logic. This method improves the efficiency of data processing to a certain extent, enabling developers to quickly incorporate table data into software logic.
[0003] However, although this method shows a certain degree of flexibility in data processing, the data structure defined in the table is often limited to simple numerical data. In actual application scenarios, the data structure often contains more complex attributes, such as reference types (i.e., the mutual reference relationships existing between data items). Unfortunately, existing scripting languages do not support the direct parsing of reference types when reading the table data structure. This means that when the data structure contains reference attributes, developers need to manually reconstruct these relationships in the scripting language, greatly increasing the complexity and time cost of development work.
[0004] Given the limitations of the existing technology in processing data structures with reference type attributes, how to design a method that enables such data structures to be effectively read by a scripting language and maintain their original reference relationships has become a key issue that urgently needs to be solved in the field of software development. This not only concerns the improvement of data processing efficiency but also poses an important challenge to the optimization of the software development process and the guarantee of code quality. Summary of the Invention
[0005] To solve the existing technical problems, this application provides a method for a scripting language to access data in a table, a readable storage medium, and a computer program product.
[0006] In a first aspect, an embodiment of this application provides a method for a scripting language to access data in a table, including:
[0007] Define at least one data structure in the table, where the data structure includes at least one attribute, and the attribute type of at least one attribute is numerical or reference. When the attribute type of at least one attribute is numerical, the actual type of at least one attribute is a value type, and when the attribute type of at least one attribute is reference, the actual type of at least one attribute is a data structure defined in the table;
[0008] Add data information corresponding to at least one data structure to the table;
[0009] Generate data type script files based on a scripting language for all data structures defined in the table. The data type script files contain declarations of the data structures, definitions of all attributes in the data structures, and creation functions and constructors for the data structures.
[0010] Generate data information script files based on a scripting language for the data information in the table according to the data types of the data information. The data information script files contain data information sets created from all data information of the same data type.
[0011] Create a script program and load the data type script files and the data information script files.
[0012] Execute the script program.
[0013] Optionally, the data structure includes the data type name, the names and attribute types of each attribute in the data structure.
[0014] Optionally, the data structure further includes the remarks text of the data type and the remarks text of each attribute in the data structure.
[0015] Optionally, the data information includes the values of each attribute in the data structure. Among them, the value of an attribute with a reference type is a unique identification code, and the unique identification code is unique in the table corresponding to the data structure or globally.
[0016] Optionally, the step of generating data type script files based on a scripting language for all data structures defined in the table specifically includes:
[0017] Traverse all form pages in the table;
[0018] Based on the form page, obtain the data structure name, the names of each attribute in the data structure, the attribute types of each attribute in the data structure, and the remarks text of each attribute in the data structure;
[0019] Create a text file, and generate the declaration information of the corresponding data structure and the declaration information of the attributes according to the syntax requirements of the scripting language for the data structure name, the names of each attribute in the data structure, the attribute types of each attribute in the data structure, and the remarks text of each attribute in the data structure;
[0020] Add a creation function for the data type to the text file. The creation function is used to create an object based on the data type;
[0021] Add a constructor for the data type to the text file. The constructor is used to initialize the attributes in the object and assign values;
[0022] Rename the text file and modify its extension to change the text file to a data type script file.
[0023] Optionally, the steps of generating a data information script file based on the script language for the data information in the table include:
[0024] Traverse all the form pages in the table;
[0025] Based on the form page, obtain all the data information corresponding to the data structure in the form page;
[0026] Create a text file, generate a data structure object set for all the data information corresponding to the data structure according to the type of the data structure and the syntax requirements of the script language, and write it into the text file;
[0027] Rename the text file and modify its extension to change the text file to a data information script file.
[0028] Optionally, the script language is the Lua language.
[0029] Optionally, the table is Excel.
[0030] In a second aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the method for a script language to access data in a table in the above-mentioned first aspect of the technical solution and any of its optional solutions are implemented.
[0031] In a third aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps in the method for a script language to access data in a table in the above-mentioned first aspect of the technical solution and any of its optional solutions are implemented.
[0032] In the technical solution of the present application, by adding a data structure with reference type attributes to the table, the flexibility and scalability of the table data can be significantly improved, thereby reducing the coding pressure on developers, reducing costs, and improving development efficiency. Description of the Drawings
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the following will describe the drawings required to be used in the embodiments of the present application or the background technology.
[0034] Figure 1 Shows a flowchart of a method for a script language to access data in a table provided by an embodiment of the present application.
[0035] Figure 2 Shows a flowchart of generating a data type script file based on a script language provided by an embodiment of the present application.
[0036] Figure 3 The figure shows a flowchart of generating a data information script file based on a scripting language provided by an embodiment of the present application. Detailed implementation manners
[0037] In the description of the embodiments of the present invention, those skilled in the art should know that the embodiments of the present invention can be implemented as a method, a computer-readable storage medium, and a computer program product. Therefore, the embodiments of the present invention can be specifically implemented in the following forms: a complete software (including firmware, resident software, microcode, etc.), a form of combination of hardware and software. In addition, in some embodiments, the embodiments of the present invention can also be implemented in the form of a computer program product in one or more computer-readable storage media, and the computer-readable storage media contains computer program code.
[0038] The above-mentioned computer-readable storage media can adopt any combination of one or more computer-readable storage media. Computer-readable storage media include: electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or components, or any combination of the above. More specific examples of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fibers, CD-ROMs, optical storage devices, magnetic storage devices, or any combination of the above. In the embodiments of the present invention, the computer-readable storage media can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, device, or component.
[0039] The computer program code contained in the above-mentioned computer-readable storage media can be transmitted by any suitable medium, including: wireless, wire, optical cable, radio frequency (RF), or any suitable combination of the above.
[0040] The computer program code for performing the operations of the embodiments of the present invention may be written in assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine - related instructions, microcode, firmware instructions, status - setting data, integrated circuit configuration data, or in one or more programming languages or combinations thereof. The programming languages include object - oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as C language or similar programming languages. The computer program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand - alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), and may also be connected to an external computer.
[0041] The methods provided by the embodiments of the present invention are described by flowcharts and / or block diagrams.
[0042] It should be understood that each block of the flowchart and / or block diagram, and the combinations of blocks in the flowchart and / or block diagram, can be implemented by computer - readable program instructions. These computer - readable program instructions can be provided to a processor of a general - purpose computer, a special - purpose computer, or other programmable data - processing device, thereby producing a machine. These computer - readable program instructions, when executed by a computer or other programmable data - processing device, produce a device that implements the functions / operations specified in the blocks of the flowchart and / or block diagram.
[0043] These computer - readable program instructions can also be stored in a computer - readable storage medium that enables a computer or other programmable data - processing device to work in a specific manner. In this way, the instructions stored in the computer - readable storage medium produce an instruction device product that includes instructions for implementing the functions / operations specified in the blocks of the flowchart and / or block diagram.
[0044] The computer - readable program instructions can also be loaded onto a computer, other programmable data - processing device, or other device, such that a series of operation steps are executed on the computer, other programmable data - processing device, or other device to produce a computer - implemented process. Thus, the instructions executed on the computer or other programmable data - processing device can provide a process for implementing the functions / operations specified in the blocks of the flowchart and / or block diagram.
[0045] In the fields of data processing and software development, an innovative method is gradually changing the traditional way of data export and code interaction. Specifically, this method realizes the direct association between tabular data and Lua code types by carefully designing data structure definitions in Excel tables. This design allows developers to define data types in the table and make flexible references to them at other positions in the table before export. In this way, the same type can be completely defined in the table and can be used nested in the table or in Lua code, greatly enhancing the flexibility and convenience of data processing.
[0046] This innovative starting point breaks the gap between tabular data and code types in traditional data processing. The traditional way usually simply exports data as batch data for the program to load and run, lacking sufficient flexibility and functionality. In contrast, the new method not only focuses on data export but also endows tabular data with more functionality and flexibility. By defining data types and completing the composite structure design between types, developers can complete complex data structure designs in the table without writing a large amount of code.
[0047] The core advantage of this design is that it can complete complex data type definitions and composite structure designs in the table. This means that developers can directly define data types in the table and build complex data structures by nesting these types. This method significantly reduces the code writing work of developers, reduces costs, improves efficiency, and increases the convenience of use. By reducing the amount of code, developers can focus more on the implementation of business logic, thus accelerating the product development process. In addition, the form of type definition in the table is also intuitive. Developers can clearly see the definition and nesting relationship of the data structure, making it easier to understand and process the data structure. This intuitiveness reduces the cost of understanding and communication, enabling team members to reach a consensus faster and improving collaboration efficiency.
[0048] More importantly, this method allows the use of predefined types for nesting in the table. Developers can nest these types in the table in the form of data fields or data content and then export them together for use. In this way, what is exported by Excel will not only be batch data composed of basic data types but also can include the definition and nested use of more complex composite data structures. This key innovation point significantly enhances the richness and complexity of the exported data, exceeding the simple batch data of traditional exports. Through this method, developers can handle complex data structures more flexibly to meet diverse business needs.
[0049] The embodiments of the present invention will be described below with reference to the accompanying drawings in the embodiments of the present invention.
[0050] Figure 1 The flowchart of a method for accessing data in a table by a scripting language provided by an embodiment of the present invention is shown. As Figure 1 shown, the method includes the following steps:
[0051] Define at least one data structure in the table, where the data structure includes at least one attribute, and the attribute type of at least one attribute is numeric or reference type. When the attribute type of at least one attribute is numeric, the actual type of at least one attribute is value type, and when the attribute type of at least one attribute is reference type, the actual type of at least one attribute is the data structure defined in the table;
[0052] Add data information corresponding to at least one data structure to the table;
[0053] Generate data type script files based on the scripting language for all data structures defined in the table respectively. The data type script files contain declarations of data structures, definitions of all attributes in the data structures, and creation functions and constructor functions of the data structures;
[0054] Generate data information script files based on the scripting language for the data information in the table according to the data type of the data information. The data information script files contain data information sets created from all data information of the same data type;
[0055] Create a script program and load the data type script files and data information script files;
[0056] Execute the script program.
[0057] The present invention proposes an efficient data processing and software development method, the core of which is to use a table to define complex data structures and automatically generate data type and data information script files required by a scripting language (such as Lua, Python, etc.).
[0058] First, the user can define at least one data structure in a table (such as Excel or other spreadsheet software). Each data structure contains at least one attribute, and the numerical types of these attributes can be numerical (such as integers, floating-point numbers) or reference types. When the numerical type of an attribute is a reference type, it actually points to other data structures defined in the table. This design allows for the construction of complex data type hierarchies in the table. After defining the data structures, the user can fill in the data information corresponding to these data structures in the table. This information can be specific numerical values or references to other data structures, and the content filled in is related to the type of the specific attribute. A text editing program can be written programmatically, and its purpose is to extract the data in the table and convert it into a file format supported by the scripting language. The program reads the information in the table and automatically generates a data type script file based on the target scripting language according to the data structure definition in the table. This file contains the declarations of the data structures, the definitions of all attributes, and the functions for creating and constructing the data structures. This greatly reduces the burden on developers to manually write these scripts. Similarly, the program will generate a data information script file based on the data information in the table according to the target scripting language. This file contains a data information set composed of all data information of the same data type, facilitating batch processing and operations in the script program. The developer creates a new script program and loads the previously generated data type script file and data information script file. In this way, the script program can directly access and use these predefined data structures and data information. Finally, the developer executes the script program and uses the loaded data structures and data information to perform specific business logic or data processing tasks.
[0059] All data structures and data information are centrally stored in the table, making it more intuitive and convenient to modify and update the data. When the data structure changes, only the table needs to be updated and then the script file is regenerated, without the need to manually modify a large amount of code. The design of reference type attributes allows for the construction of complex data type hierarchies in the table, making the data structure more flexible and extensible. This helps to meet diverse business needs and improve the customizability and adaptability of the software. By automatically generating data type and data information script files, the present invention significantly reduces the workload of developers to manually write code. This not only speeds up the development process but also reduces the error rate. The data structure definition and data information filling in table form enable non-technical personnel to participate in the data design and modification process, thus promoting collaboration and communication among teams.
[0060] In some embodiments, optionally, the data structure includes but is not limited to the following necessary elements: the data type name, the names of the attributes in the data structure, and the attribute types. The data type name is used to uniquely identify the name of the data structure, facilitating reference and operation in the code; the attribute name is used to uniquely identify the name of the attribute, ensuring accurate access within the data structure; the attribute type specifies the data type of the attribute, such as integer, floating-point number, string, boolean, array, object, or other custom data types, to ensure data consistency and accuracy. Additionally, if the scripting language or programming environment supports other parameters for defining data structures, the data structure should also include these additional parameters, including but not limited to:
[0061] Default value: Specify a default value for some attributes to be automatically filled when creating an instance of the data structure;
[0062] Nullable: Indicate whether the attribute allows null values to enhance data integrity verification;
[0063] Constraints: Define the range or format requirements of the attribute values, such as minimum / maximum values, regular expression matching, etc., to further ensure data validity.
[0064] By clearly requiring the data type name, attribute name, and attribute type as necessary elements for defining the data structure, it ensures consistent understanding and use of the data structure among different developers and projects, reducing data errors caused by misunderstandings or confusions; providing a detailed list of attributes and type information for each attribute enables other developers to quickly understand the composition and usage of the data structure. At the same time, the additional description information helps to explain the purpose of complex attributes or data structures, reducing the learning cost of the code; by introducing additional parameters such as default values, nullable, and constraints, the system or method can automatically perform data verification when creating or modifying data, effectively preventing invalid or unexpected data from being entered, thereby improving the stability and data quality of the application; considering that different scripting languages or programming environments may have different definitions of data structures, the design of this embodiment allows for the inclusion of environment-specific additional parameters, ensuring that the definition of the data structure can be widely applicable to various technology stacks, enhancing the compatibility and scalability of the system.
[0065] In some embodiments, optionally, the data structure further includes a note text for the data type and note texts for each attribute in the data structure. Provide a short description or explanatory text for the entire data type, aiming to elaborate on the design purpose, usage scenarios, or important considerations of the data type. This note text aims to reduce the cost of explaining the data type to non-professionals, enabling them to understand the purpose and importance of the data type more quickly. For each attribute in the data structure, provide a short description or explanatory text. These note texts should detail the meaning, value range, intended use, or relationship with other attributes of the attribute, as well as any considerations that may affect data integrity. By providing note texts for the attributes, the readability of the tabular data can be significantly improved, enabling non-professionals to easily understand and correctly fill in the parameter data.
[0066] By providing note texts for the data type and attributes, the system or method can significantly reduce the cost of explaining the data structure to non-professionals. These note texts serve as built-in "help documents", enabling users to quickly understand the purpose and filling requirements of the data structure without the need to consult additional documents or experts. The note texts provide intuitive context information for each element in the data structure, making the tabular data easier to understand and read. This is particularly helpful for non-professionals who may not be familiar with specific data structures or terminology but can quickly grasp the key information through the note texts. The note texts not only provide information but also serve as a guide. By clarifying the value range, intended use, and considerations of the attributes, the note texts help users fill in the data correctly, thereby reducing errors and inconsistencies. This is crucial for maintaining data quality, especially in large projects involving multiple departments or teams. Traditionally, the definition and management of data structures have often been the responsibility of professionals. However, by introducing note texts, the system or method provides a possibility for non-professionals to participate in the writing of parameter data. This enables the project team to utilize resources more widely and improve the efficiency and flexibility of data management.
[0067] In some embodiments, optionally, the data information includes the values of each attribute in the data structure. Among them, the value of an attribute of the reference type is a unique identifier, and the unique identifier remains unique in the table corresponding to the data structure or globally. For an attribute of the reference type in the data structure, its value is set as a unique identifier (UniqueIdentifier, UID). This unique identifier remains unique in the table corresponding to the data structure or globally, ensuring that each reference-type attribute can accurately point to its associated data object or entity. By looking up the unique identifier, the program can quickly and accurately locate the storage location of the corresponding data. This mechanism avoids the possible data lookup delays and errors in traditional methods and improves the efficiency of data retrieval. As a bridge between data, the unique identifier ensures that the relevant data in different data structures or tables can be correctly associated. When the data is updated or changed, the consistency of the data can be easily maintained through the unique identifier. Due to the uniqueness and non-replicability of the unique identifier, it can also be used as a means of data access control to enhance data security.
[0068] Suppose there is an employee management system that includes an employee information table and a department information table. There is an attribute "department ID" in the employee information table. This attribute is of the reference type, and its value is the unique identifier of the corresponding department in the department information table. When querying the department information of a certain employee, the program only needs to look up the corresponding record in the department information table according to the "department ID" (i.e., the unique identifier) in the employee information table to quickly obtain the department information of the employee. If the name or description of a certain department changes, only the record corresponding to the unique identifier in the department information table needs to be updated, without modifying the "department ID" in the employee information table, thus ensuring the consistency of the data. At the same time, due to the uniqueness and non-replicability of the unique identifier, even without a strict access control mechanism, it can prevent data from being illegally tampered with or misused to a certain extent.
[0069] Through the use of the unique identifier, the program can quickly locate the required data, avoiding the complex lookup process that may exist in traditional methods, thereby improving the efficiency of data retrieval. As a bridge between data, the unique identifier ensures that the relevant data in different data structures or tables can be correctly associated, and even when the data is updated or changed, the consistency of the data can be easily maintained.
[0070] In some embodiments, optionally, the step of generating data type script files based on a scripting language for all data structures defined in the table specifically includes:
[0071] Traverse all form pages in the table;
[0072] Based on the form page, obtain the data structure name, the names of each attribute in the data structure, the attribute types of each attribute in the data structure, and the comment text of each attribute in the data structure;
[0073] Create a text file, and generate the declaration information of the corresponding data structure and the declaration information of the attributes according to the syntax requirements of the scripting language for the data structure name, the names of each attribute in the data structure, the attribute types of each attribute in the data structure, and the comment text of each attribute in the data structure;
[0074] Add a creation function for the data type to the text file, and the creation function is used to create an object based on the data type;
[0075] Add a constructor function for the data type to the text file, and the constructor function is used to initialize the attributes in the object and assign values;
[0076] Rename the text file and modify the extension name to change the text file to a data type script file.
[0077] The program first reads a table file containing the data structure. This file may contain multiple form pages, and each form page defines a different data structure; traverse all form pages to ensure that each form page is processed one by one; obtain the data structure information in the form page, extract the data structure name from the header or specified position of the form page, traverse each column in the form page, which can be the column name or the value of a specific row in the column, so as to obtain the name of each column, that is, the names of each attribute in the data structure; traverse the value of a specific row in each column in the form page to obtain the numerical type of each column; traverse the value of a specific row in each column in the form page to obtain the comment text of each column. The comment text may be stored in a specific cell of the table or in an attached comment; create a new text file to store the generated script content. According to the syntax requirements of the scripting language, convert the data structure name, the names of each attribute, the attribute type, and the comment text into the corresponding data type declarations and attribute declarations. The comment text can be converted into comments or docstrings in the script to facilitate subsequent developers to understand the purpose and limitations of the attributes; add a creation function to the text file, which is used to create a new object instance according to the defined data structure, and add a constructor function to the text file, which is automatically called when the object is created and is responsible for initializing all the attributes in the object and assigning values to them as needed. These values can be default values, parameter values passed from the creation function, or values calculated according to other logic; after completing the above steps, rename the generated text file to a descriptive name and modify its extension name to the extension name corresponding to the scripting language,
[0078] such as.js,.py,.lua.txt, etc. This step ensures that the generated script file conforms to the naming convention of the scripting language, facilitating subsequent development and deployment.
[0079] This method automatically converts the data structure in a table into a data type script file in a scripting language, greatly reducing the manual coding workload and improving development efficiency. Since this method defines the data structure based on the table, it is possible to easily add or modify the data structure without modifying the code. This enhances the flexibility and scalability of the system. The automated process reduces errors that may occur during manual coding, such as spelling mistakes and type mismatches. At the same time, the accuracy of the code is improved through explicit attribute types and note information. The generated script file follows the specifications of the scripting language and can therefore run on different operating systems and platforms, enhancing the cross-platform capabilities and compatibility of the system.
[0080] In some embodiments, optionally, the steps of generating a data information script file based on a scripting language from the data information in the table include:
[0081] Traverse all form pages in the table;
[0082] Based on the form page, obtain all the data information corresponding to the data structure in the form page;
[0083] Create a text file, and generate a data structure object set for all the data information corresponding to the data structure according to the type of the data structure and the syntax requirements of the scripting language, and write it into the text file;
[0084] Rename the text file and modify the file extension to change the text file into a data information script file.
[0085] Open and access the table through a program, visit each form page in the table one by one to ensure that no data is missed; analyze the data structure of each form page, identify data columns and data types (such as strings, numbers, dates, etc.); read the data of each row and each column to ensure the integrity and accuracy of the data; create a new text file in the local file system or a specified storage location, set an appropriate file encoding (such as UTF-8) to ensure the correct display of character data; according to the syntax rules of the target scripting language, construct a data structure object set, and for different types of data (such as arrays, dictionaries, objects, etc.), use corresponding syntax elements for encapsulation to ensure that the hierarchical relationship and nested structure between data objects are correct; serialize the constructed data structure object set into a string form, and use the file write operation to write the string content line by line or at once into the previously created text file; according to the naming convention of the target scripting language or project specifications, rename the text file and modify the file extension to the extension of the target scripting language, such as.js,.py,.lua.txt, etc., to indicate its data type and purpose.
[0086] Convert the tabular data into a data structure object of a scripting language to make the data more understandable and usable; automate the processing of tabular data by the program to reduce manual intervention and improve the speed and accuracy of data conversion; the generated data information script file can be directly used in the scripting language environment, facilitating the secondary development and reuse of the data; by generating data information script files in different scripting languages, it can flexibly adapt to different development environments and requirements.
[0087] In some embodiments, optionally, the scripting language is the Lua language and the table is Excel.
[0088] Lua is a lightweight, embedded scripting language designed to be embedded in applications to provide flexible extension and customization capabilities for the applications. The Lua language has a concise syntax, high execution speed, and good cross-platform compatibility, making it a popular choice in fields such as game development, embedded systems, and automated script writing. The table data structure of Lua is particularly powerful and can flexibly represent various data structures such as arrays, sets, and records, making it very suitable for handling complex data relationships.
[0089] Excel is a spreadsheet software in the Microsoft Office suite, widely used in data recording, analysis, processing, and visualization. An Excel table consists of multiple worksheets, and each worksheet contains rows and columns for storing and displaying data. Excel supports rich data types and functions and can handle complex calculations, data filtering, sorting, and chart generation. The popularity and ease of use of Excel make it one of the preferred tools for data management and analysis.
[0090] The Lua scripting language needs to process data from Excel spreadsheets to generate script files that conform to Lua syntax rules. Since Lua's table data structure can flexibly represent various data relationships, it is very suitable for processing complex data in Excel spreadsheets; by writing Lua scripts, data can be automatically read from Excel spreadsheets, processed, and Lua script files can be generated, thereby improving the efficiency and accuracy of data processing. For example, install a library for reading Excel files (such as luaxlsx or lua-office) in the Lua environment so that Lua scripts can access Excel files. According to Lua's syntax rules, convert the data in Excel into a Lua table data structure. For complex data relationships, such as nested tables or merged cells, special processing is required to ensure data integrity and accuracy; serialize the converted Lua table data structure into a string form and write it into a new Lua script file. Ensure that the naming and file extension of the script file conform to the naming convention of Lua scripts; verify and test the generated Lua script file to ensure the correctness of data conversion and the usability of the script.
[0091] By combining the advantages of the Lua language and Excel spreadsheets, this solution can efficiently process Excel spreadsheet data and generate script files that conform to Lua syntax rules, providing strong support for data management and automated processing. The program converts Excel data into a Lua table data structure, making the data easier to understand and use, facilitating subsequent data analysis and processing; the generated Lua script file can be directly run in the Lua environment, facilitating secondary development and reuse of data, and improving development efficiency; automate the processing of Excel spreadsheet data, reduce manual intervention, and improve the speed and accuracy of data processing; the automated script can automatically update the Lua script file as the Excel spreadsheet data changes, reducing the workload and error rate of manual updates and lowering the maintenance cost.
[0092] Example 1
[0093] In Example 1, the small game of Snake is used as a reference case. First, create four sheets in the Excel spreadsheet. The content of the sheets is as follows: scene, snake, snake attributes, and snake resources. The specific content is as follows:
[0094] Scene sheet:
[0095] # Scene # ID Difficulty TargetScore Snake1 Snake2 # int string int Snake Snake # Integer: Number String: Difficulty Integer: Clearance Score Reference: Snake 1 Reference: Snake 2 1001 Simple Scene 10000 1001 1002 1002 Normal Scene 30000 2001 2002 1003 Difficult Scene 80000 3001 3002
[0096] Snake sheet:
[0097]
[0098]
[0099] Snake Attribute Table:
[0100] # SnakeProperty # ID Length Speed # int int int # Integer: Number Integer: Initial Length Integer: Speed 1001 100 3.5 1002 150 5.5 2001 200 8.5 2002 250 11.5 3001 300 13.5 3002 350 15.5
[0101] Snake Resource Table:
[0102] # SnakeResource # ID SkinPath SoundPath # int string string # Integer: Number String: Skin Resource Path String: Sound Effect Resource Path 1001 Assets / Game / Pics / Skin1.png Assets / Game / Sounds / Sound1.mp4 1002 Assets / Game / Pics / Skin2.png Assets / Game / Sounds / Sound2.mp4 2001 Assets / Game / Pics / Skin3.png Assets / Game / Sounds / Sound3.mp4 2002 Assets / Game / Pics / Skin4.png Assets / Game / Sounds / Sound4.mp4 3001 Assets / Game / Pics / Skin5.png Assets / Game / Sounds / Sound5.mp4 3002 Assets / Game / Pics / Skin6.png Assets / Game / Sounds / Sound6.mp4
[0103] From the data in the above table, it can be concluded that the table can include attributes of numerical types, such as the ID attribute in the Scene class, and can also include attributes of reference types, such as the Snake1 attribute in the Scene class. At the same time, the class corresponding to Snake1 is the Snake class, and the Snake class also contains an attribute Property of type SnakeProperty, that is, nested reference types can be implemented.
[0104] For the design of the above table, the row with the first cell being "#" records the data structure definition part. The first row represents the class name, such as "SnakeResource", the second row represents the attribute name, such as "SkinPath", the third row represents the attribute type, such as "string", and the fourth row represents the attribute comment, such as "String: Skin resource path". The data row with the first cell being empty records the data corresponding to the class.
[0105] The program first reads each sheet in the Excel and parses the data in the above table according to the above rules, and generates data type script files and data information script files based on the Lua scripting language respectively according to different types. The specific content recorded in the data type script file is the declaration of the data structure, the definition of all attributes in the data structure, and the creation function and constructor of the data structure; the data information script file contains a data information set created by all data information of the same data type.
[0106] The file names of the created files are as follows:
[0107] SceneObjects.lua.txt Scene Class Data Information File SnakeObjects.lua.txt Snake Class Data Information File SnakePropertyObjects.lua.txt Snake Property Class Data Information File SnakeResourceObjects.lua.txt Snake Resource Class Data Information File Scene.lua.txt Scene Class Data Type File Snake.lua.txt Snake Class Data Type File SnakeProperty.lua.txt Snake Property Class Data Type File SnaleResource.lua.txt Snake Resource Class Data Type File
[0108] Among them, the data type file is defined by adding a suffix to the name of the class of the data structure. For example, the data type file name of the scene class is: Scene.lua.txt, where "Scene" is the class name and ".lua.txt" is the file suffix; the data information file is composed of the class name of the data structure plus Objects plus a suffix. For example, the data information file of the scene class has the name: SceneObjects.lua.txt, where "Scene" is the scene class name, ".lua.txt" is the file suffix, and Objects represents the object set of this type.
[0109] After the program reads the specific data in each table, it parses the data in the table according to the above rules and generates relevant files. Taking the scenario class as an example, the generation rules of the new data message script file based on the Lua language are illustrated as follows:
[0110] By reading the table, the program will obtain the various attributes, attribute types, and attribute names of the data, and thus create a data information list object based on the data type. Specifically:
[0111] SceneObjects = {
[0112] [“1001”] = Scene:Create({ID = 1001, Difficulty = ”Simple scenario”, TargetScore = 10000, Snake1 = 1001, Snake2 = 1002}),
[0113] [“1002”] = Scene:Create({ID = 1002, Difficulty = ”Normal scenario”, TargetScore = 30000, Snake1 = 2001, Snake2 = 2002}),
[0114] [“1003”] = Scene:Create({ID = 1003, Difficulty = ”Difficult scenario”, TargetScore = 80000, Snake1 = 3001, Snake2 = 3002})
[0115] }
[0116] Following the rules of the Lua scripting language, all the data in the data type are assigned to the objects of each data structure according to different attribute types. For example, integer and reference types do not require quotation marks, and string types require quotation marks, etc., which are the rules in the Lua scripting language. Finally, the list object corresponding to the data type is created, written, and saved in the corresponding data information script file.
[0117] Taking the Snake type as an example, the creation rules of the data type script file are illustrated
[0118] ---@class Snake
[0119] ---@field ID number
[0120] ---@field Property SnakeProperty
[0121] ---@field Resource SnakeResource
[0122] local Snake = class('Snake')
[0123] The above is the definition of a type, that is, defining a class with the type name "Snake".
[0124] Among them, "field" is the prefix for property definition, indicating that the subsequent defined content is a property in the type, "number" indicates that the defined property type is an integer type, and "ID" indicates the defined property name.
[0125] Among them, "Property" and "Resource" are property names, and "SnakeProperty" and "SnakeResource" are the names of their respective corresponding reference types.
[0126] --- Creation function
[0127] ---@type fun(args:table):Snake
[0128] ---@param args table
[0129] ---@return Snake
[0130] Function Snake:Create(args)
[0131] return Snake.new(args)
[0132] end
[0133] The above function is an object creation function for the Snake class based on the Lua script. Through this function, an operation object corresponding to the Snake class is created.
[0134] --- Constructor
[0135] @type fun(args:table):void
[0136] @param args table
[0137] function Snake:ctor(args)
[0138] Snake.super.ctor(self,args)
[0139] self.ID = args.ID
[0140] self.Property = SnakePropertyObjects[args.Property]
[0141] self.Resource = SnakeResourceObjects[args.Resource]
[0142] end
[0143] The above function is the constructor of the Snake class based on the Lua script, which initializes the data for the object of the created Snake class. In the constructor, "self" represents the object of this class. The Snake class contains three attributes, namely ID, Property, and Resource. Among them, the attribute type of the ID attribute is numeric, which is directly passed into the constructor through parameters and assigned values. The Property attribute and the Resource attribute are reference types. The program can read the type name of this reference type to find the set storing the data of this type, such as SnakePropertyObjects and SnakeResourceObjects. By passing the reference value in the parameters, the specific value of the relevant type can be found in the set, such as SnakePropertyObjects[args.Property].
[0144] In the Lua script, the data information script file is responsible for storing the data of the specified type, and the data definition script file is responsible for storing the class definition, creation function, and constructor to complete the creation and initialization of the relevant objects. And through the program, the data storage sets of all reference types can be queried to complete the data initialization work of the reference types. Then, by creating an execution script, the script will automatically load all the script files created by the program and finally execute the relevant script program.
[0145] In the above embodiment, the method is described based on a series of steps. However, the present invention is not limited to the order of the steps. Instead, some steps can be executed simultaneously with other steps or can be executed in a different order from other steps. In addition, those of ordinary skill in the art should understand that these steps are not mutually exclusive, and without affecting the scope of the present invention, other steps can be added to the flowchart or some steps can be deleted.
[0146] As described above, it is only the specific implementation manner of the embodiments of the present invention. However, the protection scope of the embodiments of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the embodiments of the present invention can easily think of changes or substitutions, which should all be covered within the protection scope of the embodiments of the present invention. Therefore, the protection scope of the embodiments of the present invention should be subject to the protection scope of the claims.
Claims
1. A method for accessing data in a table using a scripting language, characterized in that: include: At least one data structure is defined in a table, the data structure includes at least one attribute, the attribute type of the at least one attribute is a numeric type or a reference type, when the attribute type of the at least one attribute is a numeric type, the actual type of the at least one attribute is a value type, when the attribute type of the at least one attribute is a reference type, the actual type of the at least one attribute is the data structure defined in the table; Adding data information corresponding to the at least one data structure in the table; Generate data type script files based on the scripting language for all the data structures defined in the table, wherein the data type script files include declarations of the data structures, definitions of all attributes in the data structures, and creation functions and constructors of the data structures; Generate a data information script file based on the scripting language from the data information in the table according to the data type of the data information, wherein the data information script file includes a data information set created by all the data information of the same data type; Create a script program and load the data type script file and the data information script file; Execute the script program.
2. The method according to claim 1, characterized in that The data structure includes a data type name, a name of each attribute in the data structure, and an attribute type.
3. The method according to claim 2, characterized in that The data structure also includes a remark text of the data type and a remark text of each attribute in the data structure.
4. The method according to claim 1 or 3, characterized in that: The data information includes the value of each attribute in the data structure, wherein the value of the attribute whose attribute type is reference type is a unique identification code, and the unique identification code remains unique in the table corresponding to the data structure or globally.
5. The method according to claim 4, characterized in that The step of generating data type script files based on the scripting language for all data structures defined in the table specifically includes: Traverse all form pages in the table; Based on the form page, obtaining the name of the data structure in the form page, the name of each attribute in the data structure, the attribute type of each attribute in the data structure, and the remark text of each attribute in the data structure; Creating a text file, generating corresponding data structure declaration information and attribute declaration information according to the grammatical requirements of the scripting language by using the data structure name, the name of each attribute in the data structure, the attribute type of each attribute in the data structure, and the remark text of each attribute in the data structure; Adding a creation function of the data type to the text file, wherein the creation function is used to create an object based on the data type; Adding a constructor of the data type to the text file, the constructor being used to initialize the attributes in the object and assign values; Rename the text file and modify its extension, and change the text file into the data type script file.
6. The method according to claim 5, characterized in that The step of generating a data information script file based on the script language from the data information in the table comprises: Traverse all form pages in the table; Based on the form page, obtaining all data information corresponding to the data structure in the form page; Creating a text file, generating a data structure object set for all data information corresponding to the data structure according to the type of the data structure and the grammatical requirements of the scripting language, and writing the data structure object set into the text file; Rename the text file and modify its extension, and change the text file into the data information script file.
7. The method according to claim 6, characterized in that The scripting language is Lua language.
8. The method according to claim 7, characterized in that The table is in Excel.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps in the method for accessing data in a table using a scripting language as described in any one of claims 1 to 8 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps in the method for accessing data in a table using a scripting language according to any one of claims 1 to 8 are implemented.