Import data from Excel 2010 into InfoPath 2010

Applies to: InfoPath 2010

Learn how you can import Excel data into InfoPath 2010 by creating an XML mapping in Excel 2010 to be able to save the spreadsheet as an XML file and then use it in InfoPath 2010.

ADVERTISEMENTS

There are two ways to import Excel data into InfoPath 2010:

  1. You could save an Excel file as an XML file and then create an XML data connection in InfoPath to that XML file; or
  2. You could export the Excel file to a SharePoint list and then create a data connection in InfoPath to that SharePoint list.

This article uses the first method to import Excel data into InfoPath 2010 through an XML file.

The first step to be able to import Excel 2010 data into InfoPath 2010 is to save the Excel file as an XML file. But before you can do this, you must create an XML mapping in Excel by mapping the data in Excel to XML elements in an XML schema definition (XSD).

Here you are going to misuse InfoPath to create an XML file that Excel can use to automatically extract the XML data source and use it for the XML mappings in Excel.

Suppose you have an XML spreadsheet with names and colors of Microsoft Office applications, for example:

TitleColor
WordBlue
ExcelGreen
AccessRed

To be able to import such data into InfoPath, it must have a repeating structure. The quickest way to create an XML file that has a repeating structure without manually having to type in the XML yourself is as follows:

  1. Open InfoPath 2010 and create a new Blank Form template.
  2. Add a Repeating Table control with 2 columns to the form template.
  3. Rename the fields in the repeating table to title and color.
  4. Rename group2 to application, and then move the application repeating group to a location under the myFields group by right-clicking the application repeating group and selecting Move from the drop-down menu that appears.
  5. Rename the myFields group to OfficeApplications, and delete the group1 group. The final data source for the InfoPath form should resemble the following figure:

    Repeating group in the Main data source of the InfoPath 2010 form template

    Figure 1. Repeating group in the Main data source of the InfoPath 2010 form template.
  6. Preview the form.
  7. When the form opens, click Insert item to add a second row to the repeating table.
  8. Click Save to save the InfoPath form locally on disk. Rename the file to OfficeApplications.xml when you save it.
  9. Close InfoPath 2010 without saving the form template.

Once you have an XML file with the structure for a repeating group, you can use this XML file in Excel as follows to create an XML mapping in Excel 2010:

  1. In Excel 2010, open the Excel spreadsheet you want to import into InfoPath 2010.
  2. If the Developer tab is not currently visible in Excel 2010, click File > Options.
  3. On the Excel Options dialog box, click Customize Ribbon on the left side, and then in the Main Tabs list on the right, select Developer, and click OK. The Developer tab should now be visible in Excel 2010.
  4. Click Developer > XML > Source.
  5. On the XML Source task pane, click XML Maps.
  6. On the XML Maps dialog box, click Add, and browse to and select the OfficeApplications.xml file you saved earlier.
  7. Click OK when Excel prompts to create a schema based on the XML source data.
  8. On the XML Maps dialog box, click OK.
  9. On the XML Source task pane, click the ns1:application repeating group. This will automatically also select the ns1:title and ns1:color fields under the repeating group.

    XML Source task pane in Excel 2010 to create XML Mappings

    Figure 2. XML Source task pane in Excel 2010 to create XML Mappings.
  10. Right-click the ns1:application repeating group and select Map element from the context menu.
  11. On the Excel spreadsheet, select all of the rows and columns that make up the data you want to import, and then on the Map XML Elements dialog box, click OK.
  12. Click File > Save As.
  13. On the Save As dialog box, browse to a location where you want to save the XML file for the Excel spreadsheet, enter a suitable File name, select XML Data (*.xml) as the Save as type, and click Save.
  14. Click Continue if Excel displays a warning for losing the worksheet features.
  15. Close Excel.

Now you can add an InfoPath XML data connection to the XML file containing the Excel data in InfoPath 2010 and then use the secondary InfoPath data source to the Excel data to fill a drop-down list box or a repeating table or whatever you wish.

 


Related InfoPath Articles:

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services