Excel report from RPG or SQL

20 pts.
Tags:
Microsoft Excel
RPG
SQL
How do I produce an excel report via RPG or SQL inside an RPG program?

Answer Wiki

Thanks. We'll let you know when a new response is added.

if you can use a CSV file there are a couple ways to do this. If you already have a program that is creating the information, say to a database file, you can do a CPYTOIMPF command from inside the RPG program to copy the ‘native’ file to the IFS. Change the program so the output file is user controlled, at the end of the logic, close the output file, and do a CPYTOIMPF from either a QCMDEXC command or the C system() function.
if you have more time or are creating the program from scratch, consider writing directly to the IFS using among others the open(), write(), and close() api’s. I typically build a string of comma delimited data then write the entire string (record, row) at once.

============================================================

Since a .CSV isn’t an Excel file, though Excel can certainly read and write them (but so can RPG and COBOL and…), I assume that what you want is to write an actual Excel .XLS file.

The simplest way to do it from (ILE) RPG is to use the Java POI/HSSF API. And almost certainly the best introduction to that is through Scott Klement’s articles on POI/HSSF from RPG.

You could, of course, study Microsoft and other documentation on Excel file formats and write them directly with (ILE) RPG. But there’s not much point to it since most of it is already done with POI/HSSF.

Tom

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following