05
Sat, Oct
2 New Articles

Getting Data into Microsoft Excel Using the Web

Microsoft
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
Since Microsoft Excel is virtually ubiquitous in many shops, it's best to learn to use it to maximum advantage. One way of doing this is to make it retrieve data from external sources automatically. There are several ways to accomplish this, including ODBC, the Client Access Excel add-in, and text file imports. Each of these methods has its advantages and disadvantages, but one thing that's common about all three is that they're better suited to intranet connections. ODBC and the Client Access Excel add-in also require that you install and configure software on the client machine, which makes it more difficult to distribute spreadsheets that reference external data and adds a layer of complexity to the process.

Fortunately, if you've got a Web server and Microsoft Excel, the HTTP protocol may be the only "middleware" you need. Excel has a built-in method of grabbing data from Web pages and inserting it into a worksheet. This enables you to create a single HTML-formatted report that can be displayed in any Web browser or inserted directly into a spreadsheet. Since there are so many ways to create HTML from your data, this makes an easy and powerful way to get it into your users' spreadsheets.

Get Your Web Data into Excel Step by Step

Let's take a look at the process of getting Web data into Excel. Below are the steps needed to pull data into Excel from any Web server, including your iSeries.

  1. Open a new or existing spreadsheet.
  2. Find where you want to insert the data. Select Data, then Get External Data, and then New Web Query, as shown in Figure 1.

    http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v400.png
    Figure 1: Select Data, Get External Data, New Web Query.

  3. Fill out the New Web Query panel. Enter the URL to retrieve in step 1. (Hint: Try the one shown in Figure 2 for an example.) Then, choose whether or not you want the whole page, only the tables, or one or more specific tables on the page. If you format the data using tables, you get more control over how things are imported. We'll go through that in a bit, but for now, select Entire Page for Step 2. For this example and most applications, you'll probably need only the words on the screen, rather than the formatting as well. One exception to this is if you've got links that you want to carry through to the spreadsheet. For now, set the formatting option in Step 3 to None. Click OK.

    http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v401.png
    Figure 2: Enter the URL to retrieve into your worksheet. Try http://www.mcpressonline.com/mcpressonline_popular_articles.html for a live example!

  4. Select where you want the data to go, and click OK. Note that you can select areas on the screen while the dialog box is open, so point and click!

    http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v402.png
    Figure 3: Select where you want the data to be placed.

  5. The data is inserted into your spreadsheet, ready to be calculated upon or further parsed. If you used the URL in the above example, you'll get a list of our most popular articles, as shown in Figure 4. Note that as of Excel 2000, there is a 65K record limit per worksheet. If you have any more than that, you'll need something like Microsoft Access, which unfortunately, as of at least Office 2000, doesn't seem to have the ability to import Web pages in a manner similar to this.

    http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v403.png
    Figure 4: The page is returned in the worksheet.

How Refreshing!

One of the best things about creating a query in Excel is that you can refresh it automatically. To do so, simply right-click in the query range and select "Refresh Data" from the menu. If you don't see a menu that looks something like the one shown in Figure 5, make sure that you are clicking in the query range, which is any cell that contains data from the query.

http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v404.png
Figure 5: Get new data automatically by right-clicking in the query range and selecting "Refresh Data."

You can also set queries (both Web queries and database queries) to refresh automatically. Do this by right-clicking in the query range and selecting Data Range Properties. That brings up the screen shown in Figure 6.

http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v405.png
Figure 6: Set the query to refresh automatically by editing the data range properties.

Parsing Character Data into Columns

Sometimes, if you don't have control over the page you are retrieving, it may come in to the worksheet in one huge column with a row for each line in the file. In such cases, you may need to split the data into separate fields. There are two ways to do this: 1) parse the column data using available Excel tools or 2) reformat your source data into a table. There are advantages and disadvantages of each.

The Text to Columns Wizard

Excel has a built-in Wizard that may help get the data looking right. If your source data is comma-separated values (CSV) or some other uniform format, Excel's "Text to Columns" feature (shown in Figure 7) will handily convert your data.

http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v406.png

Figure 7: One way to split simple data into columns is to invoke the Text to Columns Wizard.

One problem with the method of importing the whole page and then parsing the results is that it makes getting data into Excel columns a two-step process. That is, you have to import the data and then run a process on it to make it usable. That makes it more complex to distribute your spreadsheet if you want remote users to be able to update it directly from the source data.

