4. Using Link Data
If
you have Visio 2010 Pro or Premium, you also have access to the Link
Data feature. Using it is not only much easier than using the Database
Wizard, but it gives you more data choices. In addition to OLEDB and
ODBC data sources, Link Data can hook up to data stored in Excel,
Access, SharePoint lists, and SQL Server.
Link Data works in only one direction: External data
is brought into shapes, but shapes can’t change external data. You can,
however, link data from multiple sources to a single shape.
If you’re not sure which edition of Visio you have,
take a quick look at the Ribbon. If you see the Data tab, then you have
Visio Pro or Premium, and Link Data is available. You can also go to
the Backstage area and click Help. In the upper-right corner, your
edition is listed under Product Activated.
|
Preparing a Master for Link Data
1. | Continue with Ch7 Shape Data.vsd.
|
2. | Create a new, blank page and name it Link Data.
|
3. | Copy a shape from the Light Bulbs page.
Note: This shape shouldn’t be an instance of any master; it still has
the default internal row naming for its Shape Data fields (that is,
Prop.Row_1, Prop.Row_2, and so on) and it doesn’t have an ID field.
|
4. | Clear or set generic values for the bulb’s Shape Data fields.
|
5. | Create a new master in the Document Stencil.
- a. Make sure that the Document Stencil is visible by checking More Shapes, Show Document Stencil.
- b. Drag the light bulb shape into the Document Stencil.
- c. Click on your new master and change the name from Master.X to Light Bulb LD.
|
You use this master with the Link Data features in
the following steps. Unlike Light Bulb DBW, this master is not linked
in any special way to external data.
Now you can import the Excel data. Instead of an
elaborate (long!) set of steps to establish the connection, Link Data
shows the data inside Visio in the External Data window and enables you
to link to shapes using drag and drop.
Importing Data for Link Data (Pro and Premium Only)
1. | Click the Data tab on the Ribbon.
|
2. | Click Link Data to Shapes in the External Data group. The Data Selector window appears. You can see the Data Ribbon in Figure 7.
|
3. | Select Microsoft Excel Workbook and then click Next. |
4. | Browse to the location of Light Bulb Data.xlsx and then select it. Click Next.
|
5. | For
the worksheet or range, select ModelTypePower from the drop-down list.
Notice that the Data Selector also sees Sheet1$ as a data range. If you
use Link Data, you don’t need to define a named range as for the
Database Wizard, but it is nice to see a meaningful name nevertheless.
|
6. | Make sure that First Row of Data Contains Column Headings is checked and then click Next.
|
7. | In
the Connect to Data screen, you can select columns and specific rows
from the data source to import. For now, leave the default (All
Columns) and (All Rows) settings as they are and then click Next.
|
8. | In
the Configure Refresh Unique Identifier screen, an ID field is
recommended as the key into your data. Make sure that this is checked,
click Next, and then click Finish.
|
The External Data window appears beneath
the drawing window, filled with familiar data from the Light Bulb Data
Excel file. Now you’re ready to link the data to shapes.