Schedule upload of Excel to database
ryjfgjl

ryjfgjl @ryjfgjl

Joined:
Aug 23, 2022

Schedule upload of Excel to database

Publish Date: Mar 29 '24
1 0

This article will introduce how to schedule upload Excel data to the database.

Prepare data

As shown in the figure, we have a table called product information, which records all the company's product information. When there is a new product, new data will be added to the table. When there is a change in product information, the table data may also be updated. Now, we need to synchronize the data of this table to the database, and when the Excel data is updated, the data in the database can be updated regularly.

DiLu Converter

Initialization

The DiLu Converter tool we use imports Excel to the database table with one click and imports a copy of the initialization data.

DiLu Converter

Determine the update method

There are generally two ways to update data: full update and add update

  1. Full update: that is, delete all the data in the database table, and then import all the data in the Excel table. This method is simple and crude, ensuring the complete consistency of Excel and database data. It is suitable for scenarios where there is full data in Excel.

  2. Add update: that is, based on the existing data in the database table, only the newly added or modified data in Excel is updated. This method requires each row of data to have a fixed unique identifier to distinguish the data, such as the product id here. This is suitable for scenarios where there is only part of the data in the Excel table and there is a unique identifier in the data.

Note: Add updates cannot update physically deleted data

Below we introduce two update methods

Full update

First, save the import just now and name it Product Information, select Overwrite for the import mode, and click Save

DiLu Converter

In the software toolbar-Tasks Schedule -Add Tasks, add a scheduled task called Product Information-Full Update (here we keep the default settings of the scheduled tasks first, and make supplements later)

DiLu Converter

DiLu Converter

You can see the running status of the task in the task schedule interface

DiLu Converter

Edit excel, delete, add, and modify a data test effect respectively. The following figure shows the data in the database table before modification. We will delete product 10, change the unit price of product 1 to 88, and add a new product 11

DiLu Converter

After modification, as shown in the figure, save excel

Check the database table data again, it has been updated

DiLu Converter

Add update

If a full update is in progress, stop it first.

DiLu Converter

Here, we use product id as the unique identifier of the data and set it as the primary key in the database table.

DiLu Converter

Prepare add data, as shown in the figure, a copy contains modified and added data.

DiLu Converter

Add an import, select the add data file, select the target table, select the update mode, click the + on the right, and you can see that the default is to update according to the primary key of the database table. We keep the default and click Save

DiLu Converter

Add a scheduled task called Product Information-Add Update

DiLu Converter

DiLu Converter

You can see that the data has been updated. Let's modify another data test. Here we modify the unit price of product 1 to 100 and add a new product 14

As shown in the figure:

DiLu Converter

Check the database table again, it has been updated

DiLu Converter

Scheduled task settings

DiLu Converter

Subtask type: Select a database connection, you can add saved imports, exports and jobs

Task execution time:

Month: 1-12 can be filled in

Week: 1-7 can be filled in, that is, Monday to Sunday

Day: 1-31 can be filled in

Hour: 0-23 can be filled in

Minute: 0-59 can be filled in

Second: 0-59 can be filled in

If you don't know how to fill in, you can click the Timing Settings Assistant.

Send an email reminder when the task fails: Check and fill in the email settings in the software menu bar-Settings-Email interface.

Note: Scheduled tasks require the software to run all the time. When you click x to close the software interface, the software will exit immediately and stop the scheduled task by default. You can go to the software menu bar-Tools-Settings, check to hide in the tray area instead of exiting the program directly. After hiding, you can right-click the program icon in the tray area and choose to open the main interface or exit the program.

Startup

Applications that need to run scheduled tasks are generally placed on servers that run 24 hours a day, but if it is a scheduled task running on your own computer, you may restart the computer every day. At this time, we can add the program to the startup, and the scheduled task will automatically run after starting the program.

DiLu Converter

Other timing methods

The built-in scheduled task of DiLu Converter needs to keep the program open, and the scheduled task will automatically stop running after exiting the program. If you want to run the scheduled task in the background without opening the program, you can let other special scheduled task programs call the API provided by DiLu Converter. For example, the task scheduler that comes with Windows, this method provides a background operation method without a graphical interface, and can automatically start when the computer is turned on.

API usage can refer to:

DiLu Converter

Comments 0 total

    Add comment