http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v407.png

Figure 8: If your data format matches the possibilities on this page, the Text to Columns Wizard can easily import your data. If not, HTML tables are the answer.

Another limitation of the Text to Columns Wizard is that it won't split data into fields based upon varying criteria. It is limited to data formats that can be described in the dialog shown in Figure 8. Depending upon your data, this may or may not be a problem. For example, since there are no clear delimiters, if I wanted to get the From and To locations in the data shown in Figure 7, the Wizard can't do it.

Because of these limitations, a more robust method of retrieving some forms of data is needed. Visual Basic for Applications is one possibility, but I prefer to avoid coding on the client if possible. Fortunately, there is another possibility: importing table data.

Importing Data from Tables

If the Web page that you are importing has data formatted into tables, it makes the data import process more automatic. Excel can be told to read all the tables on a page or one or more particular ones. Using this technique, you can format Web data into tables and have it come into your spreadsheet as columns, automatically--with complete headers! If you have control over the look and layout of the HTML pages that you are importing, you can tweak them for specific types of data transfers, if necessary. No middleware needed!

The process to import data from HTML tables is nearly the same as that outlined above. The only difference comes in Step 3 from the list above: specifying what on the page to grab. In this case, select the "Only the tables" option (Figure 9) or the option to choose one or more specific tables.

http://www.mcpressonline.com/articles/images/2002/Getting%20Data%20Into%20Excel%20Using%20The%20Web%20v408.png

Figure 9: Select the "Only the tables" option to import all the tables on a page.

When you import the table data, each cell in the table will correspond to a cell in your spreadsheet, so the rows and columns will be the same as in your table.

Serving HTML with a Smile

There are many ways to output HTML from iSeries data, whether you serve it directly or indirectly. When serving it directly, the first thing you need is a Web server instance configured and running. For more information on how to set one up, see "Configuring the HTTP Server (Powered by Apache)", which describes the setup process and has links to sources of more information.

You can serve either static files (pages) or dynamic pages. Static files are just plain-text files that contain HTML that can be created by RPG programs or any other process capable of outputting plain-text files. In contrast to static files, dynamic HTML pages are built on the fly and require a process to run on the iSeries and output the results each time they are requested. Dynamic pages give you more current data, but they require processing each time they are requested, so they may have more of an impact on your system's resources. You can create dynamic pages in many ways, including Java Server Pages (JSP) and Java servlets, an RPG-CGI (aka e-RPG) program, a Net.Data macro (see "From Zero to Web with the HTTP Wizard and Net.Data" for a quick start), or any of the numerous third-party tools designed for HTML creation.

The method you choose depends upon your skills, requirements, and pre-existing environment. When considering which type to use, one interesting possibility is to create a report program that outputs static HTML to a flat file. Then, schedule that report program to run when needed (daily, weekly, monthly, etc.). This would give you updated data, yet would minimize the number of times the report would need to be run.

Learning to Love Microsoft Excel

IT shops typically have a love/hate relationship with Microsoft Excel. The love comes from the fact that, in many aspects, it's a great tool for users to analyze their own data and create custom reports. The hate begins when users go too far in creating their own complex reporting systems that need to be fed data, creating extra work for all involved. The worst situation, which I have seen too many times, is when people take data from sources such as iSeries reports and copy/paste or even re-key that data into their spreadsheets. Fortunately, with the many ways to bring external data into Excel, it's easier to learn to love Excel rather than fight it.

Brian Singleton, formerly Editor of Midrange Computing magazine is the Director of Web Development for MCPressOnline. Over the past few years, Brian has developed a line of best-selling training videos, authored the best-selling The OS/400 and Microsoft Office Integration Handbook--Second Edition, and spoken at many popular seminars and conferences. He can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it.

Additional Resources

Brian Singleton
Brian Singleton is former editor of Midrange Computing. He has worked in the IBM midrange arena for many years, performing every job from backup operator to programmer to systems analyst to technology analyst for major corporations and IBM Business Partners. He also has an extensive background in the PC world. Brian also developed a line of bestselling Midrange Computing training videos, authored the bestselling i5/OS and Microsoft Office Integration Handbook, and has spoken at many popular seminars and conferences.

MC Press books written by Brian Singleton available now on the MC Press Bookstore.

i5/OS and Microsoft Office Integration Handbook i5/OS and Microsoft Office Integration Handbook
Harness the power of Microsoft Office while exploiting the iSeries database.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: