Definitely simpler than using RPG and CL and you could generify this even more by passing in an SQL query select and other parms such as output file and you now have a general utility.

Richard Schoen
Email: richard@xxxxxxxxxxxxxxxxx

message: 1
date: Tue, 16 Nov 2021 20:50:52 +0000
from: Kevin Bucknum <Kevin@xxxxxxxxxxxxxxxxxxx>

This is the shell I start with for Q&D exports. Nothing fancy, but 90% of the time I just create my headers and query, and let it run. Indentation is significant in python, so posting on code.midrange also. Switching to open source list and directly copying Art since I'm not sure if he is on there or not.

#!/usr/bin/env python3

import ibm_db_dbi as db2
import xlsxwriter as xl

query = "select cusnum, lstnam, init, cdtlmt from qiws.qcustcdt where cdtlmt > 100"

conn = db2.connect()
cur = conn.cursor()

wb = xl.Workbook('sample.xlsx')
ws = wb.add_worksheet('Uno')

# Header row
header = wb.add_format()
ws.write(0,1,'Last Name')
ws.write(0,3,'Credit Limit')

for row_num, row_data in enumerate(cur):
for col_num, value in enumerate(row_data):
ws.write(row_num + 1,col_num, value)

On Tue, 2021-11-16 at 15:23 -0500, Art Tostaine, Jr. wrote:
If we have to add a field to an old query we don't generally rewrite the code/technique. Any new excel spreadsheet requests are always just written directly as a CSV from RPG/SQL or whatever language we are using to extract the data.

I recently tried to write an XSLX natively but didn't get very far. I'd have to search out a simple example in Python to help me get started.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2021 by and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.