fhg
Volume 8, Number 29 -- August 13, 2008

Serving Up Spreadsheets

Published: August 13, 2008

by Paul Tuohy

Our users are always looking for information in different formats. They want to see it on a screen, in a report, in a PDF document, in an email, or in a spreadsheet. There are many ways of achieving all of these but most require third-party products or quite a bit of study to master a new programming technique.

Well, there is a very easy way to generate the spreadsheets your users require using nothing more then Excel, RPG, CGIDEV2, and a little knowledge of XML (no experience required).

Excel (as of Excel 2002, I believe) allows you to save a spreadsheet in an XML format. This allows you to create a "skeleton" spreadsheet (using Excel), input that skeleton spreadsheet to an RPG program, and generate another Excel spreadsheet (also in XML format).

CGIDEV2 is a free tool that you can download at www.easy400.net. CGIDEV2 is best known for allowing RPG programs to interact with Web pages, but it can also be used to create a document in the IFS.

The best way to learn is to look at an example.

The Required Result

Figure 1 shows the spreadsheet I want to create. It lists products, their descriptions, the stock on hand, and the value of a single product. The extended value for each product is calculated (stock on hand multiplied by value) and the extended values are summarized.


Figure 1: Expected Spreadsheet


The Skeleton Spreadsheet

You start by creating a skeleton spreadsheet, as shown in Figure 2. The main points to note are:

  • Unnecessary worksheets are deleted and the worksheet is named as required (Stock Valuation)
  • Cells are set to required widths and formatted (numeric formats, etc.) as required
  • Define one row as it should appear in the spreadsheet
  • Extended Value is a formula (C3*D3)
  • Total Extended Value is a formula (=SUM(E3:E3))

Figure 2: Skeleton Spreadsheet


Select Save As to save the spreadsheet. In the resulting window (shown in Figure 3) select XML Spreadsheet as the Save As Type and give the spreadsheet a name of your choice. (StockValuationSkeleton.xml in this example.)


Figure 3: Saving Spreadsheet in XML Format


You now have an XML document that requires a few minor changes.

Changing the XML Skeleton Spreadsheet

Edit the XML Skeleton spreadsheet using any text editor of your choice--even Notepad. You need to change the XML to include the required CGIDEV2 section and variable names, and you'll have to make one little tweak to ensure the generated spreadsheet may be loaded. There is a lot of XML but very few changes to be made. The changes are as follows (please refer to the corresponding numbers in Figure 4):

  1. Put a section name (/$start) at the start of the document.
  2. Change the value of the ExpandedRowCount attribute in the Table element to reflect the maximum number of rows that can be in the generated spreadsheet. This is very important. If the actual number of rows in the generated spreadsheet exceeds this number, the spreadsheet will not be accessible.
  3. Put a section name (/$line) at the start of the product row.
  4. Replace the data values for the four cells with variable names (/%ProductCode%/, /%ProductDescription%/, /%stoh%/ and /%buyingprice%/)
  5. Put a section name (/$end) after the product row.
  6. Change the value (1) of the row reference in the first part of the SUM formula to a variable name /%NumRows%/. Cell references are relative and this row reference will indicate the starting row (relative to the total row) for the sum function.

Figure 4: Editing the XML Spreadsheet for use with CGIDEV2


Click here to download the code shown in Figure 4.

Save the XML document and copy it to a directory in the IFS

The RPG Program

The RPG program is a standard CGIDEV2 program, as shown in Figure 5. The main points to note are:

  1. The CGIDEV2 service program (CGISRVPGM2) is listed in the binding directory CGIBNDDIR.
  2. Copy directives include the required CGIDEV2 copy members.
  3. The XML skeleton spreadsheet is loaded.
  4. Start of the document is written.
  5. Variables are updated and a row is written for each product.
  6. Number of rows for SUM function is updated and the rest of the document is written. Note that the document is written with an extension of xls.

Figure 5: The RPG Program to generate the spreadsheet


Click here to download the code shown in Figure 5.

You may simply open the generated document with Excel and you have the spreadsheet shown in Figure 1.

In the End

