home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR8 / 123EXP.ZIP / EXPRTWK1.CLA next >
Text File  |  1994-01-07  |  32KB  |  746 lines

  1.             MEMBER('dcf')
  2. exprtwk1    PROCEDURE
  3. !******************************************************************************
  4. !   This sample program illustrates the method for exporting to a 1-2-3
  5. !   format spreadsheet file and a WYSIWYG format file (.FMT).
  6.  
  7. !   The key routines to reference are:
  8. !       init_wks        - Creates the spreadsheet file and sets up the
  9. !                           initial header records
  10. !       write_BOF       - Write the 123 "beginning of file" record
  11. !       def_window      - Defines the spreadsheet window, the default formats
  12. !                           and the default column widths
  13. !       set_widths      - Sets the column widths
  14. !       write_label     - Write a "label" cell (uses the write_cell ROUTINE below)
  15. !       write_real      - Writes a real number cell (uses the write_cell ROUTINE below)
  16. !       write_int       - Writes an integer number cell (uses the write_cell ROUTINE below)
  17. !       write_cell      - Writes a cell (and displays the cell location on the
  18. !                           statistics window).
  19.  
  20. !   NOTE: The WYSIWYG formatting code is almost impossible to follow without
  21. !         having some understanding of how the .FMT file records are laid out.
  22. !         This is provided in the Lotus documentation.
  23.  
  24. !   DISCLAIMER: I have not spent any time cleaning up this code.  There are
  25. !   lots of calls to other functions and procedures that I have not removed.
  26. !   There are also references to global variables and files that I have not
  27. !   provided.
  28.  
  29. !******************************************************************************
  30.  
  31. !══════════════════════════════════════════════════════════════════════════════
  32. !   RED - 04/27/93
  33.  
  34. !   This procedure is used to export the cash flow to a 1-2-3 spreadsheet
  35. !   file and a WYSIWYG .FMT formatting file.
  36.  
  37. !══════════════════════════════════════════════════════════════════════════════
  38. stat_screen SCREEN         WINDOW(13,44),PRE(sta),HUE(9,7)
  39.                 ROW(12,2)  PAINT(1,1),TRN
  40.                 ROW(12,3)  PAINT(1,40),HUE(8,0),TRN
  41.                 ROW(4,4)   PAINT(5,38),HUE(1,7)
  42.                 ROW(1,2)   PAINT(1,41),TRN
  43.                 ROW(13,2)  PAINT(1,41),TRN
  44.                 ROW(1,1)   PAINT(13,1),TRN
  45.                 ROW(1,43)  PAINT(13,2),TRN
  46.                 ROW(3,43)  PAINT(10,1),HUE(8,0),TRN
  47.                 ROW(5,22)  PAINT(1,18),HUE(0,7)
  48.                 ROW(7,22)  PAINT(1,7),HUE(0,7)
  49.                 ROW(2,2)   STRING('█▀{39}█')
  50.                 ROW(3,2)   REPEAT(6);STRING('█<0{39}>█') .
  51.                 ROW(9,2)   STRING('█─{39}█')
  52.                 ROW(10,2)  STRING('█<0{39}>█')
  53.                 ROW(11,2)  STRING('█▄{39}█')
  54.                 ROW(4,4)   STRING('┌─{15}╥─{19}┐')
  55.                 ROW(5,4)   REPEAT(2),EVERY(2);STRING('│<0{15}>║<0{19}>│') .
  56.                 ROW(6,4)   STRING('├─{15}╫─{19}┤')
  57.                 ROW(8,4)   STRING('└─{15}╨─{19}┘')
  58.                 ROW(5,6)   STRING('Lines Exported')
  59.                     COL(30) STRING('of')
  60.                 ROW(7,16)  STRING('Cell')
  61.                     COL(24) STRING(':')
  62. msg             ROW(3,4)   STRING(38),HUE(0,7)
  63. exp_cnt         ROW(5,22)  STRING(@N7),HUE(0,7)
  64. max_cnt             COL(33) STRING(7),HUE(0,7)
  65. col             ROW(7,22)  STRING(2),HUE(0,7)
  66. row                 COL(25) STRING(5),HUE(0,7)
  67. esc_msg         ROW(10,4)  STRING('Press [Shift+Esc] to abort.'),HUE(8,7)
  68.             .
  69.  
  70.     INCLUDE('wks_file.inc')
  71.     INCLUDE('wysiwyg.inc')
  72.  
  73. rec_cnt     LONG
  74. exp_cnt     LONG
  75.  
  76. yr_no       BYTE
  77. year        SHORT
  78.  
  79. cur_ptr     LONG
  80. total_line  LONG    ! This is the POINTER of the group total line record.
  81. exp_tot_ttl BYTE    ! If true, the total group heading needs to be exported.
  82.                     !   Set true whenever a group total is encountered, set
  83.                     !   off after the 1st sub-line for that group is exported
  84.                     !   (the group total title must be exported BEFORE the
  85.                     !   1st sub-line for the group is exported).  Used to
  86.                     !   determine if any sub-lines for the group were exported.
  87.                     !   If none were, the group total line is exported without
  88.                     !   the separator line and without the "Total" prefix.
  89.  
  90. lin_ndx     BYTE
  91.  
  92. total_equity    REAL
  93. total_cap       REAL
  94.  
  95. smry_amt    REAL                ! Summary and balance sheet amounts
  96. ini_amt     REAL,OVER(smry_amt)
  97. fin_amt     REAL
  98. col_offset  BYTE                ! Balance sheet column offset (1=left (initial)
  99.                                 !   column, 2=right (final) column)
  100.  
  101. range_row   SHORT               ! Bottom row of the initial, default print range
  102.  
  103. row_attrs   GROUP,PRE(atb)      ! Row attributes to use
  104. row_height      BYTE,DIM(300)
  105. row_attr        BYTE,DIM(300)
  106.             .
  107. attr_idx    SHORT
  108. max_attr    SHORT
  109. sep_line    BYTE
  110.  
  111. top_border  BYTE                ! # of rows in the Top border
  112.  
  113. !──────────────────────────────────────────────────────────────────────────────
  114.     CODE
  115.  
  116.     DO init_stats
  117.     DO init_wks                 ! Initialize the worksheet, define the column
  118.                                 !   layouts and write out the header info
  119.     DO exp_lines                ! Export the line items
  120.     DO line_attrs               ! Write out the line attributes
  121.  
  122.     DO prt_settings             ! Setup the WYSIWYG print settings
  123.     DO cleanup
  124.  
  125.     mem:status = true           ! Normal completion
  126.     RETURN
  127.  
  128. !───Routines───────────────────────────────────────────────────────────────────
  129.  
  130. init_stats   ROUTINE
  131.     exp_cnt        = 0
  132.  
  133.     OPEN(stat_screen)
  134.     sta:max_cnt     = LEFT(FORMAT(RECORDS(lineitem),@N7),SIZE(sta:max_cnt))
  135.     sta:row         = 1
  136.     sta:col         = 'A'
  137.     sta:exp_cnt     = exp_cnt
  138.  
  139. init_wks    ROUTINE     ! Initialize the worksheet and define the column layouts
  140.     wks_filename = CLIP(prj:export_dir) & '\' & dcf:export_file
  141.  
  142.     CREATE(wks_file)                ! Create (or re-create) the file.
  143.     IF ERRORCODE()
  144.         err_msg('Unable to create the spreadsheet file.')
  145.         DO cleanup
  146.         RETURN
  147.     .
  148.     wyv:filename = wks_filename
  149.     wysifile(wyf:setup)             ! Create (or re-create) the WYSIWYG file.
  150.     IF mem:status = false
  151.         DO cleanup
  152.         RETURN
  153.     .
  154.     DO write_BOF                    ! Write the spreadsheet beginning of file record
  155.     DO std_attr_tab                 ! Write out the standard .FMT attribute table record
  156.     DO def_window                   ! Define the spreadsheet window
  157.     DO set_widths                   ! Set the column widths
  158.     DO write_titles                 ! Write out the titles
  159.     DO write_hdrs                   ! Write out the column headings
  160.  
  161.     wks:format = def_format
  162.  
  163. exp_lines   ROUTINE                 ! Export the line items
  164.     sta:msg = 'Exporting the lines for ' & CLIP(dcf:id) & '...'
  165.  
  166.     total_line  = 0
  167.     exp_tot_ttl = 0
  168.  
  169.     lin:dcf_id  = dcf:id
  170.     lin:no      = 0
  171.     lin:sub_no  = 0
  172.     SET(lin:key,lin:key)
  173.  
  174.     LOOP UNTIL EOF(lineitem)
  175.         NEXT(lineitem)
  176.         IF lin:dcf_id <> dcf:id
  177.             BREAK
  178.         .
  179.         exp_cnt    += 1
  180.         sta:exp_cnt = exp_cnt
  181.  
  182.         DO abort_check
  183.  
  184.         IF lin:sub_no = 0
  185.             IF total_line                   ! Is there a group total line
  186.                 DO exp_total                !   to export?
  187.         .   .
  188.         IF lin:hide_line                    ! Hide this line?
  189.             CYCLE                           ! Yes - don't export it
  190.         .
  191.         IF exp_tot_ttl                      ! Is there a pending total title?
  192.             DO total_title                  ! Yes - write the title line first
  193.         .
  194.         DO write_line                       ! Write out the line item info
  195.     .
  196.     attr_idx += 1                           ! Format the bottom border
  197.     atb:row_height[attr_idx] = 7            ! Set line height
  198.     atb:row_attr  [attr_idx] = wat:n_lr_wb[6]   ! Normal w/ Left and right borders, wide bottom border
  199.  
  200.     DO exp_id                               ! Export the id at the bottom
  201.  
  202.     range_row        = wks:row              ! Save the most recent row for
  203.                                             !   the print range
  204.     wks:row         += 2
  205.  
  206. line_attrs  ROUTINE                 ! Export the line formatting attributes
  207.     sta:msg = 'Exporting the formats for ' & CLIP(dcf:id) & '...'
  208.     max_attr = attr_idx
  209.     exp_cnt  = 0
  210.  
  211.     LOOP attr_idx = 1 TO max_attr
  212.         exp_cnt    += 1
  213.         sta:exp_cnt = exp_cnt
  214.  
  215.         IF atb:row_height[attr_idx] = 0
  216.             wys:row_height[wyv:cluster_row] = 14            ! Set to default height
  217.         ELSE
  218.             wys:row_height[wyv:cluster_row] = atb:row_height[attr_idx]  ! Row height in points
  219.         .
  220.         IF wys:row_height[wyv:cluster_row] <> 14            ! Default height?
  221.             wys:row_attrs [wyv:cluster_row] = row_fix_hgt   ! No - Mark row as having a non-default row height specified
  222.         .
  223.         wys:row_lumps [wyv:cluster_row] = 2             ! 3 LUMPs for every row
  224.  
  225.         wys:col_count [wyv:cluster_lump] = 0            ! Column "A" (rel to 0!)
  226.         wys:attr_style[wyv:cluster_lump] = 0
  227.         wyv:cluster_lump += 1
  228.  
  229.         wys:col_count [wyv:cluster_lump] = dcf:years    ! The column count is relative to 0 so this will include the description column
  230.         wys:attr_style[wyv:cluster_lump] = atb:row_attr[attr_idx]
  231.         wyv:cluster_lump += 1
  232.  
  233.         wys:col_count [wyv:cluster_lump] = 255 - (1 + dcf:years)
  234.         wysifile(wyf:row_end_lump)                      ! "Write" out the attribute cluster
  235.     .
  236.  
  237. exp_id  ROUTINE         ! Export the release # and DCF id at the bottom
  238.     wks:format       = def_format
  239.     wks:label_prefix = ''''
  240.     wks:row         += 1
  241.     wks:col          = 1
  242.     wks:string       = 'Release: ' & mem:version & '   Id: ' & dcf:id
  243.     DO write_label
  244.  
  245.     attr_idx += 1                               ! Format the line
  246.     atb:row_height[attr_idx] = 9                ! Row height in points
  247.     atb:row_attr  [attr_idx] = wat:no_attr[5]   ! Normal, smaller font
  248.  
  249. write_line  ROUTINE                     ! Write out the line info
  250.     IF lin:method = mth:seperator       ! Seperator line?
  251.         DO set_sep_line                 ! Reformat the previous line
  252.         EXIT
  253.     .
  254.     IF lin:method = mth:group_total     ! Group total line?
  255.         total_line = POINTER(lineitem)  ! Save the record pointer to export the
  256.                                         !   titel and total numbers later
  257.         exp_tot_ttl = true              ! We may need to export the title
  258.         EXIT
  259.     .
  260.     IF wks:row = max_123_rows       ! Check for an overflow
  261.         err_msg('The spreadsheet is full. ' & |
  262.                  CLIP(LEFT(FORMAT(max_123_rows,@N9))) & ' rows have been written.')
  263.         DO cleanup
  264.         mem:status = false
  265.         RETURN
  266.     .
  267.     wks:format       = def_format   ! Turn on cell protection
  268.     wks:label_prefix = ''''         ! Left justify
  269.     wks:col          = 1
  270.  
  271.     IF lin:sub_no = 0               ! Don't indent main lines
  272.         wks:string = lin:desc
  273.     ELSE
  274.         IF total_line                       ! Is there a total line pending?
  275.             wks:string = '    ' & lin:desc  ! Indent sub line descriptions
  276.         ELSE
  277.             wks:string = lin:desc
  278.     .   .
  279.     DO write_label                  ! Export the description
  280.     DO set_attr                     ! Set the attributes for the line
  281.  
  282.     IF lin:method = mth:title       ! Don't export any numbers for a
  283.         wks:row += 1                !   title
  284.     ELSE
  285.         DO export_yrs               ! Export the yearly amounts
  286.     .
  287.  
  288. total_title ROUTINE                 ! Export the current total title line
  289.     exp_tot_ttl = false
  290.     cur_ptr = POINTER(lineitem)     ! Save pointer to current record
  291.     GET(lineitem,total_line)        ! Reload the group total line item
  292.  
  293.     wks:format       = def_format   ! Turn on cell protection
  294.     wks:label_prefix = ''''         ! Left justify
  295.     wks:col          = 1
  296.     wks:string       = lin:desc     ! Just export the description
  297.  
  298.  
  299.     DO write_label                  ! Export the total description
  300.     DO set_attr                     ! Set the attributes for the line
  301.     atb:row_height[attr_idx] = 21   ! Make line 50% taller
  302.     wks:row += 1
  303.     GET(lineitem,cur_ptr)           ! Reload the current line
  304.  
  305. set_attr    ROUTINE     ! Set the attributes depending on what line we're on
  306.     attr_idx += 1
  307.     CASE lin:no
  308.     OF   lno:oper_profit
  309.         atb:row_attr[attr_idx] = wat:b_lr[6]        ! Bold
  310.  
  311.     OF   lno:pre_tax_inc
  312.     OROF lno:net_income
  313.         atb:row_attr[attr_idx] = wat:n_lrb[6]       ! Normal w/ Left, right and bottom borders
  314.  
  315.     OF lno:new_ltd
  316.         atb:row_attr[attr_idx] = wat:n_lr_db[6]     ! Normal with double bottom
  317.     OF lno:available_cf
  318.         atb:row_attr[attr_idx] = wat:bs_lrb[6]      ! Bold, shade, left, right and bottom borders
  319.  
  320.     OF lno:pv_factor
  321.         atb:row_attr[attr_idx] = wat:n_lrb[6]       ! Normal with bottom border
  322.     OF lno:pv_of_cash
  323.         atb:row_attr[attr_idx] = wat:bs_lr[6]       ! Bold, shade
  324.     ELSE
  325.         atb:row_attr[attr_idx] = wat:n_lr[6]        ! Default to Normal w/ Left and right borders
  326.     .
  327.  
  328. set_sep_line    ROUTINE     ! Set the underline attribute for the line above
  329.                             !   when a seperator line is encountered.
  330.     IF attr_idx > 0
  331.         IF atb:row_height[attr_idx] = 7 ! Is the previous line a total seperator?
  332.             EXIT                        ! Yes - no need to underline
  333.         .
  334.         CASE atb:row_attr[attr_idx] ! Be sure the previous line is underlined
  335.         OF   wat:b_lr_wb [6]
  336.         OROF wat:n_lr_db [6]
  337.         OROF wat:bs_lr_wb[6]
  338.         OROF wat:b_lrb   [6]        ! Do nothing if already underlined
  339.  
  340.         OF   wat:b_lr    [6]        ! Bold?
  341.             atb:row_attr[attr_idx] = wat:b_lrb[6]   ! Keep bold w/ Left, right and bottom borders
  342.         OF   wat:bs_lr    [6]       ! Bold and shaded?
  343.             atb:row_attr[attr_idx] = wat:bs_lrb[6]  ! Keep bold and shading w/ Left, right and bottom borders
  344.         ELSE
  345.             atb:row_attr[attr_idx] = wat:n_lrb[6]   ! Normal w/ Left, right and bottom borders
  346.     .   .
  347.  
  348. exp_total ROUTINE           ! Export the total line for a group
  349.     cur_ptr = POINTER(lineitem)     ! Save pointer to current record
  350.     GET(lineitem,total_line)        ! Reload the group total line item
  351.  
  352.     wks:col          = 1
  353.     wks:format       = def_format   ! Turn on cell protection
  354.     IF NOT exp_tot_ttl              ! Were any sub-lines exported?
  355.         atb:row_attr[attr_idx] = wat:n_lr_db[6] ! Yes - Change the formatting
  356.                                                 !   for the previous row to
  357.                                                 !   include a double line
  358.  
  359.         wks:label_prefix = '"'                  ! Right justify
  360.         IF UPPER(SUB(lin:desc,1,6)) = 'TOTAL '
  361.             wks:string   = lin:desc             ! "Total" already there
  362.         ELSE
  363.             wks:string   = 'Total ' & lin:desc  ! Stick "Total" in front
  364.         .
  365.     ELSE                                        ! No sub-lines printed -
  366.         wks:label_prefix = ''''                 ! Left justify
  367.         wks:string   = lin:desc                 ! Just use the straight description
  368.     .
  369.     DO write_label
  370.  
  371.     DO export_yrs               ! Export the yearly amounts
  372.     attr_idx += 1
  373.  
  374.     IF exp_tot_ttl              ! Were any sub-lines exported?
  375.         atb:row_height[attr_idx] = 0                ! Set line height to the default
  376.         atb:row_attr  [attr_idx] = wat:n_lr[6]      ! No - don't use a bottom line
  377.     ELSE
  378.         atb:row_height[attr_idx] = 21               ! Taller line
  379.         atb:row_attr  [attr_idx] = wat:b_lrb[6]     ! Bold w/ Left, right and bottom borders
  380.  
  381.         wks:row += 1            ! Open up an extra blank (seperator) line after
  382.         DO tot_sep_row          ! Format it
  383.     .
  384.     GET(lineitem,cur_ptr)       ! Reload the current line
  385.     total_line  = 0             ! Clear the total line pointer
  386.     exp_tot_ttl = false         !   and flag
  387.  
  388. export_yrs  ROUTINE             ! Export the year columns for the current line item
  389.     wks:col = 2                 ! Always start in column "C"
  390.     LOOP yr_no  = 1 TO dcf:years
  391.  
  392.         DO set_lin_fmt              ! Set the wks format for the current line
  393.         wks:real_no = lin:amount[yr_no]
  394.         DO write_real
  395.         wks:col += 1
  396.     .
  397.     wks:row    += 1                 ! Move down to the next line
  398.  
  399. write_BOF   ROUTINE
  400.     sta:msg = 'Creating the spreadsheet for ' & CLIP(dcf:id) & '...'
  401.  
  402.     CLEAR(wks:record)               ! Initialize the spreadsheet record
  403.     wks:opcode  = bof_op            ! BOF op code
  404.     wks:version = ver_123_2         ! Set to Version 2.x
  405.     wks:length  = 2                 ! Record size (2 bytes)
  406.     ADD(wks_file,wks:length +4)     ! Write the BOF record (length = data + op code + 123 length)
  407.  
  408.     wysifile(wyf:std_init)          ! Do the standard WYSIWYG file
  409.     IF mem:status = false           !   initialization.
  410.         DO cleanup
  411.         RETURN
  412.     .
  413.  
  414. std_attr_tab    ROUTINE ! Setup the attributes needed for this spreadsheet
  415.     CLEAR(wyv:fonts_to_use)
  416.     wyv:font_to_use[1] = 6      ! Use WYSIWYG fonts 6 (primary) and 5.
  417.     wyv:font_to_use[2] = 5
  418.  
  419.     wysifile(wyf:std_attr)      ! Make the standard attribute record for the fonts.
  420.  
  421. def_window  ROUTINE                 ! Define the main spreadsheet window
  422.     CLEAR(wks:window1_info)         ! Initialize the spreadsheet record
  423.     wks:opcode       = window1_def  ! Window #1 definition op code
  424.     wks:length       = 32
  425.  
  426.     top_border = 4                  ! Set the #of rows that make up the top
  427.                                     !   border.  Allow for the fixed company
  428.                                     !   and for up to 4 rows for column headers.
  429.     IF dcf:title <> ''              ! Allow for optional DCF title
  430.         top_border += 1
  431.     .
  432.     LOOP lin_ndx = 1 TO 4           ! Allow for optional title lines
  433.         IF prj:header_line[lin_ndx] <> ''
  434.             top_border += 1
  435.     .   .
  436.     wks:cursor_row   = top_border       ! Define the cursor row
  437.     wks:cursor_col   = 2                !   and column
  438.     wks:top_row      = top_border       ! Define the total row
  439.     wks:title_rows   = top_border       ! Define the #of title rows
  440.  
  441.     wks:cell_format  = comma_0_dec      ! Set the default numeric format
  442.     wks:w1_col_width =  9               ! Set the default column width
  443.     wks:screen_cols  =  5
  444.     wks:screen_rows  = 16
  445.  
  446.     wks:br_width_row =  4           ! I'm not sure why these values work but
  447.     wks:br_width_col =  4           !   the spreadsheet won't load into 1-2-3
  448.     wks:window_width = 53           !   without them!
  449.  
  450.     ADD(wks_file,wks:length +4)     ! Write the definition record
  451.  
  452. set_widths  ROUTINE                 ! Set the column widths
  453.  
  454.     wks:opcode     = col_width_op   ! Set column width op code
  455.     wks:length     = 3              ! 123 record length
  456.  
  457.     wks:col_number = 0              ! Column "A" is a blank border
  458.     wks:col_width  = 1
  459.     ADD(wks_file, 7)
  460.  
  461.     wks:col_number = 1                      ! "B" is the titles
  462.     wks:col_width  = SIZE(lin:desc) + 2     ! Allow for indents
  463.     ADD(wks_file, 7)
  464.  
  465.     ! The yearly amount columns use the default column width of 9
  466.  
  467. set_lin_fmt  ROUTINE      ! Set the wks format for the current line
  468.     EXECUTE (lin:places +1) ! Set the format to use
  469.         wks:format = comma_0_dec
  470.         wks:format = comma_1_dec
  471.         wks:format = comma_2_dec
  472.         wks:format = comma_3_dec
  473.         wks:format = comma_4_dec
  474.         wks:format = comma_5_dec
  475.         wks:format = comma_6_dec
  476.     .
  477.  
  478. write_titles    ROUTINE             ! Write out the titles
  479.     sta:msg = 'Exporting the titles for ' & CLIP(dcf:id) & '...'
  480.  
  481.     wks:label_prefix = ''''
  482.     wks:format       = BAND(def_format,unprot_cell) ! Unprotect the title data
  483.  
  484.     wks:row          = 0            ! Start at the "home" position (B:1)
  485.     wks:col          = 1
  486.     wks:string       = UPPER(mem:company_name)
  487.     DO write_label                  ! Write the company name
  488.     max_attr         = 1            ! Count the title lines written
  489.  
  490.     hdr:dcf_ttl_lin = 0
  491.     LOOP lin_ndx = 1 TO 4
  492.         IF prj:header_line[lin_ndx] = ''    ! Line defined?
  493.             IF hdr:dcf_ttl_lin              ! No - has the DCF title been exported?
  494.                 CYCLE                       ! Yes - don't do it again
  495.             ELSE
  496.                 hdr:dcf_ttl_lin = lin_ndx   ! No - export it
  497.                 IF dcf:title = ''           ! Don't export a blank line!
  498.                     CYCLE
  499.                 ELSE
  500.                     wks:string = dcf:title
  501.             .   .
  502.         ELSE
  503.             wks:string   = prj:header_line[lin_ndx] ! Export the header line
  504.         .
  505.         max_attr += 1
  506.         wks:row  += 1
  507.         DO write_label
  508.     .
  509.     wysifile(wyf:first_clustr)      ! Setup the first WYSIWYG cluster
  510.  
  511.     LOOP max_attr TIMES             ! Set the format for the 1st six rows
  512.         wys:row_height[wyv:cluster_row] = 14            ! Row height in points (default)
  513.         wys:row_lumps [wyv:cluster_row] = 2             ! 3 LUMPs for this row (relative to 0!)
  514.  
  515.         wys:col_count [wyv:cluster_lump] = 0            ! 1st column (rel to 0!)
  516.         wys:attr_style[wyv:cluster_lump] = 0
  517.         wyv:cluster_lump += 1
  518.  
  519.         wys:col_count [wyv:cluster_lump] = 0
  520.         wys:attr_style[wyv:cluster_lump] = wat:b[6]
  521.         wyv:cluster_lump += 1
  522.  
  523.         wys:col_count [wyv:cluster_lump] = 255 - 2
  524.  
  525.         wysifile(wyf:row_end_lump)  ! Finish the row and "write" the cluster
  526.     .
  527.     wks:row += 1
  528.  
  529.  
  530. write_hdrs  ROUTINE                 ! Write out the column headings
  531.     sta:msg = 'Exporting the headers for ' & CLIP(dcf:id) & '...'
  532.  
  533.     wks:format       = BAND(def_format,unprot_cell) ! Unprotect the column header cells
  534.     wks:label_prefix = '^'          ! Center the column headers
  535.  
  536.     wks:col = 1
  537.     wks:label_prefix = '"'
  538.     wks:string = 'YEARS'
  539.     DO write_label
  540.  
  541.     wks:label_prefix = '^'
  542.     LOOP yr_no = 1 TO dcf:years     ! Write out the year numbers
  543.         wks:col += 1                !   across the top
  544.         wks:string = '-' & yr_no & '-'
  545.         DO write_label
  546.     .
  547.     wks:row   += 1                  ! Next line
  548.     wks:col    = 1
  549.     wks:label_prefix = ''''
  550.     wks:string = 'ITEMS'
  551.     DO write_label
  552.  
  553.     wks:label_prefix = '^'
  554.     year = YEAR(dcf:date)
  555.     LOOP yr_no = 1 TO dcf:years     ! Write out the years
  556.         wks:col += 1                !   across the top
  557.         wks:string = year
  558.         DO write_label
  559.         year += 1
  560.     .
  561.     wks:row   += 2
  562.  
  563.     ! WYSIWYG formats for the column headers
  564.     wys:row_height[wyv:cluster_row] = 14        ! Row height in points (default)
  565.     wys:row_lumps [wyv:cluster_row] = 3         ! 4 LUMPs for this row
  566.  
  567.     wys:col_count [wyv:cluster_lump] = 0        ! Column "A" (rel to 0!)
  568.     wys:attr_style[wyv:cluster_lump] = 0
  569.     wyv:cluster_lump += 1
  570.  
  571.     wys:col_count [wyv:cluster_lump] = 0                ! "YEARS" title
  572.     wys:attr_style[wyv:cluster_lump] = wat:bs_lrtb[6]   ! Shaded, bold with complete border
  573.     wyv:cluster_lump += 1
  574.  
  575.     wys:col_count [wyv:cluster_lump] = dcf:years - 1    ! Year numbers columns
  576.     wys:attr_style[wyv:cluster_lump] = wat:bs_lrt[6]    ! Shaded, bold w/ top, left and right borders
  577.     wyv:cluster_lump += 1
  578.  
  579.     wys:col_count [wyv:cluster_lump] = 255 - (2 + (dcf:years - 1))
  580.     wysifile(wyf:row_end_lump)
  581.  
  582.     wys:row_height[wyv:cluster_row] = 14            ! Row height in points (default)
  583.     wys:row_lumps [wyv:cluster_row] = 3             ! 4 LUMPs for this row
  584.  
  585.     wys:col_count [wyv:cluster_lump] = 0            ! Column "A" (rel to 0!)
  586.     wys:attr_style[wyv:cluster_lump] = 0
  587.     wyv:cluster_lump += 1
  588.  
  589.     wys:col_count [wyv:cluster_lump] = 0            ! "ITEMS" title
  590.     wys:attr_style[wyv:cluster_lump] = wat:b_lr_wb[6]
  591.     wyv:cluster_lump += 1
  592.  
  593.     wys:col_count [wyv:cluster_lump] = dcf:years - 1    ! Years columns
  594.     wys:attr_style[wyv:cluster_lump] = wat:bs_lr_wb[6]
  595.     wyv:cluster_lump += 1
  596.  
  597.     wys:col_count [wyv:cluster_lump] = 255 - (2 + (dcf:years - 1))
  598.     wysifile(wyf:row_end_lump)
  599.  
  600.     CLEAR(row_attrs)                ! Clear the row attributes
  601.     attr_idx = 0                    ! Init the attribute row counter
  602.  
  603.     DO tot_sep_row
  604.  
  605. tot_sep_row     ROUTINE     ! Setup a short, totals seperator WYSIWYG line
  606.     attr_idx += 1
  607.     atb:row_height[attr_idx] = 7                ! Set line height
  608.     atb:row_attr  [attr_idx] = wat:n_lr[6]      ! Normal w/ Left and right borders
  609.  
  610. wysi_small      ROUTINE     ! Write out the formatting for the "Release:" row
  611.                             !   with the smaller font (#5)
  612.     wys:row_height[wyv:cluster_row] = 9             ! Row height in points
  613.     wys:row_attrs [wyv:cluster_row] = row_fix_hgt   ! Mark row as having a non-default row height specified
  614.     wys:row_lumps [wyv:cluster_row] = 3             ! 3 LUMPs for this row
  615.  
  616.     wys:col_count [wyv:cluster_lump] = 0            ! Column "A" (rel to 0!)
  617.     wys:attr_style[wyv:cluster_lump] = 0
  618.     wyv:cluster_lump += 1
  619.  
  620.     wys:col_count [wyv:cluster_lump] = 0
  621.     wys:attr_style[wyv:cluster_lump] = wat:no_attr[5]  ! Normal, smaller font
  622.     wyv:cluster_lump += 1
  623.  
  624.     wys:col_count [wyv:cluster_lump] = 255 - 2
  625.     wysifile(wyf:row_end_lump)
  626.  
  627. end_border     ROUTINE      ! WYSIWYG formatting the last line of the DCF
  628.     wys:row_height[wyv:cluster_row] = 7
  629.     wys:row_attrs [wyv:cluster_row] = row_fix_hgt
  630.     wys:row_lumps [wyv:cluster_row] = 2             ! 3 LUMPs for this row
  631.  
  632.     wys:col_count [wyv:cluster_lump] = 0            ! Column "A" (rel to 0!)
  633.     wys:attr_style[wyv:cluster_lump] = 0
  634.     wyv:cluster_lump += 1
  635.  
  636.     wys:col_count [wyv:cluster_lump] = dcf:years
  637.     wys:attr_style[wyv:cluster_lump] = wat:n_lr_wb[6]  ! Normal w/ Left and right borders, wide bottom border
  638.     wyv:cluster_lump += 1
  639.  
  640.     wys:col_count [wyv:cluster_lump] = 255 - (1 + dcf:years)
  641.     wysifile(wyf:row_end_lump)
  642.  
  643. prt_settings    ROUTINE             ! Setup the WYSIWYG print settings
  644.     wysifile(wyf:flush_clustr)              ! Must flush out any pending cluster
  645.                                             !   record before writing over the
  646.                                             !   WYSIWYG record area.
  647.  
  648.     CLEAR(wys:prt_settings)
  649.                                                 ! Print range:
  650.     wys:UpLeftCol = 2                           ! C:10 is the upper left corner
  651.     wys:UpLeftRow = top_border
  652.     wys:LoRghtCol = wys:UpLeftCol + dcf:years - 1   ! Compute the rightmost column of the range
  653.     wys:LoRghtRow = range_row                       ! Last row of the DCF body
  654.  
  655.     wys:RowUpLeftCol = 1                        ! Border row range definition
  656.     wys:RowUpLeftRow = 0                        ! B:1 to B:9
  657.     wys:RowLoRghtCol = 1
  658.     wys:RowLoRghtRow = top_border - 1
  659.  
  660.     wys:ColUpLeftCol = 1                        ! Border Column range definition
  661.     wys:ColUpLeftRow = top_border               ! B:10
  662.     wys:ColLoRghtCol = 1
  663.     wys:ColLoRghtRow = top_border
  664.  
  665.     wys:PaperSizeWid = 8500                     ! Paper size is 8.5" x 11"
  666.     wys:PaperSizeLen = 11000
  667.  
  668.     wys:MarginLeft   = 500                      ! 1/2" left and
  669.     wys:MarginRight  = 500                      !   right margins
  670.     wys:MarginTop    = 1000                     ! 1" top margin
  671.     wys:MarginBot    = 500                      ! 1/2" bottom margin
  672.  
  673.     wys:print_flags  = landscape_on             ! Set to landscape
  674.  
  675.     wysifile(wyf:prt_settings)                  ! Write the settings record
  676.  
  677. write_label ROUTINE                 ! Writes out the current label cell
  678.     wks:opcode  = label_op                      ! Label op code
  679.     wks:string  = CLIP(wks:string) & '<00>'     ! Add the null terminator (using only '' doesn't work)
  680.     wks:length  = 6 + LEN(CLIP(wks:string))     ! Record size = 6 bytes + the
  681.                                                 !   size of the string (with
  682.                                                 !   the null terminator!)
  683.     DO write_cell
  684.  
  685. write_real  ROUTINE                 ! Writes out a real number cell
  686.     wks:opcode  = floating_op               ! Floating (real) op code
  687.     wks:length  = 13                        ! Total data length = cell format code(1 byte)
  688.                                             !                   + row             (2 bytes)
  689.                                             !                   + col             (2 bytes)
  690.                                             !                   + data            (8 bytes)
  691.     DO write_cell
  692.  
  693. write_int   ROUTINE                 ! Writes out an integer # cell
  694.     wks:opcode  = integer_op                ! Integer op code
  695.     wks:length  = 7                         ! Total data length = cell format code(1 byte)
  696.                                             !                   + row             (2 bytes)
  697.                                             !                   + col             (2 bytes)
  698.                                             !                   + data            (2 bytes)
  699.     DO write_cell
  700.  
  701. write_cell  ROUTINE                 ! Writes the current cell record
  702.     sta:row     = wks:row + 1                   ! Show the row written
  703.     IF wks:col < 26
  704.         sta:col    = ' ' & CHR(65 + wks:col)    ! Show the column letter(s) written
  705.     ELSE
  706.         col_offset = INT((wks:col - 1) / 25)    ! Compute the group# (Ax,Bx,Cx,etc.)
  707.         sta:col    = CHR(64 + col_offset) & |   ! Display the group letter
  708.                      CHR(64 + (wks:col - (col_offset * 25)) )   ! and the sub-group letter (AA,AB,AC,etc)
  709.     .
  710.     ADD(wks_file, 4 + wks:length)       ! Write the cell record. Total bytes
  711.                                         !   written = op code (2 bytes)
  712.                                         !           + length  (2 bytes)
  713.                                         !           + data    (x bytes)
  714.  
  715. abort_check     ROUTINE
  716.     LOOP UNTIL NOT KEYBOARD()                   ! Look for keystroke
  717.         ASK                                     ! Get keycode if there is one
  718.  
  719.         IF (KEYCODE() = reject_key) OR |        ! On Shift+Esc
  720.            (KEYCODE() = ctrl_esc)               !   or Ctrl+Esc
  721.             BEEP
  722.             OPEN(msg_box); msg_text = 'Aborting.  Just a moment...'
  723.  
  724.             DO cleanup
  725.             disp_msg('The exporting was aborted as requested.')
  726.             mem:status = false
  727.             RETURN
  728.     .   .
  729.  
  730. cleanup         ROUTINE
  731.     DO write_EOF                ! Write the end of file record
  732.     CLOSE(wks_file)             ! Close the spreadsheet file
  733.     CLOSE(wys_file)             ! Close the WYSIWYG format file
  734.  
  735.     CLOSE(msg_box)              ! Clear whatever message was displayed
  736.  
  737.     sta:exp_cnt     = exp_cnt   ! Display the final record counts
  738.     sta:esc_msg     = ''
  739.  
  740. write_EOF   ROUTINE             ! Write a standard 1-2-3 EOF record
  741.     wks:opcode = eof_op
  742.     wks:length = 0
  743.     ADD(wks_file, 4)
  744.  
  745.     wysifile(wyf:eof)           ! Write the WYSIWYG EOF record and close it
  746.