Mysql For Excel
Mysql For Excel
Excel
By: Javier Ignacio Trevino Cobos
In previous posts we have talked about importing data from MySQL to Excel,
exporting data from Excel to a new or existing MySQL table (via the Export
Data or Append Data operations) which are common tasks to be performed
against MySQL tables. In this post we will talk about possibly the coolest feature
in MySQL for Excel: the Edit Data operation. This feature allows the retrieval of
a MySQL table's data to an Excel worksheet so the data can be edited, deleted or
inserted in new rows and those changes saved back to the MySQL database in a
friendly and intuitive way; and more importantly, without the need of writing SQL
queries making it accessible to any kind of user.
You will learn in this guide how to do it and all the details about the Edit Data feature
in MySQL for Excel.
This guide assumes you already have a working MySQL Server instance, Microsoft
Office Excel 2007 or higher and MySQL for Excel installed
If you are already familiar with MySQL for Excel and have a connection to
a MySQL server instance you can skip directly to step 4.
1. Opening MySQL for Excel
In Excel, go to the Data tab located in the Ribbon and click MySQL for Excel at the
far right of the Ribbon.
The worksheet name is the same as the MySQL table name, if before this
new worksheet is created there is another one with the same name as the
was already a worksheet named "actor" the new worksheet would have
The Edit MySQL Data action label gets disabled for the
selected MySQL table, since there can be only 1 active "Edit Session" for
that table.
The Edit Data dialog only appears if the selected cell(s) are within the
"Editing Range", if an Excel cell outside that range is selected the Edit
you try to change a value outside that range you will get an error stating that
changes outside the "Editing Range". If for some reason you need to edit
cells outside the "Editing Range" you will need to exit the "Edit Session"
The very first row containing the column names (Excel cells with
a gray color) cannot be edited, if you try to change its contents you will get
When you change some table's data, the Excel cells will turn blue indicating they
contain changes that haven't been committed to the database.
New rows can be inserted using the yellow row just below the last row containing
data, when any Excel cell on that yellow row is changed the row will
turn blue (indicating uncommitted data) and the row just below will now
become yellow and ready to accept data for another new table row.
If you want to delete a whole row from the MySQL table you need to delete the row
as you would in Excel, i.e. by right-clicking the row heading and selecting from the
pop-up context menu the Deleteoption.
To commit the changes to the MySQL database just click Commit Changes on the
floating Edit Data dialog. The result of the commit will be displayed next, if an error
occurred the submitted changes will not be applied and an error dialog will be shown
containing the error message. MySQL for Excel creates a transaction for the
submitted changes, so it is committed or rolled-back as a whole. Below you can see
an example of an error thrown when trying to commit.
Note that the error message is stating the number 140 would be a duplicate entry for
the primary key, hinting the problem is at a changed cell with a value of 140. You will
see that any cells that produced an error will be colored in red, so you know you must
correct the errors before attempting a new commit.
This error can only be corrected by reverting that value (140) back to its original one
(142) since changing the value of a primary key is not allowed. If a value is reverted
back to its previous value the Excel cell will be reverted back to its original
background color (white). After the correction a new attempt to commit the changes
to the database can be made. Let's review a scenario where there are further errors
in this change set as you can see below.
In this particular example the error message was thrown because one of the changes
sent to the database included a deleted row, judging by the error message you can
notice there are foreign key constraints preventing the row from being deleted. In
this scenario we need to undo the changes and apply them again without the deleted
row. To undo the changes click Revert Data on the floating Edit Data dialog, from
here there are 2 options to undo changes:
Refresh Data from DB: undoes any uncommitted changes (blue cells) and
pulls from the database a fresh copy of the table, this is useful when several
persons may be updating the MySQL table's data at the same time since
the contents of the table may have already changed from the time the data
Revert Changed Data: just undoes any uncommitted changes (blue cells)
reverting the data back to the way it was at the time the data was imported
Right-clicking on any area of the floating Edit Data dialog, and a context
menu will pop-up, clicking Exit Edit Mode will close the Edit Data dialog,
and unprotect the Excel worksheet so any Excel cell can be changed
- https://blogs.oracle.com/MySqlOnWindows/
Facebook - http://www.facebook.com/mysql