WO2019179021A1 - Method and apparatus for importing excel data into database, and computer device and storage medium - Google Patents

Method and apparatus for importing excel data into database, and computer device and storage medium Download PDF

Info

Publication number
WO2019179021A1
WO2019179021A1 PCT/CN2018/101991 CN2018101991W WO2019179021A1 WO 2019179021 A1 WO2019179021 A1 WO 2019179021A1 CN 2018101991 W CN2018101991 W CN 2018101991W WO 2019179021 A1 WO2019179021 A1 WO 2019179021A1
Authority
WO
WIPO (PCT)
Prior art keywords
relational database
excel
field
conversion result
correspondence
Prior art date
Application number
PCT/CN2018/101991
Other languages
French (fr)
Chinese (zh)
Inventor
占锐
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2019179021A1 publication Critical patent/WO2019179021A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/254Extract, transform and load [ETL] procedures, e.g. ETL data flows in data warehouses

Definitions

  • the present application relates to the field of data processing technologies, and in particular, to a method, an apparatus, a computer device, and a storage medium for importing an Excel data into a database.
  • the embodiment of the present invention provides a method, a device, a computer device, and a storage medium for importing an Excel data into a database, which can process data to be processed according to a conversion rule in the process of importing Excel data into a database, and then import and improve data import. effectiveness.
  • an embodiment of the present application provides a method for importing Excel data into a database, where the method includes:
  • an embodiment of the present application provides an apparatus for importing an Excel data into a database, the apparatus comprising means for performing the method of importing the Excel data into the database according to the first aspect.
  • an embodiment of the present application provides a computer device, where the computer device includes a memory, and a processor connected to the memory;
  • the memory is for storing a computer program for executing a computer program stored in the memory to perform the method of importing Excel data into the database according to the first aspect.
  • an embodiment of the present application provides a computer readable storage medium, where the computer readable storage medium stores a computer program, where the computer program includes program instructions, and when the program instructions are executed by a processor, implementing the foregoing The method of importing Excel data into a database according to the first aspect.
  • the embodiment of the present application connects Excel to the relational database through the Excel VBA program, determines the conversion rule according to the correspondence relationship and related attributes of the fields in the correspondence table of the relational database, and then converts the value of the corresponding column of the field in the Excel table into the conversion rule according to the conversion rule.
  • the relational database corresponds to the value of the column corresponding to the field in the table and displays the conversion result in Excel, and imports the conversion result into the relational database.
  • the embodiment of the present application uses the determined conversion rules to process the data to be processed, and then import, thereby improving the efficiency of data import; before the import, the conversion result is displayed in Excel for convenience.
  • the user view is so convenient for the user to operate and improve the user experience.
  • FIG. 1 is a schematic diagram of a scenario of a method for importing Excel data into a database provided by an embodiment of the present application
  • FIG. 2 is a schematic flowchart of a method for importing Excel data into a database according to an embodiment of the present application
  • FIG. 3 is a schematic diagram of a sub-flow of a method for importing Excel data into a database according to an embodiment of the present application
  • FIG. 4 is a schematic diagram of another sub-flow of a method for importing Excel data into a database according to an embodiment of the present application
  • FIG. 5 is a flow chart showing an example of a method for importing an Excel data into a database according to another embodiment of the present application.
  • FIG. 6 is a schematic block diagram of an apparatus for importing an Excel data into a database provided by an embodiment of the present application
  • FIG. 7 is a schematic block diagram of a setting unit provided by an embodiment of the present application.
  • FIG. 8 is a schematic block diagram of an import unit provided by an embodiment of the present application.
  • FIG. 9 is a schematic block diagram of an apparatus for importing an Excel data into a database according to another embodiment of the present application.
  • FIG. 10 is a schematic block diagram of a computer device according to an embodiment of the present application.
  • FIG. 1 is a schematic diagram of a method for importing Excel data into a database according to an embodiment of the present application.
  • the user receives the requirement to import the data in an Excel table with multiple rows and columns into the relational database, first connect the Excel to the relational database through the Excel VBA program; read the relational database table through the driver such as the ADO driver.
  • All the fields and field attributes are returned to Excel; the correspondence between the fields in the Excel table and the relational database table is set by Excel VBA; the related attributes of the corresponding fields in the relational database are analyzed; according to the corresponding relationship of the fields and related attributes, Determining a conversion rule, and using the conversion rule to convert the value of the column corresponding to the field in the Excel table to the value of the column corresponding to the field in the relational database according to the corresponding relationship of the field and display the conversion result in Excel; when the receiving user clicks When importing the import request generated by the button, the conversion result displayed in Excel is imported into the relational database through the ADO driver.
  • the determined conversion rules are used to process the data to be processed, and then imported, thereby improving the efficiency of data import; before the import, the conversion result is displayed in Excel, so that the user can view the conversion.
  • the result is an error, which is convenient for the user to operate and improves the user experience.
  • FIG. 2 is a schematic flowchart diagram of a method for importing Excel data into a database according to an embodiment of the present application. The method includes the following steps S201-S206.
  • the relational database is a database based on the relational model.
  • Relational databases include Oracle databases, SQL Server databases, My SQL databases, and more.
  • the following example will use the Oracle database as an example.
  • Excel is connected to the relational database through the Excel VBA program.
  • the Excel is connected to the relational database by using the driver, for example, the Excel is connected to the Oracle database through the ADO driver.
  • ADO ActiveX Data Objects
  • ADO ActiveX Data Objects
  • Excel needs to reference the ADO driver library when connecting to the Oracle database via VBA.
  • To reference the ADO driver library follow these steps: 1. Open the VBA editor, click on “Tools”, “References” in the menu; check “Microsoft ActiviteX Data Objects 2.8 Library” and “Microsoft ActiviteX Data ObjectS Recordset 2.8 Library” Option to ensure that the ADO driver library is selected.
  • the ADO driver library name may be another name.
  • the ADO driver library such as calling the ADO driver library open method, enter the corresponding user name, password, Oracle database server name, etc. in the open method to open the Oracle database and establish a connection with the Oracle database.
  • the create object function is called to create an ADO object, and an object function such as CreateObject is created.
  • the open method of the ADO object After creating the ADO object, call the open method of the ADO object, enter the corresponding user name, password, Oracle database server name, etc. in the open method to open the Oracle database, establish a connection with the Oracle database, and maintain a connection with the Oracle database.
  • the specific driver is not limited, and may be an ADO driver or an ODBC (Open Database Connectivity) driver. It is also possible to select the driver that best matches the corresponding database according to the specific database.
  • Data Source represents the database server name
  • User Id and Password respectively represent the user name and password to connect to the database.
  • Each field has a corresponding attribute, and a field is added in the corresponding table and the attribute corresponding to each field is set. If the attribute includes a field name, a field type, a field length, etc., the attribute may also include a uniqueness constraint, a primary key constraint, and the like.
  • the number of fields in the relational database correspondence table is less than or equal to the number of fields in the Excel table. If the number of fields in the relational database correspondence table is equal to the number of fields in the Excel table, it can be understood that all the columns in the Excel table need to be imported into the relational database.
  • the number of fields in the relational database correspondence table is smaller than the number of fields in the Excel table, it can be understood that only the data of some columns in the Excel table need to be imported into the relational database. It should be noted that creating a table in the relational database and adding a field in the corresponding table may be performed before step S101, or may be performed after step S101. Creating a table and adding fields in the corresponding table can be done by executing the corresponding SQL language. After there is a corresponding table in the relational database, the correspondence between the fields in the Excel table and the fields in the relational database correspondence table is set. Set the correspondence by VBA programming.
  • the step S202 includes steps S301-S303.
  • S302 Set a correspondence between a field in the Excel table and a field in the correspondence table of the relational database.
  • the correspondence relationship can be understood as which column of the corresponding table in the Oracle database is imported into the corresponding column of the Excel table.
  • the field in the relational database correspondence table refers to a field in which the correspondence relationship is set in the relational database.
  • Read the related attributes of the fields in the Oracle database correspondence table and the corresponding table such as the field name, field type, and field length.
  • the related attributes of the read are obtained through the VBA program, and the related attributes of the fields in the correspondence table of the relational database are obtained. Parse the relevant properties obtained. If the field name is date and the field type is date, the date data type in the Oracle database includes century, year, month, day, hour, minute, and second. A total of 7 bytes are occupied.
  • the conversion rule is determined according to the field in the excel table and the field type of the field in the relational database correspondence table.
  • the field type of the date field in the Excel table is char
  • the field type of the corresponding date field in the Oracle database is date, which is a field of two different data types
  • the conversion rule is: the field corresponding to the column data of the Excel table.
  • the type is converted from char to the Oracle database corresponding field type date. In this way, the date data in the Excel table can be imported into the Oracle database.
  • the field type corresponding to the column data of the field needs to be converted from int to the field type flout of the corresponding field of the relational database.
  • the step S205 includes: obtaining a value of a column corresponding to a field in each row of the Excel table; and converting, by using the conversion rule, a value of a column corresponding to a field in each row of the Excel table according to a correspondence relationship of the field
  • the value corresponding to the column in the field in the Oracle database corresponds to the table; the conversion result is displayed in Excel. It can be understood that in the present embodiment, the conversion is completed line by line.
  • the value of the column corresponding to the field in the Excel table may also be obtained; using the conversion rule, the value of the corresponding column of the Excel table field is converted into the column corresponding to the field in the corresponding table of the Oracle database according to the corresponding relationship of the field.
  • the step S206 includes the following steps S401-S402.
  • S401 Compare the data in the conversion result with the data stored in the relational database correspondence table. After receiving the import instruction, the comparison of the data is performed. When comparing, compare the data of each row in the conversion result with the data stored in the relational database correspondence table, for example, according to the column of the primary key constraint in the Oracle database correspondence table and the value of the corresponding column in the conversion result, To quickly determine whether there is data for the corresponding row. After judging that there is data of the corresponding row, the data of the corresponding row is compared to determine whether the data of the corresponding row in the conversion result is consistent with the data in the relational database. After all the data are compared, S402 is executed.
  • the data in the conversion result is imported into the relational database; if there is data in the relational database that is consistent with the conversion result, a prompt is given, such as In the form of a dialog box, "consistent data already exists in the database, whether to re-import"; if there is data in the relational database that is inconsistent with the conversion result, the inconsistent data is updated to the data in the conversion result in units of rows.
  • the data of a column in a row in the conversion result is inconsistent with the data of the corresponding row in the relational database, the data of the row in the relational database is updated by the data of the row in the conversion result; if the data of the row in the conversion result is multi-row If it does not exist in the relational database, the data of the multiple rows is inserted into the relational database in units of rows.
  • the Excel data is used in the process of importing the database, and the data to be processed is processed, and then imported, thereby improving the efficiency of data import; before the import, the conversion result is displayed in Excel for the user to view. This facilitates further user operations and improves the user experience.
  • FIG. 5 is a schematic flowchart of a method for importing Excel data into a database according to another embodiment of the present application.
  • the method includes steps S501-S508. Among them, steps S506-S507 are added.
  • the other steps are the same as those shown in the embodiment of FIG. 2 .
  • please refer to the description in the embodiment of FIG. 2 and details are not described herein again.
  • detecting whether the conversion result is an error can be determined by the cause of the error in the feedback. It can also be combined with the value of the corresponding column in the specific application and the value of the corresponding column in the relational database correspondence table to determine whether the conversion result is wrong, such as detecting whether the converted data format is correct and/or Whether the converted data meets the requirements of the specific application scenario.
  • step S507 if the conversion result is wrong, the conversion rule is modified according to the error reason. For example, in Excel, the data in a column is 123.5, and in the relational database, the column is int, and the corresponding value after conversion is 124, but in the relational database, the value required for the column in the row is 123, then judge the conversion result error, modify the conversion rule of the corresponding column to: round down. Then step S505 is performed.
  • the embodiment further checks whether the conversion result is in error. If an error occurs, the corresponding conversion rule is modified to improve the probability of successful import, and the import efficiency is further improved.
  • FIG. 6 is a schematic block diagram of an apparatus for importing an Excel data into a database according to an embodiment of the present application.
  • the apparatus 60 includes a connection unit 601, a setting unit 602, an analysis unit 603, a rule determination unit 604, a conversion unit 605, and an introduction unit 606.
  • the connecting unit 601 is configured to connect Excel to the relational database through an Excel VBA program.
  • the setting unit 602 is configured to set a correspondence between the field in the Excel table and the field in the relational database correspondence table.
  • the setting unit 602 includes a field obtaining unit 701, a relationship setting unit 702, and a saving unit 703.
  • the field obtaining unit 701 is configured to obtain a field in the relational database correspondence table by using a VBA program.
  • the relationship setting unit 702 is configured to set a correspondence between the field in the Excel table and the field in the relational database correspondence table.
  • the saving unit 703 is configured to save the correspondence.
  • the parsing unit 603 is configured to parse related attributes of the fields in the relational database correspondence table.
  • the rule determining unit 604 is configured to determine a conversion rule according to the correspondence between the fields and related attributes.
  • the converting unit 605 is configured to convert, by using the conversion rule, the value of the corresponding column of the field in the Excel table to the value of the column corresponding to the field in the relational database correspondence table according to the correspondence relationship of the field, and display the conversion result in Excel.
  • the conversion unit 605 includes a column value acquisition unit, a value conversion unit, and a display unit.
  • the column value obtaining unit is configured to obtain a value of a column corresponding to a field in each row of the Excel table.
  • a value conversion unit configured to convert, by using the conversion rule, a value of a field corresponding column in each row of the Excel table to a value corresponding to a field in the Oracle database correspondence table according to the correspondence relationship of the fields.
  • Display unit for displaying the conversion result in Excel It can be understood that in the present embodiment, the conversion is completed line by line.
  • the value of the column corresponding to the field in the Excel table may also be obtained; using the conversion rule, the value of the corresponding column of the Excel table field is converted into the column corresponding to the field in the corresponding table of the Oracle database according to the corresponding relationship of the field. Value; display the conversion result in Excel. It can be understood that the value of the corresponding column of one field can be converted at one time, and then the value of the corresponding column of another field is converted to complete the conversion of all the fields. If an error occurs during the conversion process, the cause of the conversion error is displayed; if there is no error during the conversion process, after all the data has been converted, the conversion result is displayed on the Excel interface. You can see if the conversion is wrong and where it went wrong by displaying the conversion result on the Excel interface. The conversion rules can be modified depending on the cause of the error.
  • the import unit 606 is configured to import the conversion result into the relational database.
  • the import unit 606 includes a comparison unit 801 and an update import unit 802.
  • the comparing unit 801 is configured to compare the data in the conversion result with the data stored in the relational database correspondence table.
  • the update import unit 802 is configured to: if the corresponding data does not exist in the relational database, import the data in the conversion result into the relational database; if there is consistent data in the relational database, prompt; if the relational database If there is inconsistent data, the inconsistent data is updated to the data in the conversion result.
  • the Excel data is used in the process of importing the database, and the data to be processed is processed, and then imported, thereby improving the efficiency of data import; before the import, the conversion result is displayed in Excel for the user to view. This facilitates further user operations and improves the user experience.
  • FIG. 9 is a schematic block diagram of an apparatus for importing an Excel data into a database according to another embodiment of the present application.
  • the apparatus 90 includes a connection unit 901, a setting unit 902, an analysis unit 903, a rule determination unit 904, a conversion unit 905, a detection unit 906, a modification unit 907, and an introduction unit 908.
  • the difference between this embodiment and the embodiment of FIG. 6 is that the detecting unit 906 and the modifying unit 907 are added.
  • the detecting unit 906 and the modifying unit 907 will be described below. For other units, please refer to the description of the corresponding unit in the embodiment of FIG. 6, and details are not described again.
  • the detecting unit 906 is configured to detect whether the conversion result is an error.
  • the modifying unit 907 is configured to modify the conversion rule according to the error reason if the conversion result is wrong.
  • the execution conversion unit 905 is then triggered.
  • the import unit 908 is configured to import the conversion result into the relational database if the conversion result is not erroneous.
  • the above apparatus may be embodied in the form of a computer program that can be run on a computer device as shown in FIG.
  • FIG. 10 is a schematic block diagram of a computer device according to an embodiment of the present application.
  • the device 100 can also be in the form of a client.
  • the device 100 includes a processor 102, a memory and a network interface 103 connected by a system bus 101, wherein the memory can include a non-volatile storage medium 104 and an internal memory 105.
  • the non-volatile storage medium 104 can store an operating system 1041 and a computer program 1042.
  • the processor 102 can be caused to execute a method of importing Excel data into a database.
  • the processor 102 is used to provide computing and control capabilities to support the operation of the entire device 100.
  • the internal memory 105 provides an environment for the operation of a computer program in a non-volatile storage medium that, when executed by the processor 102, causes the processor 102 to perform a method of importing Excel data into a database.
  • the network interface 103 is used for network communication, such as receiving instructions and the like. It will be understood by those skilled in the art that the structure shown in FIG.
  • the specific device 100 may be It includes more or fewer components than those shown in the figures, or some components are combined, or have different component arrangements.
  • the processor 102 is configured to execute a computer program stored in a memory to implement any one of the foregoing methods for importing Excel data into a database.
  • the processor 102 may be a central processing unit (CPU), and the processor may also be another general-purpose processor, a digital signal processor (DSP). , Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc.
  • the general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
  • a computer readable storage medium is stored, the computer readable storage medium storing a computer program, the computer program comprising program instructions, when executed by a processor, Any embodiment of a method of implementing the aforementioned Excel data import database.
  • the computer readable storage medium may be an internal storage unit of the terminal described in any of the foregoing embodiments, such as a hard disk or a memory of the terminal.
  • the computer readable storage medium may also be an external storage device of the terminal, such as a plug-in hard disk equipped on the terminal, a smart memory card (SMC), and a Secure Digital (SD) card. Wait.
  • the computer readable storage medium may also include both an internal storage unit of the terminal and an external storage device.
  • the disclosed terminal and method may be implemented in other manners.
  • the terminal embodiment described above is only illustrative.
  • the division of the unit is only a logical function division, and the actual implementation may have another division manner.
  • a person skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working process of the terminal and the unit described above can be referred to the corresponding process in the foregoing method embodiment, and details are not described herein again.
  • the foregoing is only a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto, and any equivalents can be easily conceived by those skilled in the art within the technical scope disclosed in the present application. Modifications or substitutions are intended to be included within the scope of the present application. Therefore, the scope of protection of this application should be determined by the scope of protection of the claims.

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Embodiments of the present application provide a method and apparatus for importing Excel data into a database, and a computer device and a storage medium. The method comprises: connecting Excel to a relational database by means of an Excel VBA program; setting a correspondence between a field in the Excel form and a field in a corresponding table of the relational database; analyzing the relevant attribute of the field in the corresponding table of the relational database; determining a conversion rule according to the correspondence and the relevant attribute of the field; utilizing the conversion rule to convert the value of the corresponding row of the field in the Excel table into the value of the corresponding row of the field in the corresponding table of the relational database according to the correspondence of the field, and displaying the conversion result in the Excel; and importing the conversion result into the relational database.

Description

Excel数据导入数据库的方法、装置、计算机设备及存储介质Method, device, computer device and storage medium for importing Excel data into database
本申请要求于2018年3月22日提交中国专利局、申请号为201810241485.1、发明名称为“Excel数据导入数据库的方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to Chinese Patent Application No. 201810241485.1, entitled "Method, Device, Computer Equipment and Storage Media for Excel Data Import Database", filed on March 22, 2018, the entire contents of which are hereby incorporated by reference. This is incorporated herein by reference.
技术领域Technical field
本申请涉及数据处理技术领域,尤其涉及一种Excel数据导入数据库的方法、装置、计算机设备及存储介质。The present application relates to the field of data processing technologies, and in particular, to a method, an apparatus, a computer device, and a storage medium for importing an Excel data into a database.
背景技术Background technique
因为Excel数据类型和关系型数据如Oracle数据库的类型存在差异,因此若想将Excel表格中的数据导入到Oracle数据库时,需要进行数据转换。导入数据之前Oracle会根据自身数据类型从Excel表格中引入相应的数据内容进行数据转换,并判断出不符合要求的数据进行提示,最终将转换后的符合Oracle数据类型的数据导入到Oracle数据库中。这种方法不能直观地看到Excel数据转换成Oracle的数据结果,只能通过导入之后再打开Oracle数据库查看相关导入的数据。当Excel数据类型转换Oracle数据类型出现不能转换的错误时,上述方法不能根据需要在导入过程中把需要处理的数据进行修改和删除等操作后继续进行数据导入,而只能通过修改Excel数据之后重新再导入。Because Excel data types and relational data such as Oracle database types are different, if you want to import the data in the Excel table into the Oracle database, you need to perform data conversion. Before importing data, Oracle will import the corresponding data content from the Excel table according to its own data type to convert the data, and judge the data that does not meet the requirements, and finally import the converted data conforming to the Oracle data type into the Oracle database. This method can't visually see the result of converting Excel data into Oracle data. You can only view the related imported data by importing and then opening the Oracle database. When the Excel data type conversion Oracle data type has an error that cannot be converted, the above method cannot continue to perform data import after the operation of modifying and deleting the data to be processed in the import process, but can only be performed after modifying the Excel data. Import again.
发明内容Summary of the invention
本申请实施例提供一种Excel数据导入数据库的方法、装置、计算机设备及存储介质,可在Excel数据导入数据库的过程中根据转换规则对需要处理的数据进行处理,再进行导入,提高数据导入的效率。The embodiment of the present invention provides a method, a device, a computer device, and a storage medium for importing an Excel data into a database, which can process data to be processed according to a conversion rule in the process of importing Excel data into a database, and then import and improve data import. effectiveness.
第一方面,本申请实施例提供了一种Excel数据导入数据库的方法,该方法包括:In a first aspect, an embodiment of the present application provides a method for importing Excel data into a database, where the method includes:
通过Excel VBA程序将Excel连接上关系型数据库;设置Excel表中字段与关系型数据库对应表中字段的对应关系;解析关系型数据库对应表中字段的相关属性;根据所述字段的对应关系和相关属性,确定转换规则;利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果;将所述转换结果导入到关系型数据库中。Connect the Excel to the relational database through the Excel VBA program; set the correspondence between the fields in the Excel table and the fields in the relational database; analyze the related attributes of the fields in the relational database; according to the corresponding relationship of the fields and related Attribute, determining a conversion rule; using the conversion rule, converting the value of the corresponding column of the field in the Excel table to the value of the column corresponding to the field in the relational database according to the corresponding relationship of the field, and displaying the conversion result in Excel; The conversion result is imported into a relational database.
第二方面,本申请实施例提供了一种Excel数据导入数据库的装置,该装置包括用于执行上述第一方面所述Excel数据导入数据库的方法的单元。In a second aspect, an embodiment of the present application provides an apparatus for importing an Excel data into a database, the apparatus comprising means for performing the method of importing the Excel data into the database according to the first aspect.
第三方面,本申请实施例提供了一种计算机设备,所述计算机设备包括存储器,以及与所述存储器相连的处理器;In a third aspect, an embodiment of the present application provides a computer device, where the computer device includes a memory, and a processor connected to the memory;
所述存储器用于存储计算机程序,所述处理器用于运行所述存储器中存储的计算机程序,以执行上述第一方面所述的Excel数据导入数据库的方法。The memory is for storing a computer program for executing a computer program stored in the memory to perform the method of importing Excel data into the database according to the first aspect.
第四方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令被处理器执行时,实现上述第一方面所述的Excel数据导入数据库的方法。In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, where the computer readable storage medium stores a computer program, where the computer program includes program instructions, and when the program instructions are executed by a processor, implementing the foregoing The method of importing Excel data into a database according to the first aspect.
本申请实施例通过Excel VBA程序将Excel连接上关系型数据库,根据关系型数据库对应表中字段的对应关系和相关属性,确定转换规则,再根据转换规则将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果,并将转换结果导入到关系型数据库中。本申请实施例在Excel数据导入数据库的过程中利用确定的转换规则,对需要处理的数据进行处理,再进行导入,提高数据导入的效率;在导入之前,将转换结果显示在Excel中,以方便用户查看,如此方便了用户操作,提高了用户体验。The embodiment of the present application connects Excel to the relational database through the Excel VBA program, determines the conversion rule according to the correspondence relationship and related attributes of the fields in the correspondence table of the relational database, and then converts the value of the corresponding column of the field in the Excel table into the conversion rule according to the conversion rule. The relational database corresponds to the value of the column corresponding to the field in the table and displays the conversion result in Excel, and imports the conversion result into the relational database. In the process of importing Excel data into the database, the embodiment of the present application uses the determined conversion rules to process the data to be processed, and then import, thereby improving the efficiency of data import; before the import, the conversion result is displayed in Excel for convenience. The user view is so convenient for the user to operate and improve the user experience.
附图说明DRAWINGS
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings used in the description of the embodiments will be briefly described below. Obviously, the drawings in the following description are some embodiments of the present application, For the ordinary technicians, other drawings can be obtained based on these drawings without any creative work.
图1是本申请实施例提供的Excel数据导入数据库的方法的场景示意图;1 is a schematic diagram of a scenario of a method for importing Excel data into a database provided by an embodiment of the present application;
图2是本申请实施例提供的一种Excel数据导入数据库的方法的流程示意图;2 is a schematic flowchart of a method for importing Excel data into a database according to an embodiment of the present application;
图3是本申请实施例提供的一种Excel数据导入数据库的方法的子流程示意图;3 is a schematic diagram of a sub-flow of a method for importing Excel data into a database according to an embodiment of the present application;
图4是本申请实施例提供的一种Excel数据导入数据库的方法的另一子流程示意图;4 is a schematic diagram of another sub-flow of a method for importing Excel data into a database according to an embodiment of the present application;
图5是本申请另一实施例提供的一种Excel数据导入数据库的方法的流程示例图;5 is a flow chart showing an example of a method for importing an Excel data into a database according to another embodiment of the present application;
图6是本申请施例提供的一种Excel数据导入数据库的装置的示意性框图;6 is a schematic block diagram of an apparatus for importing an Excel data into a database provided by an embodiment of the present application;
图7是本申请实施例提供的设置单元的示意性框图;7 is a schematic block diagram of a setting unit provided by an embodiment of the present application;
图8是本申请实施例提供的导入单元的示意性框图;8 is a schematic block diagram of an import unit provided by an embodiment of the present application;
图9是本申请另一实施例提供的一种Excel数据导入数据库的装置的示意性框图;9 is a schematic block diagram of an apparatus for importing an Excel data into a database according to another embodiment of the present application;
图10是本申请实施例提供的一种计算机设备的示意性框图。FIG. 10 is a schematic block diagram of a computer device according to an embodiment of the present application.
具体实施方式detailed description
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application are clearly and completely described in the following with reference to the drawings in the embodiments of the present application. It is obvious that the described embodiments are a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present application without departing from the inventive scope are the scope of the present application.
应当理解,当在本说明书和所附权利要求书中使用时,术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。也应当理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。The use of the terms "comprising", "comprising", "","," The presence or addition of a plurality of other features, integers, steps, operations, elements, components, and/or collections thereof. It is also to be understood that the term "and/or" used in the specification and the appended claims are intended to mean any combination and all possible combinations of one or more of the associated listed items.
以下描述的实施例可以应用于具有显示器和/或触摸板的移动电话、膝上型计算机或平板计算机之类的便携式设备中,也可以应用在具有显示器和/或触摸板的非便携式设备,如台式计算机中。需要注意的是,这些设备中安装有Excel 相关软件。The embodiments described below can be applied to portable devices such as mobile phones, laptop computers or tablet computers having displays and/or touch pads, as well as non-portable devices having displays and/or touch pads, such as In a desktop computer. It should be noted that Excel related software is installed in these devices.
请参看图1,图1是本申请实施例提供的Excel数据导入数据库的方法的场景示意图。当用户接收到将一个有多行多列的Excel表中的数据导入到关系型数据库的需求时,先通过Excel VBA程序将Excel连接上关系型数据库;通过驱动如ADO驱动读取关系型数据库表中所有字段以及字段属性返回给Excel;通过Excel VBA设置Excel表中与关系型数据库表中字段的对应关系;解析关系型数据库对应表中对应字段的相关属性;根据字段的对应关系和相关属性,确定转换规则,并利用所述转换规则,根据字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果;当接收用户点击导入按钮产生的导入请求时,通过ADO驱动将Excel中显示的转换结果导入到关系型数据库中。如此在Excel数据导入数据库的过程中利用确定的转换规则,对需要处理的数据进行处理,再进行导入,提高数据导入的效率;在导入之前,将转换结果显示在Excel中,以方便用户查看转换结果是否出错,如此方便了用户操作,提高了用户体验。Please refer to FIG. 1. FIG. 1 is a schematic diagram of a method for importing Excel data into a database according to an embodiment of the present application. When the user receives the requirement to import the data in an Excel table with multiple rows and columns into the relational database, first connect the Excel to the relational database through the Excel VBA program; read the relational database table through the driver such as the ADO driver. All the fields and field attributes are returned to Excel; the correspondence between the fields in the Excel table and the relational database table is set by Excel VBA; the related attributes of the corresponding fields in the relational database are analyzed; according to the corresponding relationship of the fields and related attributes, Determining a conversion rule, and using the conversion rule to convert the value of the column corresponding to the field in the Excel table to the value of the column corresponding to the field in the relational database according to the corresponding relationship of the field and display the conversion result in Excel; when the receiving user clicks When importing the import request generated by the button, the conversion result displayed in Excel is imported into the relational database through the ADO driver. In the process of importing Excel data into the database, the determined conversion rules are used to process the data to be processed, and then imported, thereby improving the efficiency of data import; before the import, the conversion result is displayed in Excel, so that the user can view the conversion. The result is an error, which is convenient for the user to operate and improves the user experience.
图2为本申请实施例提供的一种Excel数据导入数据库的方法的流程示意图。该方法包括以下步骤S201-S206。FIG. 2 is a schematic flowchart diagram of a method for importing Excel data into a database according to an embodiment of the present application. The method includes the following steps S201-S206.
S201,通过Excel VBA程序将Excel连接上关系型数据库。S201, connecting Excel to a relational database through an Excel VBA program.
其中,关系型数据库是建立在关系模型基础上的数据库,现实世界中的各种实体以及实体之间的各种联系均用关系模型来表示。关系型数据库包括Oracle数据库、SQL Server数据库、My SQL数据库等。下面的例子中将以Oracle数据库为例进行说明。通过Excel VBA程序将Excel连接上关系型数据库,具体地,通过Excel的VBA程序,利用驱动将Excel连接上关系型数据库,如通过ADO驱动将Excel连接上Oracle数据库。可以理解为,通过Excel VBA编程,调用ADO驱动,将Excel连接上Oracle数据库。其中,ADO(ActiveX Data Objects)是一个用于存取数据源的COM组件。Excel通过VBA连接Oracle数据库需要引用ADO驱动库。引用ADO驱动库可按如下步骤操作:1、打开VBA编辑器,在菜单中点选“工具”,“引用”;勾选“Microsoft ActiviteX Data Objects 2.8 Library”和“Microsoft ActiviteX Data ObjectS Recordset 2.8 Library”选项,确保ADO驱动库被选上。其中,ADO驱动库名称可能是其他的名称。引用了 ADO驱动库后,通过ADO驱动库,如调用ADO驱动库的打开方法,在打开方法中输入相应的用户名、密码、Oracle数据库服务器名称等,以打开Oracle数据库,建立与Oracle数据库的连接,并保持与Oracle数据库的连接。若没有ADO驱动或者不引用ADO驱动,也可以创建一个ADO对象。具体地,调用创建对象函数来创建ADO对象,创建对象函数如CreateObject。创建ADO对象后,调用ADO对象的打开方法,在打开方法中输入相应的用户名、密码、Oracle数据库服务器名称等,以打开Oracle数据库,建立与Oracle数据库的连接,并保持与Oracle数据库的连接。在本申请实施例中,具体的驱动不限制,如可以为ADO驱动,也可以为ODBC(OpenDatabaseConnectivity)驱动。也可以根据具体数据库选择与对应数据库最相匹配的驱动。Among them, the relational database is a database based on the relational model. Various entities in the real world and various connections between entities are represented by a relational model. Relational databases include Oracle databases, SQL Server databases, My SQL databases, and more. The following example will use the Oracle database as an example. Excel is connected to the relational database through the Excel VBA program. Specifically, through the VBA program of Excel, the Excel is connected to the relational database by using the driver, for example, the Excel is connected to the Oracle database through the ADO driver. Can be understood as, through Excel VBA programming, call the ADO driver, connect Excel to the Oracle database. Among them, ADO (ActiveX Data Objects) is a COM component for accessing data sources. Excel needs to reference the ADO driver library when connecting to the Oracle database via VBA. To reference the ADO driver library, follow these steps: 1. Open the VBA editor, click on "Tools", "References" in the menu; check "Microsoft ActiviteX Data Objects 2.8 Library" and "Microsoft ActiviteX Data ObjectS Recordset 2.8 Library" Option to ensure that the ADO driver library is selected. Among them, the ADO driver library name may be another name. After citing the ADO driver library, through the ADO driver library, such as calling the ADO driver library open method, enter the corresponding user name, password, Oracle database server name, etc. in the open method to open the Oracle database and establish a connection with the Oracle database. And maintain a connection to the Oracle database. If you do not have an ADO driver or do not reference the ADO driver, you can also create an ADO object. Specifically, the create object function is called to create an ADO object, and an object function such as CreateObject is created. After creating the ADO object, call the open method of the ADO object, enter the corresponding user name, password, Oracle database server name, etc. in the open method to open the Oracle database, establish a connection with the Oracle database, and maintain a connection with the Oracle database. In the embodiment of the present application, the specific driver is not limited, and may be an ADO driver or an ODBC (Open Database Connectivity) driver. It is also possible to select the driver that best matches the corresponding database according to the specific database.
通过创建ADO对象,将excel连接上Oracle数据库的代码可参考如下:By creating an ADO object, the code to connect the excel to the Oracle database can be found as follows:
Dim cnn As Object,rst As ObjectDim cnn As Object, rst As Object
Set cnn=CreateObject(″ADODB.Connection″)Set cnn=CreateObject("ADODB.Connection")
Set rst=CreateObject(″ADODB.Recordset″)Set rst=CreateObject("ADODB.Recordset")
cnn.Open″Provider=msdaora.1;Data Source=d1580;User Id=emssxjk;Password=emssxjk;″cnn.Open"Provider=msdaora.1;Data Source=d1580;User Id=emssxjk;Password=emssxjk;"
OraOpen=True′OraOpen=True'
其中,Data Source表示数据库服务器名称,User Id和Password分别表示连接数据库的用户名和密码。上述代码成功执行后,Oracle数据库即被打开。Among them, Data Source represents the database server name, User Id and Password respectively represent the user name and password to connect to the database. After the above code is successfully executed, the Oracle database is opened.
S202,设置Excel表中字段与关系型数据库对应表中字段的对应关系。S202: Set a correspondence between a field in the Excel table and a field in the correspondence table of the relational database.
首先,需要在关系型数据库中创建表,并在对应表中添加字段。每个字段有对应的属性,在对应表中添加字段并设置每个字段对应的属性。如属性包括字段名称、字段类型、字段长度等,属性还可以包括唯一性约束、主键约束等。其中,关系型数据库对应表中字段的个数小于或者等于Excel表中字段的个数。若关系型数据库对应表中字段个数等于Excel表中字段的个数,可以理解为,需要将Excel表中所有列的数据导入到关系型数据库中。若关系型数据库对应表中字段个数小于Excel表中字段的个数,可以理解为,只需要将Excel表中部分列的数据导入到关系型数据库中。需要注意的是,在关系型数据库中创建表,并在对应表中添加字段可以在步骤S101之前执行,也可以在步骤S101之后执 行。创建表和添加对应表中的字段可以通过执行相应的SQL语言来完成。关系型数据库中有对应表之后,再设置Excel表中字段与关系型数据库对应表中字段的对应关系。如通过VBA编程来设置对应关系。First, you need to create a table in a relational database and add fields to the corresponding table. Each field has a corresponding attribute, and a field is added in the corresponding table and the attribute corresponding to each field is set. If the attribute includes a field name, a field type, a field length, etc., the attribute may also include a uniqueness constraint, a primary key constraint, and the like. The number of fields in the relational database correspondence table is less than or equal to the number of fields in the Excel table. If the number of fields in the relational database correspondence table is equal to the number of fields in the Excel table, it can be understood that all the columns in the Excel table need to be imported into the relational database. If the number of fields in the relational database correspondence table is smaller than the number of fields in the Excel table, it can be understood that only the data of some columns in the Excel table need to be imported into the relational database. It should be noted that creating a table in the relational database and adding a field in the corresponding table may be performed before step S101, or may be performed after step S101. Creating a table and adding fields in the corresponding table can be done by executing the corresponding SQL language. After there is a corresponding table in the relational database, the correspondence between the fields in the Excel table and the fields in the relational database correspondence table is set. Set the correspondence by VBA programming.
在一实施例中,如图2所示,所述步骤S202包括步骤S301-S303。In an embodiment, as shown in FIG. 2, the step S202 includes steps S301-S303.
S301,通过VBA程序获取关系型数据库对应表中的字段。如对于Oracle数据库,通过VBA程序,调用ADO驱动,使Excel连接上Oracle数据库后,通过ADO驱动就能读取Oracle数据库中的数据了,如此获取Oracle数据库中对应表中的字段,其中,Oracle数据库中对应表指的是将Excel数据导入到Oracle数据库中的那张表。S301. Acquire a field in a relational database correspondence table by using a VBA program. For example, for the Oracle database, through the VBA program, call the ADO driver, so that Excel can connect to the Oracle database, the data in the Oracle database can be read through the ADO driver, so that the fields in the corresponding table in the Oracle database are obtained, wherein the Oracle database The corresponding table refers to the table that imports Excel data into the Oracle database.
S302,设置Excel表中字段与关系型数据库对应表中字段的对应关系。对应关系,可以理解为,将Excel表对应列的导入到Oracle数据库对应表中的哪个列。S302: Set a correspondence between a field in the Excel table and a field in the correspondence table of the relational database. The correspondence relationship can be understood as which column of the corresponding table in the Oracle database is imported into the corresponding column of the Excel table.
S303,保存所述对应关系。保存对应关系以使后续导入时将Excel表中对应列的数据导入设置有对应关系的Oracle数据库中的对应列,以避免导入时出错。S303. Save the correspondence. The corresponding relationship is saved so that the data of the corresponding column in the Excel table is imported into the corresponding column in the corresponding Oracle database when the subsequent import is performed, so as to avoid an error in the import.
S203,解析关系型数据库对应表中字段的相关属性。S203. Analyze the related attribute of the field in the correspondence table of the relational database.
其中,关系型数据库对应表中字段指的是关系型数据库中设置有对应关系的字段。读取Oracle数据库对应表和对应表中字段的相关属性,如字段名称和字段类型、字段长度等。读取到Oracle数据库对应表中字段的相关属性后,通过VBA程序获取读取的相关属性,如此获取到了关系型数据库对应表中字段的相关属性。解析获取的相关属性。如字段名称为日期,字段类型为date,Oracle数据库中date数据类型包括世纪、年、月、日、时、分、秒。共占用7个字节。The field in the relational database correspondence table refers to a field in which the correspondence relationship is set in the relational database. Read the related attributes of the fields in the Oracle database correspondence table and the corresponding table, such as the field name, field type, and field length. After reading the related attributes of the fields in the corresponding table of the Oracle database, the related attributes of the read are obtained through the VBA program, and the related attributes of the fields in the correspondence table of the relational database are obtained. Parse the relevant properties obtained. If the field name is date and the field type is date, the date data type in the Oracle database includes century, year, month, day, hour, minute, and second. A total of 7 bytes are occupied.
S204,根据所述字段的对应关系和相关属性,确定转换规则。S204. Determine a conversion rule according to the correspondence between the fields and related attributes.
获取Excel表中字段的属性,再根据字段的对应关系和相关属性,确定转换规则。可以理解地,根据excel表中字段和关系型数据库对应表中字段的字段类型来确定转换规则。如Excel表中日期字段的字段类型为char,而Oracle数据库中对应日期字段的字段类型为date,这是两个不同数据类型的字段,那么转换规则为:将Excel表该字段对应列数据的字段类型由char转换为Oracle数据库对应字段类型date。如此,才可以将Excel表中的日期数据导入到Oracle 数据库。再如Excel表中字段的类型为int,而关系型数据库中对应字段的类型为flout,那么需要将该字段对应列数据的字段类型由int转换为关系型数据库对应字段的字段类型flout。Obtain the attributes of the fields in the Excel table, and then determine the conversion rules according to the corresponding relationship of the fields and related attributes. It can be understood that the conversion rule is determined according to the field in the excel table and the field type of the field in the relational database correspondence table. For example, the field type of the date field in the Excel table is char, and the field type of the corresponding date field in the Oracle database is date, which is a field of two different data types, then the conversion rule is: the field corresponding to the column data of the Excel table. The type is converted from char to the Oracle database corresponding field type date. In this way, the date data in the Excel table can be imported into the Oracle database. If the type of the field in the Excel table is int, and the type of the corresponding field in the relational database is flout, then the field type corresponding to the column data of the field needs to be converted from int to the field type flout of the corresponding field of the relational database.
S205,利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果。S205. Convert, by using the conversion rule, the value of the corresponding column of the field in the Excel table to the value of the column corresponding to the field in the relational database correspondence table according to the correspondence relationship of the field, and display the conversion result in Excel.
在一实施例中,所述步骤S205包括:获取Excel表每一行中字段对应列的值;利用所述转换规则,根据所述字段的对应关系将Excel表每一行中字段对应列的值转换为Oracle数据库对应表中字段对应列的值;在Excel中显示转换结果。可以理解地,在本实施例中,是一行一行地完成转换。在其他实施例中,也可以获取Excel表中字段对应列的值;利用所述转换规则,根据所述字段的对应关系将Excel表字段对应列的值转换为Oracle数据库对应表中字段对应列的值;在Excel中显示转换结果。可以理解地,也可以一次将一个字段对应列的值进行转换,然后将另一个字段对应列的值进行转换,以将所有字段都转换完成。若转换的过程中出错,显示转换出错的原因;若转换的过程中没有出错,将所有的数据转换完成后,将转换结果显示在Excel中界面上。通过显示在Excel界面上的转换结果可以查看转换是否出错,以及在哪里出错。根据出错的原因可以修改转换规则。In an embodiment, the step S205 includes: obtaining a value of a column corresponding to a field in each row of the Excel table; and converting, by using the conversion rule, a value of a column corresponding to a field in each row of the Excel table according to a correspondence relationship of the field The value corresponding to the column in the field in the Oracle database corresponds to the table; the conversion result is displayed in Excel. It can be understood that in the present embodiment, the conversion is completed line by line. In other embodiments, the value of the column corresponding to the field in the Excel table may also be obtained; using the conversion rule, the value of the corresponding column of the Excel table field is converted into the column corresponding to the field in the corresponding table of the Oracle database according to the corresponding relationship of the field. Value; display the conversion result in Excel. It can be understood that the value of the corresponding column of one field can be converted at one time, and then the value of the corresponding column of another field is converted to complete the conversion of all the fields. If an error occurs during the conversion process, the cause of the conversion error is displayed; if there is no error during the conversion process, after all the data is converted, the conversion result is displayed on the Excel interface. You can see if the conversion is wrong and where it went wrong by displaying the conversion result on the Excel interface. The conversion rules can be modified depending on the cause of the error.
S206,将转换结果导入到关系型数据库中。具体地,通过VBA程序获取转换结果,接收输入的导入指令后,通过ADO驱动将转换结果导入到Oracle数据库中。用户点击“导入”相关按钮,即生成导入指令。S206, importing the conversion result into the relational database. Specifically, the conversion result is obtained by the VBA program, and after receiving the input import instruction, the conversion result is imported into the Oracle database through the ADO driver. The user clicks the "Import" related button to generate an import command.
在一实施例中,如图4所示,所述步骤S206包括以下步骤S401-S402。In an embodiment, as shown in FIG. 4, the step S206 includes the following steps S401-S402.
S401,将转换结果中的数据与关系型数据库对应表中存储的数据进行比对。当接收到导入指令后,执行数据的比对。比对时,将转换结果中每一行的数据与关系型数据库对应表中存储的数据进行比对,如根据Oracle数据库对应表中存在主键约束的列与转换结果中对应列的值进行比对,以快速判断是否存在对应行的数据。判断存在对应行的数据后,再将对应行的数据进行比对以判断转换结果中对应行的数据与关系型数据库中的数据是否一致。将所有的数据比对完成后,执行S402。S401: Compare the data in the conversion result with the data stored in the relational database correspondence table. After receiving the import instruction, the comparison of the data is performed. When comparing, compare the data of each row in the conversion result with the data stored in the relational database correspondence table, for example, according to the column of the primary key constraint in the Oracle database correspondence table and the value of the corresponding column in the conversion result, To quickly determine whether there is data for the corresponding row. After judging that there is data of the corresponding row, the data of the corresponding row is compared to determine whether the data of the corresponding row in the conversion result is consistent with the data in the relational database. After all the data are compared, S402 is executed.
S402,若关系型数据库中不存在对应的数据,则将转换结果中的数据导入到关系型数据库中;若关系型数据库中存在一致的数据,则进行提示;若关系型数据库中存在不一致的数据,则将不一致的数据更新为转换结果中的数据。S402: if there is no corresponding data in the relational database, import the data in the conversion result into the relational database; if there is consistent data in the relational database, prompt; if there is inconsistent data in the relational database , the inconsistent data is updated to the data in the conversion result.
若关系型数据库中不存在与转换结果中的数据相对应的数据,那么将转换结果中的数据导入到关系型数据库;若关系型数据库中存在与转换结果中一致的数据,则进行提示,如以对话框的形式提示“数据库中已存在一致的数据,是否进行重新导入”;若关系型数据库中存在与转换结果中不一致的数据,以行为单位将不一致的数据更新为转换结果中的数据。如转换结果中某一行中某一列的数据与关系型数据库中对应行的数据不一致,则以转换结果中该行的数据来更新关系型数据库中对应行的数据;若转换结果中多行的数据在关系型数据库中并不存在,则将该多行的数据以行为单位插入到关系型数据库中。If there is no data corresponding to the data in the conversion result in the relational database, the data in the conversion result is imported into the relational database; if there is data in the relational database that is consistent with the conversion result, a prompt is given, such as In the form of a dialog box, "consistent data already exists in the database, whether to re-import"; if there is data in the relational database that is inconsistent with the conversion result, the inconsistent data is updated to the data in the conversion result in units of rows. If the data of a column in a row in the conversion result is inconsistent with the data of the corresponding row in the relational database, the data of the row in the relational database is updated by the data of the row in the conversion result; if the data of the row in the conversion result is multi-row If it does not exist in the relational database, the data of the multiple rows is inserted into the relational database in units of rows.
上述实施例在Excel数据导入数据库的过程中利用转换规则,对需要处理的数据进行处理,再进行导入,提高数据导入的效率;在导入之前,将转换结果显示在Excel中,以供用户查看,如此方便了进一步的用户操作,提高了用户体验。In the above embodiment, the Excel data is used in the process of importing the database, and the data to be processed is processed, and then imported, thereby improving the efficiency of data import; before the import, the conversion result is displayed in Excel for the user to view. This facilitates further user operations and improves the user experience.
图5是本申请另一实施例提供的一种Excel数据导入数据库的方法的流程示意图。该方法包括步骤S501-S508。其中,增加了步骤S506-S507。其他步骤与图2实施例所示的步骤一致,具体请参看图2实施例描述的内容,在此不再赘述。FIG. 5 is a schematic flowchart of a method for importing Excel data into a database according to another embodiment of the present application. The method includes steps S501-S508. Among them, steps S506-S507 are added. The other steps are the same as those shown in the embodiment of FIG. 2 . For details, please refer to the description in the embodiment of FIG. 2 , and details are not described herein again.
S506,检测转换结果是否出错。可以通过反馈的出错原因来确定,还可以结合具体应用中Excel对应列的数值和关系型数据库对应表中对应列的数值来确定转换结果是否出错,如检测转换后的数据格式是否正确和/或转换后的数据是否符合具体应用场景的需求等。S506, detecting whether the conversion result is an error. It can be determined by the cause of the error in the feedback. It can also be combined with the value of the corresponding column in the specific application and the value of the corresponding column in the relational database correspondence table to determine whether the conversion result is wrong, such as detecting whether the converted data format is correct and/or Whether the converted data meets the requirements of the specific application scenario.
S507,若转换结果出错,根据出错原因修改转换规则。如在Excel中,某一行中某一列数据为123.5,而对应关系型数据库中,该列为int,转换后对应的数值为124,但实际上在关系型数据库,该行该列需要的数值是123,那么判断转换结果出错,将对应列的转换规则修改为:向下取整。接着执行步骤S505。S507, if the conversion result is wrong, the conversion rule is modified according to the error reason. For example, in Excel, the data in a column is 123.5, and in the relational database, the column is int, and the corresponding value after conversion is 124, but in the relational database, the value required for the column in the row is 123, then judge the conversion result error, modify the conversion rule of the corresponding column to: round down. Then step S505 is performed.
S508,若转换结果未出错,将转换结果导入到关系型数据库中。S508: If the conversion result is not in error, the conversion result is imported into the relational database.
该实施例根据显示的转换结果,进一步查看转换结果是否出错,若出错, 修改对应的转换规则,以提高导入成功的几率,进一步提高导入的效率。According to the displayed conversion result, the embodiment further checks whether the conversion result is in error. If an error occurs, the corresponding conversion rule is modified to improve the probability of successful import, and the import efficiency is further improved.
图6是本申请实施例提供的一种Excel数据导入数据库的装置的示意性框图。如图6所示,该装置60包括连接单元601、设置单元602、解析单元603、规则确定单元604、转换单元605、导入单元606。FIG. 6 is a schematic block diagram of an apparatus for importing an Excel data into a database according to an embodiment of the present application. As shown in FIG. 6, the apparatus 60 includes a connection unit 601, a setting unit 602, an analysis unit 603, a rule determination unit 604, a conversion unit 605, and an introduction unit 606.
连接单元601,用于通过Excel VBA程序将Excel连接上关系型数据库。The connecting unit 601 is configured to connect Excel to the relational database through an Excel VBA program.
设置单元602,用于设置Excel表中字段与关系型数据库对应表中字段的对应关系。The setting unit 602 is configured to set a correspondence between the field in the Excel table and the field in the relational database correspondence table.
在一实施例中,如图7所示,设置单元602包括字段获取单元701、关系设置单元702、保存单元703。In an embodiment, as shown in FIG. 7, the setting unit 602 includes a field obtaining unit 701, a relationship setting unit 702, and a saving unit 703.
字段获取单元701,用于通过VBA程序获取关系型数据库对应表中的字段。关系设置单元702,用于设置Excel表中字段与关系型数据库对应表中字段的对应关系。The field obtaining unit 701 is configured to obtain a field in the relational database correspondence table by using a VBA program. The relationship setting unit 702 is configured to set a correspondence between the field in the Excel table and the field in the relational database correspondence table.
保存单元703,用于保存所述对应关系。The saving unit 703 is configured to save the correspondence.
解析单元603,用于解析关系型数据库对应表中字段的相关属性。The parsing unit 603 is configured to parse related attributes of the fields in the relational database correspondence table.
规则确定单元604,用于根据所述字段的对应关系和相关属性,确定转换规则。The rule determining unit 604 is configured to determine a conversion rule according to the correspondence between the fields and related attributes.
转换单元605,用于利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果。The converting unit 605 is configured to convert, by using the conversion rule, the value of the corresponding column of the field in the Excel table to the value of the column corresponding to the field in the relational database correspondence table according to the correspondence relationship of the field, and display the conversion result in Excel.
在一实施例中,转换单元605包括列值获取单元、值转换单元、显示单元。其中,列值获取单元,用于获取Excel表每一行中字段对应列的值。值转换单元,用于利用所述转换规则,根据所述字段的对应关系将Excel表每一行中字段对应列的值转换为Oracle数据库对应表中字段对应列的值。显示单元,用于在Excel中显示转换结果。可以理解地,在本实施例中,是一行一行地完成转换。在其他实施例中,也可以获取Excel表中字段对应列的值;利用所述转换规则,根据所述字段的对应关系将Excel表字段对应列的值转换为Oracle数据库对应表中字段对应列的值;在Excel中显示转换结果。可以理解地,也可以一次将一个字段对应列的值进行转换,然后将另一个字段对应列的值进行转换,以将所有字段都转换完成。若转换的过程中出错,显示转换出错的原因;若转 换的过程中没有出错,将所有的数据转换完成后,将转换结果显示在Excel中界面上。通过显示在Excel界面上的转换结果可以查看转换是否出错,以及在哪里出错。根据出错的原因可以修改转换规则。In an embodiment, the conversion unit 605 includes a column value acquisition unit, a value conversion unit, and a display unit. The column value obtaining unit is configured to obtain a value of a column corresponding to a field in each row of the Excel table. And a value conversion unit, configured to convert, by using the conversion rule, a value of a field corresponding column in each row of the Excel table to a value corresponding to a field in the Oracle database correspondence table according to the correspondence relationship of the fields. Display unit for displaying the conversion result in Excel. It can be understood that in the present embodiment, the conversion is completed line by line. In other embodiments, the value of the column corresponding to the field in the Excel table may also be obtained; using the conversion rule, the value of the corresponding column of the Excel table field is converted into the column corresponding to the field in the corresponding table of the Oracle database according to the corresponding relationship of the field. Value; display the conversion result in Excel. It can be understood that the value of the corresponding column of one field can be converted at one time, and then the value of the corresponding column of another field is converted to complete the conversion of all the fields. If an error occurs during the conversion process, the cause of the conversion error is displayed; if there is no error during the conversion process, after all the data has been converted, the conversion result is displayed on the Excel interface. You can see if the conversion is wrong and where it went wrong by displaying the conversion result on the Excel interface. The conversion rules can be modified depending on the cause of the error.
导入单元606,用于将转换结果导入到关系型数据库中。The import unit 606 is configured to import the conversion result into the relational database.
在一实施例中,如图8所示,导入单元606包括比对单元801、更新导入单元802。In an embodiment, as shown in FIG. 8, the import unit 606 includes a comparison unit 801 and an update import unit 802.
比对单元801,用于将转换结果中的数据与关系型数据库对应表中存储的数据进行比对。The comparing unit 801 is configured to compare the data in the conversion result with the data stored in the relational database correspondence table.
更新导入单元802,用于若关系型数据库中不存在对应的数据,则将转换结果中的数据导入到关系型数据库中;若关系型数据库中存在一致的数据,则进行提示;若关系型数据库中存在不一致的数据,则将不一致的数据更新为转换结果中的数据。The update import unit 802 is configured to: if the corresponding data does not exist in the relational database, import the data in the conversion result into the relational database; if there is consistent data in the relational database, prompt; if the relational database If there is inconsistent data, the inconsistent data is updated to the data in the conversion result.
上述实施例在Excel数据导入数据库的过程中利用转换规则,对需要处理的数据进行处理,再进行导入,提高数据导入的效率;在导入之前,将转换结果显示在Excel中,以供用户查看,如此方便了进一步的用户操作,提高了用户体验。In the above embodiment, the Excel data is used in the process of importing the database, and the data to be processed is processed, and then imported, thereby improving the efficiency of data import; before the import, the conversion result is displayed in Excel for the user to view. This facilitates further user operations and improves the user experience.
图9是本申请另一实施例提供的一种Excel数据导入数据库的装置的示意性框图。如图9所示,该装置90包括连接单元901、设置单元902、解析单元903、规则确定单元904、转换单元905、检测单元906、修改单元907、导入单元908。其中,该实施例与图6实施例的区别在于:增加了检测单元906、修改单元907。下面将介绍检测单元906、修改单元907。其他单元请参看图6实施例中对应单元的描述,再次不再赘述。FIG. 9 is a schematic block diagram of an apparatus for importing an Excel data into a database according to another embodiment of the present application. As shown in FIG. 9, the apparatus 90 includes a connection unit 901, a setting unit 902, an analysis unit 903, a rule determination unit 904, a conversion unit 905, a detection unit 906, a modification unit 907, and an introduction unit 908. The difference between this embodiment and the embodiment of FIG. 6 is that the detecting unit 906 and the modifying unit 907 are added. The detecting unit 906 and the modifying unit 907 will be described below. For other units, please refer to the description of the corresponding unit in the embodiment of FIG. 6, and details are not described again.
检测单元906,用于检测转换结果是否出错。The detecting unit 906 is configured to detect whether the conversion result is an error.
修改单元907,用于若转换结果出错,根据出错原因修改转换规则。接着触发执行转换单元905。The modifying unit 907 is configured to modify the conversion rule according to the error reason if the conversion result is wrong. The execution conversion unit 905 is then triggered.
导入单元908,用于若转换结果未出错,将转换结果导入到关系型数据库中。The import unit 908 is configured to import the conversion result into the relational database if the conversion result is not erroneous.
上述装置实施例的具体工作过程和达到的有益效果,请参看前述方法实施例对应的实施过程和有益效果,在此不再赘述。For the specific working process and the beneficial effects of the foregoing device embodiments, refer to the corresponding implementation process and beneficial effects of the foregoing method embodiments, and details are not described herein again.
上述装置可以实现为一种计算机程序的形式,计算机程序可以在如图10所示的计算机设备上运行。The above apparatus may be embodied in the form of a computer program that can be run on a computer device as shown in FIG.
图10为本申请实施例提供的一种计算机设备的示意性框图。该设备100也可以是以客户端的形式存在。该设备100包括通过系统总线101连接的处理器102、存储器和网络接口103,其中,存储器可以包括非易失性存储介质104和内存储器105。FIG. 10 is a schematic block diagram of a computer device according to an embodiment of the present application. The device 100 can also be in the form of a client. The device 100 includes a processor 102, a memory and a network interface 103 connected by a system bus 101, wherein the memory can include a non-volatile storage medium 104 and an internal memory 105.
该非易失性存储介质104可存储操作系统1041和计算机程序1042。该计算机程序1042被执行时,可使得处理器102执行Excel数据导入数据库的方法。该处理器102用于提供计算和控制能力,支撑整个设备100的运行。该内存储器105为非易失性存储介质中的计算机程序的运行提供环境,该计算机程序被处理器102执行时,可使得处理器102执行Excel数据导入数据库的方法。该网络接口103用于进行网络通信,如接收指令等。本领域技术人员可以理解,图10中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的设备100的限定,具体的设备100可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。The non-volatile storage medium 104 can store an operating system 1041 and a computer program 1042. When the computer program 1042 is executed, the processor 102 can be caused to execute a method of importing Excel data into a database. The processor 102 is used to provide computing and control capabilities to support the operation of the entire device 100. The internal memory 105 provides an environment for the operation of a computer program in a non-volatile storage medium that, when executed by the processor 102, causes the processor 102 to perform a method of importing Excel data into a database. The network interface 103 is used for network communication, such as receiving instructions and the like. It will be understood by those skilled in the art that the structure shown in FIG. 10 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation of the device 100 to which the solution of the present application is applied. The specific device 100 may be It includes more or fewer components than those shown in the figures, or some components are combined, or have different component arrangements.
其中,所述处理器102用于运行存储在存储器中的计算机程序,以实现前述Excel数据导入数据库的方法的任一实施例。The processor 102 is configured to execute a computer program stored in a memory to implement any one of the foregoing methods for importing Excel data into a database.
应当理解,在本申请实施例中,所称处理器102可以是中央处理单元(Central Processing Unit,CPU),该处理器还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。It should be understood that, in the embodiment of the present application, the processor 102 may be a central processing unit (CPU), and the processor may also be another general-purpose processor, a digital signal processor (DSP). , Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc. The general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
在本申请的另一实施例中提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被处理器执行时,以实现前述Excel数据导入数据库的方法的任一实施例。In another embodiment of the present application, a computer readable storage medium is stored, the computer readable storage medium storing a computer program, the computer program comprising program instructions, when executed by a processor, Any embodiment of a method of implementing the aforementioned Excel data import database.
所述计算机可读存储介质可以是前述任一实施例所述的终端的内部存储单元,例如终端的硬盘或内存。所述计算机可读存储介质也可以是所述终端的外部存储设备,例如所述终端上配备的插接式硬盘,智能存储卡(Smart Media Card, SMC),安全数字(Secure Digital,SD)卡等。进一步地,所述计算机可读存储介质还可以既包括所述终端的内部存储单元也包括外部存储设备。The computer readable storage medium may be an internal storage unit of the terminal described in any of the foregoing embodiments, such as a hard disk or a memory of the terminal. The computer readable storage medium may also be an external storage device of the terminal, such as a plug-in hard disk equipped on the terminal, a smart memory card (SMC), and a Secure Digital (SD) card. Wait. Further, the computer readable storage medium may also include both an internal storage unit of the terminal and an external storage device.
在本申请所提供的几个实施例中,应该理解到,所揭露的终端和方法,可以通过其它的方式实现。例如,以上所描述的终端实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的终端和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。In the several embodiments provided by the present application, it should be understood that the disclosed terminal and method may be implemented in other manners. For example, the terminal embodiment described above is only illustrative. For example, the division of the unit is only a logical function division, and the actual implementation may have another division manner. A person skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working process of the terminal and the unit described above can be referred to the corresponding process in the foregoing method embodiment, and details are not described herein again. The foregoing is only a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto, and any equivalents can be easily conceived by those skilled in the art within the technical scope disclosed in the present application. Modifications or substitutions are intended to be included within the scope of the present application. Therefore, the scope of protection of this application should be determined by the scope of protection of the claims.

Claims (20)

  1. 一种Excel数据导入数据库的方法,其特征在于,所述方法包括:A method for importing Excel data into a database, the method comprising:
    通过Excel VBA程序将Excel连接上关系型数据库;Connect Excel to a relational database through an Excel VBA program;
    设置Excel表中字段与关系型数据库对应表中字段的对应关系;Setting the correspondence between the fields in the Excel table and the fields in the correspondence table of the relational database;
    解析关系型数据库对应表中字段的相关属性;Parsing the related attributes of the fields in the relational database correspondence table;
    根据所述字段的对应关系和相关属性,确定转换规则;Determining a conversion rule according to the correspondence between the fields and related attributes;
    利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果;Using the conversion rule, converting the value of the column corresponding to the field in the Excel table to the value of the column corresponding to the field in the relational database corresponding table according to the corresponding relationship of the field, and displaying the conversion result in Excel;
    将所述转换结果导入到关系型数据库中。Import the conversion result into a relational database.
  2. 根据权利要求1所述的方法,其特征在于,在所述将所述转换结果导入到关系型数据库中之前,所述方法还包括:The method according to claim 1, wherein before the importing the conversion result into a relational database, the method further comprises:
    检测所述转换结果是否出错;Detecting whether the conversion result is erroneous;
    若所述转换结果出错,根据出错原因修改所述转换规则;执行利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果的步骤;If the conversion result is in error, the conversion rule is modified according to the error reason; and the conversion rule is used to convert the value of the corresponding column of the field in the Excel table into the corresponding column of the field in the relational database corresponding table according to the correspondence relationship of the field The value and the step of displaying the conversion result in Excel;
    若所述转换结果未出错,执行将所述转换结果导入到关系型数据库中的步骤。If the conversion result is not erroneous, perform the step of importing the conversion result into the relational database.
  3. 根据权利要求1所述的方法,其特征在于,所述设置Excel表中字段与关系型数据库对应表中字段的对应关系,包括:The method according to claim 1, wherein the setting of the correspondence between the fields in the Excel table and the fields in the relational database correspondence table comprises:
    通过Excel VBA程序获取关系型数据库对应表中的字段;Obtain the fields in the relational database correspondence table through the Excel VBA program;
    设置Excel表中字段与关系型数据库对应表中字段的对应关系;Setting the correspondence between the fields in the Excel table and the fields in the correspondence table of the relational database;
    保存所述对应关系。Save the correspondence.
  4. 根据权利要求1所述的方法,其特征在于,所述利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果,包括:The method according to claim 1, wherein the converting the value of the corresponding column of the field in the Excel table to the value of the corresponding column of the field in the relational database correspondence table according to the correspondence relationship of the field by using the conversion rule And display the conversion results in Excel, including:
    获取Excel表每一行中字段对应列的值;Get the value of the corresponding column of the field in each row of the Excel table;
    利用所述转换规则,根据所述字段的对应关系将Excel表每一行中字段对应列的值转换为关系型数据库对应表中字段对应列的值;Using the conversion rule, converting the value of the corresponding column of the field in each row of the Excel table to the value of the column corresponding to the field in the relational database corresponding table according to the corresponding relationship of the field;
    在Excel中显示转换结果。Display the conversion result in Excel.
  5. 根据权利要求1所述的方法,其特征在于,所述将所述转换结果导入到关系型数据库中,包括:The method according to claim 1, wherein said importing said conversion result into a relational database comprises:
    将所述转换结果中的数据与关系型数据库对应表中存储的数据进行比对;Comparing the data in the conversion result with the data stored in the relational database correspondence table;
    若关系型数据库中不存在对应的数据,则将所述转换结果中的数据导入到关系型数据库中;If the corresponding data does not exist in the relational database, the data in the conversion result is imported into the relational database;
    若关系型数据库中存在一致的数据,则进行提示;Prompt if there is consistent data in the relational database;
    若关系型数据库中存在不一致的数据,则将所述不一致的数据更新为所述转换结果中的数据。If there is inconsistent data in the relational database, the inconsistent data is updated to the data in the conversion result.
  6. 一种Excel数据导入数据库的装置,其特征在于,所述装置包括:An apparatus for importing Excel data into a database, wherein the apparatus comprises:
    连接单元,用于通过Excel VBA程序将Excel连接上关系型数据库;a connection unit for connecting Excel to a relational database through an Excel VBA program;
    设置单元,用于设置Excel表中字段与关系型数据库对应表中字段的对应关系;a setting unit, configured to set a correspondence between a field in the Excel table and a field in the correspondence table of the relational database;
    解析单元,用于解析关系型数据库对应表中字段的相关属性;a parsing unit, configured to parse related attributes of the fields in the correspondence table of the relational database;
    规则确定单元,用于根据所述字段的对应关系和相关属性,确定转换规则;a rule determining unit, configured to determine a conversion rule according to the corresponding relationship of the field and related attributes;
    转换单元,用于利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果;a conversion unit, configured to convert, by using the conversion rule, a value of a column corresponding to a field in an Excel table to a value of a column corresponding to a field in a relational database according to a correspondence relationship of the field, and display a conversion result in Excel;
    导入单元,用于将所述转换结果导入到关系型数据库中。An import unit for importing the conversion result into a relational database.
  7. 根据权利要求6所述的装置,其特征在于,所述装置还包括:The device according to claim 6, wherein the device further comprises:
    检测单元,用于检测所述转换结果是否出错;a detecting unit, configured to detect whether the conversion result is erroneous;
    修改单元,用于若所述转换结果出错,根据出错原因修改所述转换规则,触发所述转换单元;若所述转换结果未出错,触发所述导入单元。And a modifying unit, configured to: if the conversion result is in error, modify the conversion rule according to the error reason, trigger the conversion unit; if the conversion result is not in error, trigger the import unit.
  8. 根据权利要求6所述的装置,其特征在于,所述设置单元,包括:The device according to claim 6, wherein the setting unit comprises:
    字段获取单元,用于通过Excel VBA程序获取关系型数据库对应表中的字段;a field obtaining unit, configured to obtain a field in a relational database correspondence table by using an Excel VBA program;
    关系设置单元,用于设置Excel表中字段与关系型数据库对应表中字段的对应关系;a relationship setting unit, configured to set a correspondence between a field in the Excel table and a field in the correspondence table of the relational database;
    保存单元,用于保存所述对应关系。A saving unit is configured to save the correspondence.
  9. 根据权利要求6所述的装置,其特征在于,所述转换单元,包括:The apparatus according to claim 6, wherein the converting unit comprises:
    列值获取单元,用于获取Excel表每一行中字段对应列的值;a column value obtaining unit, configured to obtain a value of a column corresponding to a field in each row of the Excel table;
    值转换单元,用于利用所述转换规则,根据所述字段的对应关系将Excel表每一行中字段对应列的值转换为关系型数据库对应表中字段对应列的值;a value conversion unit, configured to convert, by using the conversion rule, a value of a column corresponding to a field in each row of the Excel table to a value corresponding to a column in a correspondence table of the relational database according to a correspondence relationship of the field;
    显示单元,用于在Excel中显示转换结果。Display unit for displaying the conversion result in Excel.
  10. 根据权利要求6所述的装置,其特征在于,所述导入单元,包括:The device according to claim 6, wherein the importing unit comprises:
    比对单元,用于将所述转换结果中的数据与关系型数据库对应表中存储的数据进行比对;a comparison unit, configured to compare data in the conversion result with data stored in a relational database correspondence table;
    更新导入单元,用于若关系型数据库中不存在对应的数据,则将所述转换结果中的数据导入到关系型数据库中;若关系型数据库中存在一致的数据,则进行提示;若关系型数据库中存在不一致的数据,则将所述不一致的数据更新为所述转换结果中的数据。Updating the import unit, if the corresponding data does not exist in the relational database, importing the data in the conversion result into the relational database; if there is consistent data in the relational database, prompting; if the relational type If there is inconsistent data in the database, the inconsistent data is updated to the data in the conversion result.
  11. 一种计算机设备,其特征在于,所述计算机设备包括存储器,以及与所述存储器相连的处理器;所述存储器用于存储计算机程序;所述处理器用于运行所述存储器中存储的计算机程序,以执行如下步骤:A computer device, comprising: a memory, and a processor coupled to the memory; the memory for storing a computer program; the processor for running a computer program stored in the memory, To perform the following steps:
    通过Excel VBA程序将Excel连接上关系型数据库;Connect Excel to a relational database through an Excel VBA program;
    设置Excel表中字段与关系型数据库对应表中字段的对应关系;Setting the correspondence between the fields in the Excel table and the fields in the correspondence table of the relational database;
    解析关系型数据库对应表中字段的相关属性;Parsing the related attributes of the fields in the relational database correspondence table;
    根据所述字段的对应关系和相关属性,确定转换规则;Determining a conversion rule according to the correspondence between the fields and related attributes;
    利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果;Using the conversion rule, converting the value of the column corresponding to the field in the Excel table to the value of the column corresponding to the field in the relational database corresponding table according to the corresponding relationship of the field, and displaying the conversion result in Excel;
    将所述转换结果导入到关系型数据库中。Import the conversion result into a relational database.
  12. 根据权利要求11所述的计算机设备,其特征在于,在所述将所述转换结果导入到关系型数据库中之前,所述处理器还执行如下步骤:The computer apparatus according to claim 11, wherein said processor further performs the following steps before said importing said conversion result into said relational database:
    检测所述转换结果是否出错;Detecting whether the conversion result is erroneous;
    若所述转换结果出错,根据出错原因修改所述转换规则;执行利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果的步骤;若所述转换结果未出错,执行将所述转换结果导入到关系型数据库中的步骤。If the conversion result is in error, the conversion rule is modified according to the error reason; and the conversion rule is used to convert the value of the corresponding column of the field in the Excel table into the corresponding column of the field in the relational database corresponding table according to the correspondence relationship of the field The value and the step of displaying the conversion result in Excel; if the conversion result is not in error, perform the step of importing the conversion result into the relational database.
  13. 根据权利要求11所述的计算机设备,其特征在于,所述处理器在执行 所述设置Excel表中字段与关系型数据库对应表中字段的对应关系时,具体执行如下步骤:The computer device according to claim 11, wherein the processor performs the following steps when performing the correspondence between the fields in the setting Excel table and the fields in the relational database correspondence table:
    通过Excel VBA程序获取关系型数据库对应表中的字段;设置Excel表中字段与关系型数据库对应表中字段的对应关系;保存所述对应关系。Obtain the fields in the relational database correspondence table through the Excel VBA program; set the correspondence between the fields in the Excel table and the fields in the relational database correspondence table; save the corresponding relationship.
  14. 根据权利要求11所述的计算机设备,其特征在于,所述处理器在执行所述利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果时,具体执行如下步骤:The computer device according to claim 11, wherein the processor performs the using the conversion rule to convert a value of a column corresponding to a field in an Excel table to a relational database according to a correspondence relationship of the fields. When the field in the table corresponds to the value of the column and displays the conversion result in Excel, perform the following steps:
    获取Excel表每一行中字段对应列的值;Get the value of the corresponding column of the field in each row of the Excel table;
    利用所述转换规则,根据所述字段的对应关系将Excel表每一行中字段对应列的值转换为关系型数据库对应表中字段对应列的值;Using the conversion rule, converting the value of the corresponding column of the field in each row of the Excel table to the value of the column corresponding to the field in the relational database corresponding table according to the corresponding relationship of the field;
    在Excel中显示转换结果。Display the conversion result in Excel.
  15. 根据权利要求11所述的计算机设备,其特征在于,所述处理器在执行所述将所述转换结果导入到关系型数据库中时,具体执行如下步骤:The computer device according to claim 11, wherein the processor performs the following steps when performing the importing the conversion result into a relational database:
    将所述转换结果中的数据与关系型数据库对应表中存储的数据进行比对;Comparing the data in the conversion result with the data stored in the relational database correspondence table;
    若关系型数据库中不存在对应的数据,则将所述转换结果中的数据导入到关系型数据库中;若关系型数据库中存在一致的数据,则进行提示;若关系型数据库中存在不一致的数据,则将所述不一致的数据更新为所述转换结果中的数据。If the corresponding data does not exist in the relational database, the data in the conversion result is imported into the relational database; if there is consistent data in the relational database, the prompt is performed; if there is inconsistent data in the relational database And updating the inconsistent data to the data in the conversion result.
  16. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令被处理器执行时,实现如下步骤:A computer readable storage medium, characterized in that the computer readable storage medium stores a computer program, the computer program comprising program instructions, when the program instructions are executed by the processor, implementing the following steps:
    通过Excel VBA程序将Excel连接上关系型数据库;Connect Excel to a relational database through an Excel VBA program;
    设置Excel表中字段与关系型数据库对应表中字段的对应关系;Setting the correspondence between the fields in the Excel table and the fields in the correspondence table of the relational database;
    解析关系型数据库对应表中字段的相关属性;Parsing the related attributes of the fields in the relational database correspondence table;
    根据所述字段的对应关系和相关属性,确定转换规则;Determining a conversion rule according to the correspondence between the fields and related attributes;
    利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果;Using the conversion rule, converting the value of the column corresponding to the field in the Excel table to the value of the column corresponding to the field in the relational database corresponding table according to the corresponding relationship of the field, and displaying the conversion result in Excel;
    将所述转换结果导入到关系型数据库中。Import the conversion result into a relational database.
  17. 根据权利要求16所述的计算机可读存储介质,其特征在于,在所述将所述转换结果导入到关系型数据库中之前,所述处理器还实现如下步骤:The computer readable storage medium according to claim 16, wherein said processor further implements the following steps before said importing said conversion result into said relational database:
    检测所述转换结果是否出错;Detecting whether the conversion result is erroneous;
    若所述转换结果出错,根据出错原因修改所述转换规则;执行利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果的步骤;若所述转换结果未出错,执行将所述转换结果导入到关系型数据库中的步骤。If the conversion result is in error, the conversion rule is modified according to the error reason; and the conversion rule is used to convert the value of the corresponding column of the field in the Excel table into the corresponding column of the field in the relational database corresponding table according to the correspondence relationship of the field The value and the step of displaying the conversion result in Excel; if the conversion result is not in error, perform the step of importing the conversion result into the relational database.
  18. 根据权利要求16所述的计算机可读存储介质,其特征在于,所述处理器在执行所述设置Excel表中字段与关系型数据库对应表中字段的对应关系时,具体实现如下步骤:The computer readable storage medium according to claim 16, wherein the processor specifically implements the following steps when performing the correspondence between the fields in the setting Excel table and the fields in the relational database correspondence table:
    通过Excel VBA程序获取关系型数据库对应表中的字段;设置Excel表中字段与关系型数据库对应表中字段的对应关系;保存所述对应关系。Obtain the fields in the relational database correspondence table through the Excel VBA program; set the correspondence between the fields in the Excel table and the fields in the relational database correspondence table; save the corresponding relationship.
  19. 根据权利要求16所述的计算机可读存储介质,其特征在于,所述处理器在执行所述利用所述转换规则,根据所述字段的对应关系将Excel表中字段对应列的值转换为关系型数据库对应表中字段对应列的值并在Excel中显示转换结果时,具体实现如下步骤:The computer readable storage medium according to claim 16, wherein the processor performs the using the conversion rule to convert a value of a column corresponding to a field in an Excel table into a relationship according to a correspondence relationship of the fields. When the type database corresponds to the value of the column corresponding to the field in the table and displays the conversion result in Excel, the following steps are implemented:
    获取Excel表每一行中字段对应列的值;Get the value of the corresponding column of the field in each row of the Excel table;
    利用所述转换规则,根据所述字段的对应关系将Excel表每一行中字段对应列的值转换为关系型数据库对应表中字段对应列的值;Using the conversion rule, converting the value of the corresponding column of the field in each row of the Excel table to the value of the column corresponding to the field in the relational database corresponding table according to the corresponding relationship of the field;
    在Excel中显示转换结果。Display the conversion result in Excel.
  20. 根据权利要求16所述的计算机可读存储介质,其特征在于,所述处理器在执行所述将所述转换结果导入到关系型数据库中时,具体实现如下步骤:The computer readable storage medium according to claim 16, wherein the processor specifically implements the following steps when performing the importing the conversion result into a relational database:
    将所述转换结果中的数据与关系型数据库对应表中存储的数据进行比对;Comparing the data in the conversion result with the data stored in the relational database correspondence table;
    若关系型数据库中不存在对应的数据,则将所述转换结果中的数据导入到关系型数据库中;若关系型数据库中存在一致的数据,则进行提示;若关系型数据库中存在不一致的数据,则将所述不一致的数据更新为所述转换结果中的数据。If the corresponding data does not exist in the relational database, the data in the conversion result is imported into the relational database; if there is consistent data in the relational database, the prompt is performed; if there is inconsistent data in the relational database And updating the inconsistent data to the data in the conversion result.