CGIDEV2 provides a very simple means of generating Excel spreadsheets. All you have to do is get your hands on CGIDEV2 and start coding.

If you are already familiar with CGIDEV2 you will be generating spreadsheets in next to no time. This example took me 15 minutes to put together (creating the skeleton, changing it and writing the RPG program) and I'm sure it would have been quicker if I just had a better understanding of Excel!


Paul Tuohy is CEO of ComCon, an iSeries consulting company, and is one of the co-founders of System i Developer, which hosts the RPG & DB2 Summit conferences. He is an award-winning speaker who also speaks regularly at COMMON conferences, and is the author of "Re-engineering RPG Legacy Applications," "The Programmers Guide to iSeries Navigator," and the self-study course called "iSeries Navigator for Programmers." Send your questions or comments for Paul to Ted Holt via the IT Jungle Contact page.




                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
WORKSRIGHT SOFTWARE

Do you need area code information?
Do you need ZIP Code information?
Do you need ZIP+4 information?
Do you need city name information?
Do you need county information?
Do you need a nearest dealer locator system?

We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

Just call us and we'll arrange for 30 days FREE use of either
ZIP/CITY or PER/ZIP4.

WorksRight Software, Inc.
Phone: 601-856-8337
Fax: 601-856-9432
E-mail: software@worksright.com
Web site: www.worksright.com


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

looksoftware:  snap the best back-end into the coolest front-end
Computer Measurement Group:  CMG '08 International Conference, December 7-12, Las Vegas
COMMON:  Join us at the Focus 2008 workshop conference, October 5 - 8, in San Francisco, California


 

IT Jungle Store Top Book Picks

Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
Getting Started with PHP for i5/OS: List Price, $59.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95


 
The Four Hundred
Why Blade Servers Still Don't Cut It, and How They Might

Power Systems Memory Prices Slashed to Promote Virtualization

Database Modernization Still Unknown Territory

As I See It: God Bless Technology

Virtualization Adoption Skyrockets on Power Systems Iron

The Linux Beacon
What the Heck Is the Midrange, Anyway?

Intel Talks Up Larrabee X64-Based Graphics Engine

IBM's Q2 Server Sales: Let's Do Some Math

As I See It: Babes in Broadband

Gartner Is Projecting a Decline in IT Hiring This Year

Four Hundred Stuff
Paperless System Brings Unexpected Benefits to Power Company

LogRhythm Partners with PowerTech to Support i OS Log Data

Profound Debuts Graphical Admin Interface for Web-Enabled Apps

Correction: WebFacing Lives On, in HIS and HATS

RJS' WebDocs Gets Google-ized

Big Iron
Unisys: Crunch for the Last of the BUNCH

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
August 2, 2008: Volume 10, Number 31

July 26, 2008: Volume 10, Number 30

July 19, 2008: Volume 10, Number 29

July 12, 2008: Volume 10, Number 28

July 5, 2008: Volume 10, Number 27

June 28, 2008: Volume 10, Number 26

The Windows Observer
What Art Thou, Midori?

Microsoft Works to Put the Clamps on 'Exploit Wednesday'

Yahoo Shareholder Meeting Anti-Climactic

Gartner Is Projecting a Decline in IT Hiring This Year

Microsoft to Buy DATAllegro for Data Warehouse Appliances

The Unix Guardian
Sun Carbon Copies Another Q4 and Fiscal Year

Q&A with IBM's Ross Mauri: Talking Power Systems and Power7

Sun Delivers AMP Stack for Solaris and Linux, Windows Coming

As I See It: Babes in Broadband

SAP Profits Under Pressure in Q2, Software Prices Get Jacked

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

WorksRight Software
Help/Systems
Group8 Security


Printer Friendly Version


TABLE OF CONTENTS
Serving Up Spreadsheets

V6R1 Enhancements for Run SQL Scripts

Admin Alert: Common Mistakes When Failing Over to a CBU

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
IFF ACTIVE Equivalent in CL

Printer Problem

Capture Sort File and Copy to Database File

SNMP Traps on i5OS

Java Messages

Copying recs from a subfile to a file and keeping highlights





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement