This program produces the below spreadsheet.
It writes XML to IFS which is then read automagically
by excel as a spreadsheet. This example can be used to
produce multi tabbed spreadsheets. These spreadsheets can
contain any/all of the features in excel.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | H dftactgrp( *no ) bnddir( 'QC2LE') OPTION(*NODEBUGIO) * -------------------------------------------------- * Program - EXCEL * Purpose - * Written - * Author - * * PROGRAM DESCRIPTION * create example XML to view as excel * * INPUT PARAMETERS * Description Type Size How Used * ----------- ---- ---- -------- * * * INDICATOR USAGE * xx - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *--------------------------------------------------- * * d Buf s 65000A d BufP s * INZ(%ADDR(Buf)) d BufLen s 10U 0 d CmdString s 10000 d CmdLength s 15 5 d company s 2s 0 d Complete s 1 d count s 5 0 d count2 s 5 0 d cp s 10U 0 INZ(819) d CR c CONST(X'0d') d CRLF c CONST(X'0d25') d Current s 1 d cymd s 7 0 d Data s 65000 d dbxfil s 10 d dbxlib s 10 d dbxown s 10 d dbxtxt s 50 d dbxatr s 2 d deleted s n d DQ c CONST('"') d FileNam s 15A inz('/xml/jamie2.xml') d FileName1 s 21 d FileName2 s 21 d FileNamP s * inz(%ADDR(FileNam)) d FileDescr s 10I 0 d FirstNew s 1 d formated s 7 d formatBack s 65535A varying d From c CONST(',"''') d header s 65000 d ISODate s D d LC# s 3 0 d LaborCodes s 3 dim(100) d LaborCodeCu s 1 dim(100) d LaborCodeCo s 1 dim(100) d LaborCodePd s 7 0 dim(100) d Len s 3 0 d Length s 9 d Lilian s 10i 0 d NewDate s 52a d NLZero s 2A INZ(X'1500') d O_CREAT s 10I 0 INZ(8) d O_RDWR s 10I 0 INZ(4) d O_TEXTDATA s 10I 0 INZ(16777216) d O_CODEPAGE s 10I 0 INZ(8388608) d Oflag s 10I 0 INZ(0) d Omode s 10U 0 INZ(511) d Pos s 4 0 d Produced s 7 0 d Q c CONST('''') d ReadOneRecord s 1 d reporttype s 20 d RC s 10I 0 d savecustomer s 5 0 d savelib s 10 d SI_Fmt s 50A INZ('\n') d SI_FmtP s * INZ(%ADDR(SI_Fmt)) d SI_Msg s 50A d SI_MsgP s * INZ(%ADDR(SI_Msg)) d sqlrecords s 9 0 d sqlstmt s 23000 varying d Str s 3 0 d style s 65000 d To c CONST(' ') d useweight s 7 0 d Width s 7 d WKSDES s 30 d Workread s 3 0 d x s 2 0 d ZeroBin s 1A INZ(*ALLX'00') * * Program Info * d SDS d @PGM 001 010 d @PARMS 037 039 0 d @JOB 244 253 d @USER 254 263 d @JOB# 264 269 0 * d openList pr d FetchNext pr n d closeList pr * d Num_DS DS d Num_Hex 4A INZ(X'00000000') d Num 10I 0 OVERLAY(Num_Hex) dperror PR 10I 0 EXTPROC('perror') dconst * VALUE dsprintf PR 10I 0 EXTPROC('sprintf') d * VALUE d * VALUE d 10I 0 VALUE OPTIONS(*NOPASS) d * VALUE OPTIONS(*NOPASS) * Open Operations * value returned = file descriptor 0 (OK), -1 (Error) dopen PR 10I 0 EXTPROC('open') d * VALUE d 10I 0 VALUE d 10U 0 VALUE OPTIONS(*NOPASS) d 10U 0 VALUE OPTIONS(*NOPASS) * Read Operations * value returned = number of bytes read or , -1 (Error) Dread PR 10I 0 EXTPROC('read') d 10I 0 VALUE d * Value d 10U 0 VALUE * Write Operations * value returned = number of bytes Written or , -1 (Error) dwrite PR 10I 0 EXTPROC('write') d 10I 0 VALUE d * VALUE d 10U 0 VALUE * Close Operations * value returned = 0 (OK) or , -1 (Error) dclose PR 10I 0 EXTPROC('close') d 10I 0 VALUE * Open Directory Operation * value returned = file descriptor 0 (OK), -1 (Error) dopendir PR * EXTPROC('opendir') d * VALUE * Read Directory Operation * dreaddir PR * EXTPROC('readdir') d * VALUE * Open Directory Operation * value returned = 0 (OK) or , -1 (Error) dclosedir PR 10I 0 EXTPROC('closedir') d * VALUE * Unlink a File from system... Delete File * value returned = 0 (OK) or , -1 (Error) dunlink PR 10I 0 EXTPROC('unlink') d path * Value options(*string) d CEEDAYS pr opdesc d InputDate 65535A const options(*varsize) d picture 65535A const options(*varsize) d Lilian 10i 0 d Feedback 12a options(*omit) d CEEDATE pr opdesc d Lilian 10i 0 d picture 65535A const options(*varsize) d OutputDate 65535A const options(*varsize) d Feedback 12a options(*omit) /Free exsr $buildifs; exsr $readfile; clear data; data = '</Workbook>' + CRLF; Buf = %trim(Data); BufLen = %scan(CRLF:Buf); RC = write(filedescr: BufP: BufLen); RC = close(FileDescr); if FileDescr = -1; RC = perror(FileNamP); Return; endif; *inlr = *on; //-------------------------------------------------------- // $buildIFS - build the temp table in IFS //-------------------------------------------------------- begsr $buildIFS; Filenam = %trim('/xml/jamie.xml'); Filenamp = %ADDR(FileNam); Oflag = O_CREAT + O_RDWR + O_CODEPAGE; FileDescr=open(FileNamP:Oflag:Omode:cp); if FileDescr = -1; RC = perror(FileNamP); return; endif; RC = close(FileDescr); if RC = -1; RC = perror(FileNamP); return; endif; Oflag = O_RDWR + O_TEXTDATA; FileDescr=open(FileNamP:Oflag); if FileDescr = -1; RC = perror(FileNamP); Return; endif; // Write the header Buf = %trim(Data) + CRLF; BufLen = %scan(CRLF:Buf); RC = write(filedescr: BufP: BufLen); clear DATA; endsr; //-------------------------------------------------------- // $readfile - pretend to read file of libs //-------------------------------------------------------- begsr $readfile; for count2 = 1 to 5; // replace with your libraries select; when count2 = 1; saveLib = 'JAMIELIB'; when count2 = 2; saveLib = 'QGPL'; when count2 = 3; saveLib = 'QSYS'; when count2 = 4; saveLib = 'QRPG'; when count2 = 5; saveLib = 'QUSRSYS'; endsl; exsr $header; exsr $detail; exsr $footer; endfor; endsr; //-------------------------------------------------------- // $header - write the header for the excel sheet. //-------------------------------------------------------- begsr $header; data = '<Worksheet ss:Name=' + DQ + %trim(saveLib) + DQ + '>' + cr + '<Table ' + ' x:FullColumns="1"' + ' x:FullRows="1">' + cr + '<Column ss:AutoFitWidth="0" ss:Width="39.75"/>' +cr + '<Column ss:AutoFitWidth="0" ss:Width="90" ss:Span="1"/>' +cr + '<Column ss:Index="9" ss:AutoFitWidth="0" ss:Width="69.75"/>'+crlf; Buf = %trim(Data); BufLen = %scan(CRLF:Buf); RC = write(filedescr: BufP: BufLen); clear data; // add new heading data = '<Row ss:Height="14.25"> ' +cr + ' <Cell ss:MergeAcross="8" ss:StyleID="s22"> '+cr + ' <Data ss:Type="String">' +cr + ' Files Listed from QADBXFIL' + cr + ' </Data></Cell>'+cr + '</Row>' + cr ; // write the five column headings data = %trim(data) + cr + ' <Row>' + ' <Cell ss:StyleID="s23"><Data ss:Type="String">' + 'File' + ' </Data></Cell>' + cr + ' <Cell ss:StyleID="s23"><Data ss:Type="String">' + 'Library' + ' </Data></Cell>' + cr + ' <Cell ss:StyleID="s23"><Data ss:Type="String">' + 'Owner' + ' </Data></Cell>' + cr + ' <Cell ss:StyleID="s23"><Data ss:Type="String">' + 'Description' + ' </Data></Cell>' + cr + ' <Cell ss:StyleID="s23"><Data ss:Type="String">' + 'Attribute' + ' </Data></Cell>' + cr + ' </Row> ' + crlf ; Buf = %trim(Data); BufLen = %scan(CRLF:Buf); RC = write(filedescr: BufP: BufLen); clear data; endsr; //-------------------------------------------------------- // $detail - get detail for current salesperson for today //-------------------------------------------------------- begsr $detail; sqlstmt = 'select ' + 'dbxfil,dbxlib,dbxown,dbxtxt,dbxatr ' + ' from QADBXFIL ' + ' where DBXLIB = ' + Q+ %trim(saveLib) + Q ; openList(); dow fetchNext(); exsr $writerow; enddo; closeList(); endsr; //-------------------------------------------------------- // $writerow - write detail row of spread sheet //-------------------------------------------------------- begsr $writerow; dbxtxt = %xlate('/':' ': dbxtxt); dbxtxt = %xlate('*':' ': dbxtxt); for count = 1 to 05; select; when count = 1; data = cr + '<Row>' + CR + '<Cell><Data ss:Type="String">' + %trim(dbxfil) + '</Data></Cell>' + cr ; when count = 2; data = %trim(data) + CR + '<Cell ss:StyleID="s24"><Data ss:Type="String">' + %trim(dbxlib) + '</Data></Cell>' + cr; when count = 3; data = %trim(data) + CR + '<Cell ss:StyleID="s24"><Data ss:Type="String">' + %trim(dbxown) + '</Data></Cell>' + cr; when count = 4; data = %trim(data) + CR + '<Cell ss:StyleID="s24"><Data ss:Type="String">' + %trim(dbxtxt) + '</Data></Cell>' + cr; when count = 5; data = %trim(data) + CR + '<Cell ss:StyleID="s24"><Data ss:Type="String">' + %trim(dbxatr) + '</Data></Cell>' + cr; endsl; endfor; data = %trim(data) + cr + '</Row>' + CRLF; Buf = %trim(Data); BufLen = %scan(CRLF:Buf); RC = write(filedescr: BufP: BufLen); clear DATA; endsr; //-------------------------------------------------------- // $footer - close all the tags //-------------------------------------------------------- begsr $footer; // write footer data = ' </Table>' + cr + ' <WorksheetOptions xmlns="urn:schemas-microsoft-com:' + 'office:excel">' + cr + ' <TabColorIndex>47</TabColorIndex>' + cr + ' <ProtectObjects>False</ProtectObjects>' +cr + ' <ProtectScenarios>False</ProtectScenarios>' + cr + ' </WorksheetOptions>' + cr + ' </Worksheet>' + crlf ; Buf = %trim(Data); BufLen = %scan(CRLF:Buf); RC = write(filedescr: BufP: BufLen); clear DATA; endsr; //-------------------------------------------------------- // *inzsr - initial one time run subroutine //-------------------------------------------------------- begsr *inzsr; // get todays date in cymd format isodate = %date(); // build the headers for the xml header = '<?xml version="1.0"?>' + CR + '<?mso-application progid="Excel.Sheet"?>' + CR + '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"' + CR + 'xmlns:o="urn:schemas-microsoft-com:office:office"' + CR + 'xmlns:x="urn:schemas-microsoft-com:office:excel"' + CR + 'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"' + CR + 'xmlns:html="http://www.w3.org/TR/REC-html40">' + CR + '<DocumentProperties xmlns="urn:schemas-microsoft-com' + ':office:office">' + CR + '<Author>Author</Author>' + CR + '<LastAuthor>flanary</LastAuthor>' + CR + '<Created>2008-05-10T01:38:01Z</Created>' + CR + '<Version>11.9999</Version>' + CR + '</DocumentProperties>' + CR + '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">' +CR + '<WindowHeight>7755</WindowHeight>' + CR + '<WindowWidth>15225</WindowWidth>' + CR + '<WindowTopX>0</WindowTopX>' + CR + '<WindowTopY>255</WindowTopY>' + CR + '<ActiveSheet>1</ActiveSheet>' + CR + '<ProtectStructure>False</ProtectStructure>' +CR + '<ProtectWindows>False</ProtectWindows>' +CR + '</ExcelWorkbook> ' + CR ; style = '<Styles>' + CR + '<Style ss:ID="Default" ss:Name="Normal">' + CR + '<Alignment ss:Vertical="Bottom"/>'+ CR + '<Borders/>' + CR + '<Font/>' + CR + '<Interior/>' + CR + '<NumberFormat/>'+ CR + '<Protection/>'+ CR + '</Style>' + CR + '<Style ss:ID="s22">' + CR + '<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>' +CR + '<Font x:Family="Swiss" ss:Size="11" ss:Color="#000080"/>'+CR+ '</Style>' + CR + '<Style ss:ID="s23">' + CR + '<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>'+CR+ '<Font x:Family="Swiss" ss:Color="#0000FF" ss:Bold="1"/>' +CR+ '</Style>' + CR + '<Style ss:ID="s24">' + CR + '<NumberFormat ss:Format="Standard"/>' + CR + '</Style>' + CR + '<Style ss:ID="s25">' + CR + '<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>'+CR+ '<NumberFormat ss:Format="Standard"/>' + CR + '<Font x:Family="Swiss" ss:Color="#0000FF" ss:Bold="1"/>' +CR+ '</Style>' + CR + '<Style ss:ID="s26">'+ CR + '<Borders>' + CR + '<Border ss:Position="Bottom" ss:LineStyle="Double" ss:Weight="3"/>' + CR + '<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>'+ CR + '</Borders>' + CR + '<NumberFormat ss:Format="Standard"/>' + CR + '</Style>' + CR + '<Style ss:ID="s27">' + CR + '<Borders>'+ CR + '<Border ss:Position="Bottom" ss:LineStyle="Double" ss:Weight="3"/>' + CR + '<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>'+ CR + '</Borders>' + CR + '<NumberFormat ss:Format="Percent"/>'+ CR + '</Style>' + CR + '</Styles>' + CR; data = %trim(header) + CR + %trim(style) ; CEEDAYS(%char(isodate): 'YYYY-MM-DD': lilian: *omit); formatBack = 'Wwwwwwwwwz, DD Mmmmmmmmmz YYYY'; CEEDATE(Lilian: Formatback : NewDate: *omit); // this ===> Wednesday, 27 June 2007 endsr; /End-Free *-------------------------------------------------------- * openList - Open a cursor to read file *-------------------------------------------------------- p openList b d openList pi /Free exec sql declare MyCursor cursor for statement; exec sql prepare statement from :sqlstmt; exec sql open mycursor; /End-Free p openList e *-------------------------------------------------------- * fetchNext - read one record at a time *-------------------------------------------------------- p fetchNext b d fetchNext pi n /free exec sql fetch next from mycursor into : dbxfil , : dbxlib , : dbxown , : dbxtxt , : dbxatr ; if sqlstt < '02000'; return *on; else; return *off; endif; /end-free p fetchNext e *-------------------------------------------------------- * closeOrderList - Close the OrderHdr cursor *-------------------------------------------------------- p closeList b d closeList pi /free exec sql close MyCursor; /end-free p closeList e |
create XML from RPG read as EXCEL
RPG to XML to IFS Excel