XL2000: How to Use a Web Data Source for a PivotTable

ID: Q211908


The information in this article applies to:
  • Microsoft Excel 2000


SUMMARY

Microsoft Excel 2000 contains many Internet-related features, including Web queries, hyperlinks, and .htm file support. However, when you create a PivotTable report, you cannot directly refer to data that is on a Hypertext Transfer Protocol (HTTP) Web server.

This article includes an example that uses a Web query to retrieve data from a comma separated value (.csv) file data source on an HTTP Web server. You can use the retrieved sample data to create a PivotTable report.

NOTE: The method included in this article also works for other types of data sources; however, this article provides an example for only a .csv data source.


MORE INFORMATION

To use a Web query to retrieve data from a Web-based .csv file, you must create three files in addition to your .csv data file. These files have the following extensions: .idc, .htx, and .iqy. Additionally, you must create a data source for the .csv file on your Web server.

Creating the .Csv File

To create a sample .csv file, follow these steps:
  1. Start Microsoft Excel and open a new workbook.


  2. Type the following data in Sheet1:


  3. 
       A1: Name   B1: Amount
       A2: Bob    B2: 1
       A3: Sue    B3: 2
       A4: Tom    B4: 3
       A5: Sue    B5: 4
       A6: Bob    B6: 5 
  4. On the File menu, click Save As, type Csvsource in the File name box, and then click CSV (Comma delimited)(*.csv) in the Save as type list.


  5. Click Save, click OK to save only the active sheet, and then click Yes on the message.


  6. Close Csvsource.csv and move it to the final location on your Web server.


Creating the Data Source for the .Csv File

On the Web server, create a System Data Source Name (DSN) for the .csv file. The steps to do this may be different on your computer; however, the process is the same.

NOTE: Because there are several versions of Windows, the following steps may be different on your computer. If they are, please consult your product documentation to complete these steps.

To create the DSN, use the following steps:
  1. In Control Panel, double-click the ODBC Data Sources icon.


  2. In the ODBC Data Source Administrator dialog box, click the System DSN tab, and then click Add.


  3. In the Create New Data Source dialog box, under Name, click Microsoft Text Driver (*.txt,*.csv), and then click Finish.


  4. In the ODBC Text Setup dialog box, type CSV_Source in the Data Source Name box.


  5. Click to clear the Use Current Directory check box, and then click Select Directory.


  6. In the Select Directory dialog box, locate and select the folder that contains Csvsource.csv, and then click OK.


  7. Click OK in the ODBC Text Setup dialog box, and then click OK in the ODBC Data Source Administrator dialog box.


Creating the .Idc File

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
An .idc file is a text file that you can create with any text editor. To do this use the following steps:
  1. Start Notepad.


  2. Type the following text in the Notepad document:


  3. 
    Datasource: CSV_Source
    Template: Csv_form.htx
    DefaultParameters: Name="Name", Amount="Amount"
    SQLStatement:
    +Select "Name", "Amount"
    +From "Csvsource.csv"
    +Where "Amount" > 2 
  4. Save this file as Csv_query.idc in the Scripts folder on your Web server.


  5. Close the file.


Creating the .Htx File

An .htx file is a text file that you can create with any text editor. To do this, follow these steps:
  1. Start Notepad.


  2. Type the following text in the Notepad document:


  3. 
    <HTML>
    <BODY>
    
    <%begindetail%>
    
    <%if CurrentRecord EQ 0 %>
    <TABLE>
    <TR>
    <TH><B>Name</B></TH>
    <TH><B>Amount</B></TH>
    </TR>
    <%endif%>
    
    <TR>
    <TD><%Name%></TD>
    <TD><%Amount%></TD>
    </TR>
    <%enddetail%>
    </TABLE>
    
    </BODY>
    </HTML>       
  4. Save the file as Csv_form.htx in the Scripts folder on your Web server.


  5. Close the file.


Creating the .Iqy Web Query File

An .iqy file is a text file that you can create with any text editor. To do this, follow these steps:
  1. Start Notepad.


  2. Type the following in the Notepad document:
    
    WEB
    1
    http://<web server name>/scripts/csv_query.idc 
    NOTE: In the HTTP Uniform Resource Locater (URL), <web server name> is the name of the Web server that contains the .csv, .idc, and .htx files.


  3. Save the file as Csv_Web.iqy in the Queries folder on your computer.

    NOTE: If you do not know the location of your Queries folder use the Find command in the Tools menu of Windows Explorer.


  4. Close the file.


Performing the Web Query

To Perform the Web query, follow these steps:
  1. Start Microsoft Excel 2000.


  2. On the Data menu, point to Get External Data, and then click Run Saved Query.


  3. Click CSV_Web.iqy (if necessary browse to find the Queries folder), and then click Get Data.


  4. In the Returning External Data to Microsoft Excel dialog box, click Existing worksheet, click the cell where you want to place the upper-left corner of the external data range, and then click OK.


A table of data from the .csv file is returned to the active sheet. Because the Structured Query Language (SQL) statement in your .idc file restricts the Amount field to values that are greater than 2, only three records are returned.

NOTE: This also creates a defined name in the workbook called CSV_Web.

Creating the PivotTable report

To create the PivotTable report, follow these steps:
  1. Switch to Sheet2 in the workbook.


  2. On the Data menu, click PivotTable and PivotChart Report.


  3. In the PivotTable and PivotChart Wizard - Step 1 of 3 dialog box, click Microsoft Excel list or database and click Next.


  4. In the PivotTable and PivotChart Wizard - Step 2 of 3 dialog box, type Sheet1!CSV_Web in the Range box, and then, click Next.


  5. In the PivotTable and PivotChart Wizard - Step 3 of 3 dialog box, click Layout. Drag the Name field button to the ROW field, and then drag the Amount field button to the DATA field. Click OK, and then click Finish.

    A PivotTable that is based on the data in Sheet1 is created.


  6. Save this workbook as Web_Test.xls.


Updating the PivotTable When Data Changes

To update the PivotTable, follow these steps:
  1. Change the SQL statement in the .idc file on your Web server to the following:


  2. 
    SQLStatement:
    +Select "Name", "Amount"
    +From "Csvsource.csv" 
  3. Save the .idc file.


  4. On the computer with Microsoft Excel 2000, open Web_Test.xls.


  5. On Sheet1, select any cell in the table of data that is returned by the Web query. Then, click Refresh Data on the Data menu.

    Because you changed the SQL statement in your .idc file, all of the records in your .csv file are returned to Sheet1.


  6. Switch to Sheet2, and then select any cell in the PivotTable.


  7. On the Data menu, click Refresh Data.


The PivotTable is updated with the new data that is returned by the Web query.


REFERENCES

For more information about Web queries, click Microsoft Excel Help on the Help menu, type create a web query in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Additional query words:

Keywords : kbtool kbdta kbweb xlquery
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: February 2, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.