PCT/CN2018/101991 2018-03-22 2018-08-23 Method and apparatus for importing excel data into database, and computer device and storage medium WO2019179021A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810241485.1 2018-03-22
CN201810241485.1A CN108491510A (en) 2018-03-22 2018-03-22 Excel data import method, apparatus, computer equipment and the storage medium of database

Publications (1)

Publication Number Publication Date
WO2019179021A1 true WO2019179021A1 (en) 2019-09-26

Family

ID=63319343

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/101991 WO2019179021A1 (en) 2018-03-22 2018-08-23 Method and apparatus for importing excel data into database, and computer device and storage medium

Country Status (2)

Country Link
CN (1) CN108491510A (en)
WO (1) WO2019179021A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111444691A (en) * 2020-03-23 2020-07-24 山东浪潮通软信息科技有限公司 Method for rapidly processing import form of Word table data
WO2022242441A1 (en) * 2021-05-21 2022-11-24 北京字跳网络技术有限公司 Spreadsheet importing method, apparatus, and device, and medium

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109543154B (en) * 2018-10-11 2021-07-23 天津字节跳动科技有限公司 Type conversion method and device of table data, storage medium and electronic equipment
CN111104443A (en) * 2018-11-30 2020-05-05 中国航空工业集团公司沈阳飞机设计研究所 Excel table-based supplier software process and product monitoring method
CN109871405B (en) * 2018-12-13 2023-01-24 珠海迎迎科技有限公司 Method and device for importing Excel table data into database
CN109614434A (en) * 2018-12-14 2019-04-12 万翼科技有限公司 Data lead-in method, device and computer readable storage medium
CN109753536A (en) * 2019-01-15 2019-05-14 顺丰科技有限公司 A kind of data docking facilities and method
CN110008446A (en) * 2019-02-27 2019-07-12 深圳点猫科技有限公司 The method and electronic equipment that a kind of language based on programming converts form document
CN114217798A (en) * 2021-12-20 2022-03-22 中国农业银行股份有限公司 Code generation method and device for database form interface
CN115860677B (en) * 2022-12-12 2024-03-22 中量工程咨询有限公司 Component engineering quantity data processing method, system, equipment and storage medium
CN117009422B (en) * 2023-05-09 2024-04-12 三峡高科信息技术有限责任公司 Method for realizing data import by convenience business personnel

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103020089A (en) * 2011-09-27 2013-04-03 深圳市金蝶友商电子商务服务有限公司 Method and device for importing data in EXCEL file to database
CN106528821A (en) * 2016-11-16 2017-03-22 济南浪潮高新科技投资发展有限公司 Method for importing change column data into database
CN107145537A (en) * 2017-04-21 2017-09-08 上海斐讯数据通信技术有限公司 A kind of list data introduction method and system

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102591808B (en) * 2011-12-19 2014-11-26 上海西门子工业自动化有限公司 System and method for DCS (distributed control system) hardware configuration based on Excel
CN105760382A (en) * 2014-12-16 2016-07-13 深圳云之家网络有限公司 Method and device for importing excel data into database
CN107291674A (en) * 2017-06-12 2017-10-24 广东川田卫生用品有限公司 A kind of method that Excel list datas are converted to database format

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103020089A (en) * 2011-09-27 2013-04-03 深圳市金蝶友商电子商务服务有限公司 Method and device for importing data in EXCEL file to database
CN106528821A (en) * 2016-11-16 2017-03-22 济南浪潮高新科技投资发展有限公司 Method for importing change column data into database
CN107145537A (en) * 2017-04-21 2017-09-08 上海斐讯数据通信技术有限公司 A kind of list data introduction method and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
LIU, XUGUANG ET AL.: "Non-officical translation: A Pipeline Data Conversion Method based on Excel VBA", OFFICE INFORMATIZATION, 31 October 2014 (2014-10-31) *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111444691A (en) * 2020-03-23 2020-07-24 山东浪潮通软信息科技有限公司 Method for rapidly processing import form of Word table data
CN111444691B (en) * 2020-03-23 2023-10-13 浪潮通用软件有限公司 Method for rapidly processing Word form data import form
WO2022242441A1 (en) * 2021-05-21 2022-11-24 北京字跳网络技术有限公司 Spreadsheet importing method, apparatus, and device, and medium
US12086126B2 (en) 2021-05-21 2024-09-10 Beijing Zitiao Network Technology Co., Ltd. Method, device and apparatus for spreadsheet importing, and medium

Also Published As

Publication number Publication date
CN108491510A (en) 2018-09-04

Similar Documents

Publication Publication Date Title
WO2019179021A1 (en) Method and apparatus for importing excel data into database, and computer device and storage medium
US8601438B2 (en) Data transformation based on a technical design document
CN111324609B (en) Knowledge graph construction method and device, electronic equipment and storage medium
WO2019153554A1 (en) Data relationship display method and device, computer equipment and storage medium
US20110022618A1 (en) Standardized database connectivity support for an event processing server in an embedded context
WO2019062191A1 (en) Electronic device, method and system for extracting data in data table, and storage medium
US10657324B2 (en) Systems and methods for generating electronic document templates and electronic documents
WO2020155740A1 (en) Information query method and apparatus, and computer device and storage medium
US20200104240A1 (en) Source code management systems and methods
CN109710220B (en) Relational database query method, relational database query device, relational database query equipment and storage medium
CN108388623B (en) ER relationship generation method and device, computer equipment and storage medium
CN114328574A (en) Data query method and device, electronic equipment and computer-readable storage medium
WO2019019702A1 (en) Algorithm generation method and device, terminal device and storage medium
CN110704476A (en) Data processing method, device, equipment and storage medium
CN117909355A (en) Database query instruction generation method, device, computer equipment and storage medium
US10289620B1 (en) Reporting and data governance management
CN116244387A (en) Entity relationship construction method, device, electronic equipment and storage medium
CN113792138B (en) Report generation method and device, electronic equipment and storage medium
CN113609128A (en) Method and device for generating database entity class, terminal equipment and storage medium
WO2024012195A1 (en) Unified verification method and apparatus, and device and storage medium
US10318524B2 (en) Reporting and data governance management
CN114817990A (en) Sensitive data management method and device, electronic equipment and storage medium
CN113504957A (en) Table data processing method and device, computer equipment and storage medium
WO2019071416A1 (en) Data management method, terminal and computer readable medium
CN112287027A (en) Database synchronization method, device, equipment and storage medium

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18910796

Country of ref document: EP

Kind code of ref document: A1