Ver Mensaje Individual
  #2
Antiguo 25 de marzo de 2026, 19:51
Gusaiello
Forero Activo
Concurso: Segundo puesto: Ganador/a del Segundo puesto en un concurso - Issue reason: Generador de código QR encriptado Activista del Foro: Activista del Foro - Issue reason: Por aportar ejecrcicios para los novatos 
Última Actividad 17.09.2026 14:29
Posts Posts: 236
Likes enviados Enviados: 150
Likes recibidos Recibidos: 139

Ejemplos varios :

Código COBOL:
  1.        IDENTIFICATION DIVISION.
  2.        PROGRAM-ID. EXCEL.
  3.      *Nota Siempre cerrar el excel desde Archivo Salir
  4.      *----------------------------------------------------------------*
  5.      *Agregar un comentario
  6.      *     inquire hoja1   @cells::@item(wrow-n  1) = hrange.
  7.      *     modify  hrange  @value = wnum.
  8.      *     modify  hrange AddComment "Comentario ?????????".
  9.      *---------------------  OTROS  ----------------------------------*
  10.      *Salto de Pagina en el Excel
  11.      *     inquire hoja1  @cells::@item(wrow-n  1) = hrange.
  12.      *     modify hrange  @PageBreak xlPageBreakManual.
  13.      *----------------------------------------------------------------*
  14.      * Es mejor colocar AutoFit() que ColumnWidth
  15.      *     modify hoja1 @range("A1")::ColumnWidth = 6.
  16.      *----------------------------------------------------------------*
  17.      *Centrados
  18.      *     inquire hoja1 @Range(ColRow) = hrange.
  19.      *     modify hrange @horizontalalignment=XlRight.
  20.      *     horizontalalignment=XlCenter
  21.      *     horizontalalignment=XlLeft
  22.      *     horizontalalignment=XlRight
  23.      *----------------------------------------------------------------*
  24.      *Ejemplo Suma en la celda C5 la Fila  4  
  25.      *     modify hexcelapp
  26.      *       @Range("C5")::Formula = "=SUM(4:4)"
  27.      *----------------------------------------------------------------*
  28.      *Ejemplo Suma usando variables
  29.      * 01  Sumar.
  30.      *     02 filler  pic x(05) value "=SUM(".
  31.      *     02 wdes-l  pic xx    value spaces.
  32.      *     02 wdes-n  pic 9(05) value 0.
  33.      *     02 filler  pic x     value ":".
  34.      *     02 whas-l  pic xx    value spaces.
  35.      *     02 whas-n  pic 9(05) value 0.
  36.      *     02 filler  pic x(01) value ")".
  37.      * 01  ColRow1.
  38.      *     02 wcol    pic xx     value spaces.
  39.      *     02 wrow    pic 9(05)  value 0.
  40.      *Resultado de la Suma
  41.      *     move " C"  to wcol.
  42.      *     add 1      to wrow.
  43.      *     modify hoja1 @Range(ColRow1)::Formula = Sumar.
  44.      *----------------------------------------------------------------*
  45.        ENVIRONMENT DIVISION.
  46.        CONFIGURATION SECTION.
  47.        special-names.
  48.              copy "D:\clientes\PRUEBAS\ej-act\def\excel.def".
  49.              .
  50.        INPUT-OUTPUT SECTION.
  51.        DATA DIVISION.
  52.        WORKING-STORAGE SECTION.
  53.      *----------------------------------------------------------------*
  54.            copy "..\def\acucobol.def".
  55.            copy "..\def\fonts.def".
  56.      *----------------------------------------------------------------*
  57.        01  excel-objects-hojas.
  58.            03 hexcelapp    handle of application of excel.
  59.            03 hexcelwkb    handle of workbook    of excel.
  60.            03 hrange       handle of range       of excel.
  61.            03 hoja1        handle of worksheet   of excel.
  62.            03 hoja2        handle of worksheet   of excel.
  63.            03 hoja3        handle of worksheet   of excel.
  64.            03 hoja4        handle of worksheet   of excel.
  65.            03 hoja5        handle of worksheet   of excel.
  66.            03 hoja6        handle of worksheet   of excel.
  67.            03 hoja7        handle of worksheet   of excel.
  68.            03 hoja8        handle of worksheet   of excel.
  69.            03 hoja9        handle of worksheet   of excel.
  70.            03 hoja10       handle of worksheet   of excel.
  71.            03 hoja11       handle of worksheet   of excel.
  72.            03 hoja12       handle of worksheet   of excel.
  73.      *----------------------------------------------------------------*
  74.        01 ColRow.
  75.            02 wcol.
  76.               03 wcol-l  pic xx       value spaces.
  77.               03 wcol-n  pic 9(05)    value 0.
  78.               03 filler  pic x        value ":".
  79.               03 wrow-l  pic xx       value spaces.
  80.               03 wrow-n  pic 9(05)    value 0.
  81.      *----------------------------------------------------------------*
  82.         01 wLeftMargin   pic 9(10)v99 value 0.
  83.         01 wRightMargin  pic 9(10)v99 value 0.
  84.         01 wTopMargin    pic 9(10)v99 value 0.
  85.         01 wBottomMargin pic 9(10)v99 value 0.
  86.         01 wHeaderMargin pic 9(10)v99 value 0.
  87.         01 wFooterMargin pic 9(10)v99 value 0.
  88.      *----------------------------------------------------------------*
  89.      *Formato Fecha luego el excel muestra dd/mm/aaa
  90.        01  wfecha.
  91.            02 wmes   pic 99    value 0.
  92.            02 filler pic x     value "/".
  93.            02 wdia   pic 99    value 0.
  94.            02 filler pic x     value "/".
  95.            02 wani   pic 9999  value 0.
  96.      *----------------------------------------------------------------*
  97.      *Formato Hora (hh:mm:ss)
  98.        01  whora.
  99.             02 whh    pic 99   value 0.
  100.             02 filler pic x    value ":".
  101.             02 wmm    pic 99   value 0.
  102.             02 filler pic x    value ":".
  103.             02 wss    pic 99   value 0.
  104.      *----------------------------------------------------------------*
  105.      *Formato Hora (hhh:mm:ss)
  106.        01  wwhora.
  107.             02 wwhh    pic 999 value 0.
  108.             02 filler  pic x   value ":".
  109.             02 wwmm    pic 99  value 0.
  110.             02 filler  pic x   value ":".
  111.             02 wwss    pic 99  value 0.
  112.      *----------------------------------------------------------------*
  113.         77  wnum     pic 9(10)    value zero.
  114.         77  wape     pic x(60)    value spaces.
  115.         77  wimp     pic 9(15)v99 value zeros.
  116.      *----------------------------------------------------------------*
  117.        PROCEDURE DIVISION.
  118.        INICIO.
  119.      *----------------------------------------------------------------*
  120.            Create Application of @Excel Handle in Hexcelapp.
  121.      *----------------------------------------------------------------*
  122.      *Cantidad de Hojas
  123.            modify  hexcelapp @SheetsInNewWorkBook = 2.
  124.            modify  hexcelapp workbooks::add() giving hexcelwkb.
  125.      *----------------------------------------------------------------*
  126.      *Coloco Nombre a la Hoja 1
  127.            inquire hexcelwkb worksheets::item(1) in hoja1.
  128.            modify  hoja1  @Name = "Hoja Uno".
  129.      *----------------------------------------------------------------*
  130.      *Anulo Valores en Cero Hoja 1
  131.            modify  hoja1
  132.                    application::ActiveWindow::DisplayZeros = 0.
  133.      *----------------------------------------------------------------*
  134.      *Anulo Linea de Division Hoja 1
  135.            modify  hoja1
  136.                    application::ActiveWindow::DisplayGridlines = 0.
  137.      *----------------------------------------------------------------*
  138.      *Coloco Nombre a la Hoja 2
  139.            inquire hexcelwkb   worksheets::item(2) in hoja2.
  140.            modify  hoja2  @Name = "Hoja Dos".
  141.      *----------------------------------------------------------------*
  142.      *Activo Hoja 2
  143.            modify  hoja2  @Activate = ().
  144.      *----------------------------------------------------------------*
  145.      *Anulo Valores en Cero Hoja 2
  146.            modify  hoja2
  147.                    application::ActiveWindow::DisplayZeros = 0.
  148.      *----------------------------------------------------------------*
  149.      *Anulo Linea de Division Hoja 2
  150.            modify  hoja2
  151.                    application::ActiveWindow::DisplayGridlines = 0.
  152.      *----------------------------------------------------------------*
  153.      *Activo Hoja 1
  154.            modify  hoja1  @Activate = ().
  155.      *----------------------------------------------------------------*
  156.      *Desactivo la Hoja de Calculo mientras se Genera
  157.            modify hexcelapp   @Visible = 0.
  158.      *----------------------------------------------------------------*
  159.      *                   Titulo En hoja 1                             *
  160.      *----------------------------------------------------------------*
  161.            inquire hoja1   @cells::@item(1 1) = hrange.
  162.            modify  hrange  @value = "EJEMPLO ACUCOBOL - EXCEL".
  163.            destroy hrange.
  164.      *----------------------------------------------------------------*
  165.      *Combinar y Centrar el Titulo en Hoja 1
  166.            inquire hoja1   @Range("A1:F1") = hrange.
  167.            modify  hrange  @AutoFormat = xlRangeAutoFormatSimple.
  168.            modify  hrange  @Font::Size = 20.
  169.            modify  hrange  @Font::ColorIndex = 5.
  170.            destroy hrange.
  171.      *----------------------------------------------------------------*
  172.      *                   Subtitulos en Hoja 1                         *
  173.      *----------------------------------------------------------------*
  174.            inquire hoja1   @cells::@item(2 1) = hrange.
  175.            modify  hrange  @value = "Numero".
  176.            destroy hrange.
  177.            inquire hoja1   @cells::@item(2 2) = hrange.
  178.            modify  hrange  @value = "Apellido y Nombre".
  179.            destroy hrange.
  180.            inquire hoja1   @cells::@item(2 3) = hrange.
  181.            modify  hrange  @value = "Fecha".
  182.            destroy hrange.
  183.            inquire hoja1   @cells::@item(2 4) = hrange.
  184.            modify  hrange  @value = "Hora".
  185.            destroy hrange.
  186.            inquire hoja1   @cells::@item(2 5) = hrange.
  187.            modify  hrange  @value = "Hora".
  188.            destroy hrange.
  189.            inquire hoja1   @cells::@item(2 6) = hrange.
  190.            modify  hrange  @value = "Importe".
  191.            destroy hrange.
  192.      *----------------------------------------------------------------*
  193.      *Formato subtitulo hoja 1
  194.            inquire hoja1   @Range("A2:F2") = hrange.
  195.            modify  hrange  @AutoFormat =xlRangeAutoFormat3DEffects2.
  196.            modify  hrange  @Font::Size = 12.
  197.            modify  hrange  @Font::ColorIndex = 5.
  198.            destroy hrange.
  199.      *----------------------------------------------------------------*
  200.      *                   Subtitulos en Hoja 2                         *
  201.      *----------------------------------------------------------------*
  202.            inquire hoja2   @cells::@item(2 1) = hrange.
  203.            modify  hrange  @value = "Numero".
  204.            destroy hrange.
  205.            inquire hoja2   @cells::@item(2 2) = hrange.
  206.            modify  hrange  @value = "Apellido y Nombre".
  207.            destroy hrange.
  208.            inquire hoja2   @cells::@item(2 3) = hrange.
  209.            modify  hrange  @value = "Fecha".
  210.            destroy hrange.
  211.            inquire hoja2   @cells::@item(2 4) = hrange.
  212.            modify  hrange  @value = "Hora".
  213.            destroy hrange.
  214.            inquire hoja2   @cells::@item(2 5) = hrange.
  215.            modify  hrange  @value = "Hora".
  216.            destroy hrange.
  217.            inquire hoja2   @cells::@item(2 6) = hrange.
  218.            modify  hrange  @value = "Importe".
  219.            destroy hrange.
  220.      *----------------------------------------------------------------*
  221.      *Formato subtitulo hoja 2
  222.            inquire hoja2   @Range("A2:F2") = hrange.
  223.            modify  hrange  @AutoFormat =xlRangeAutoFormat3DEffects2.
  224.            modify  hrange  @Font::Size = 10.
  225.            modify  hrange  @Font::ColorIndex = 7.
  226.            destroy hrange.
  227.      *----------------------------------------------------------------*
  228.      *Formato de la Celda Hora en hoja 1
  229.            modify hoja1 @Range("D:D")::NumberFormat = ("hh:mm:ss").
  230.      *----------------------------------------------------------------*
  231.      *Formato de la Celda Hora en hoja 1
  232.            modify hoja1 @range("E:E")::NumberFormat = ("[h]:mm:ss").
  233.      *----------------------------------------------------------------*
  234.      *Formato de la Celda Importe en hoja 1
  235.            modify hoja1 @range("F:F")::NumberFormat = ("#.##0,00").
  236.      *----------------------------------------------------------------*
  237.  
  238.       *Coloco contador de linea en dos por los titulos
  239.            move 2 to wrow-n.
  240.  
  241.       *----------------------------------------------------------------*
  242.      * Cargo Variables Hoja 1
  243.            move 1234567890 to wnum.  move all "A"    to wape.
  244.            move 159357.25  to wimp.  move 12         to wmes.
  245.            move 20         to wdia.  move 2007       to wani.
  246.            move 10         to whh.   move 20         to wmm.
  247.            move 25         to wss.   move 120        to wwhh.
  248.            move 30         to wwmm.  move 20         to wwss.
  249.      *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  250.      *Contador
  251.            add 1 to wrow-n.
  252.      *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  253.            inquire hoja1   @cells::@item(wrow-n  1) = hrange.
  254.            modify  hrange  @value = wnum.
  255.            modify  hrange AddComment "Comentario".
  256.            destroy hrange.
  257.  
  258.            inquire hoja1   @cells::@item(wrow-n  2) = hrange.
  259.            modify  hrange  @value = wape.
  260.            destroy hrange.
  261.  
  262.            inquire hoja1   @cells::@item(wrow-n  3) = hrange.
  263.            modify  hrange  @value = wfecha.
  264.            destroy hrange.
  265.  
  266.            inquire hoja1   @cells::@item(wrow-n  4) = hrange.
  267.            modify  hrange  @value = whora.
  268.            destroy hrange.
  269.  
  270.            inquire hoja1   @cells::@item(wrow-n  5) = hrange.
  271.            modify  hrange  @value = wwhora.
  272.            destroy hrange.
  273.  
  274.            inquire hoja1   @cells::@item(wrow-n  6) = hrange.
  275.            modify  hrange  @value = wimp.
  276.            destroy hrange.
  277.      *----------------------------------------------------------------*
  278.      * Cargo Variables Hoja 2
  279.            move 0987654321 to wnum. move all "B"    to wape.
  280.            move 124578.55  to wimp. move 10         to wmes.
  281.            move 15         to wdia. move 2006       to wani.
  282.            move 12         to whh.  move 30         to wmm.
  283.            move 22         to wss.  move 130        to wwhh.
  284.            move 22         to wwmm. move 02         to wwss.
  285.      *----------------------------------------------------------------*
  286.            inquire hoja2   @cells::@item(wrow-n  1) = hrange.
  287.            modify  hrange  @value = wnum.
  288.            destroy hrange.
  289.  
  290.            inquire hoja2   @cells::@item(wrow-n  2) = hrange.
  291.            modify  hrange  @value = wape.
  292.            destroy hrange.
  293.  
  294.            inquire hoja2   @cells::@item(wrow-n  3) = hrange.
  295.            modify  hrange  @value = wfecha.
  296.            destroy hrange.
  297.  
  298.            inquire hoja2   @cells::@item(wrow-n  4) = hrange.
  299.            modify  hrange  @value = whora.
  300.            destroy hrange.
  301.  
  302.            inquire hoja2   @cells::@item(wrow-n  5) = hrange.
  303.            modify  hrange  @value = wwhora.
  304.            destroy hrange.
  305.  
  306.            inquire hoja2   @cells::@item(wrow-n  6) = hrange.
  307.            modify  hrange  @value = wimp.
  308.            destroy hrange.
  309.      *----------------------------------------------------------------*
  310.      *Ejemplo Suma en la celda B5 la Columna F
  311.            modify hexcelapp @Range("B5")::Formula = "=SUM(F:F)".
  312.      *----------------------------------------------------------------*
  313.  
  314.       *----------------------------------------------------------------*
  315.      *Borde Hoja 1 ----> (ColRow)
  316.            move " A"  to wcol-l.
  317.            move 6     to wcol-n.
  318.            move " F"  to wrow-l.
  319.  
  320.            inquire hoja1  @Range(ColRow) = hrange.
  321.            modify  hrange @Borders::LineStyle = xlContinuous
  322.                           @Borders::Weight    = xlMedium
  323.                           @Borders::Colorindex = 46
  324.  
  325.            modify  hrange @Font::Size = 8.
  326.        destroy hrange.
  327.      *----------------------------------------------------------------*
  328.      *    inquire hoja1   @Range("A7:F7") = hrange.
  329.      *    modify  hrange  @AutoFormat = xlRangeAutoformatSimple
  330.      *    modify  hrange  @Font::Size = 12.
  331.      *    modify  hrange  @Font::ColorIndex = 5.
  332.      *    destroy hrange.
  333.      *----------------------------------------------------------------*
  334.      *Activo Hoja 1
  335.            modify  hoja1  @Activate = ().
  336.      *----------------------------------------------------------------*
  337.            move 0   to wRightMargin.
  338.            move 0   to wTopMargin.
  339.            move 0   to wHeaderMargin.
  340.            move 60  to wBottomMargin.
  341.            move 10  to wLeftMargin.
  342.            move 0   to wFooterMargin.
  343.      *-----------------  Hoja 1 ---------------------------------------*
  344.      *Parametros Area de Impresion (PrintArea = ColRow)
  345.            move " A"  to wcol-l.
  346.            move 1     to wcol-n.
  347.            move " F"  to wrow-l.
  348.      *----------------------------------------------------------------*
  349.            modify  hoja1
  350.      *Imprime Hoja 1 Orientacion Horinzontal
  351.              PageSetup::Orientation = xlLandscape
  352.      *Configuro los Margenes
  353.              PageSetup::LeftMargin   wLeftMargin
  354.              PageSetup::RightMargin  wRightMargin
  355.              PageSetup::TopMargin    wTopMargin
  356.              PageSetup::BottomMargin wBottomMargin
  357.              PageSetup::HeaderMargin wHeaderMargin
  358.              PageSetup::FooterMargin wFooterMargin
  359.      *Activo Tama¤o del Papel Oficio hoja 1
  360.      *      PageSetup::PaperSize    xlPaperLegal
  361.      *Activo Titulos
  362.              PageSetup::PrintTitleRows("1:2")
  363.      *Activo Fecha y Numero de Pagina
  364.              PageSetup::LeftFooter("&F")
  365.              PageSetup::RightFooter("&P de &#")
  366.      *Ajuste de Escala
  367.              PageSetup::Zoom = 100
  368.      *Area de Impresion
  369.               PageSetup::PrintArea = ColRow.
  370.      *----------------------------------------------------------------*
  371.      *Activo Imprimir
  372.      *      modify  hoja1 printout().
  373.      *----------------------------------------------------------------*
  374.  
  375.       *----------------------------------------------------------------*
  376.      *Activo Hoja 2
  377.            modify  hoja2  @Activate = ().
  378.      *----------------------------------------------------------------*
  379.      *Borde Hoja 2 ----> (ColRow)
  380.            move " A"  to wcol-l.
  381.            move 2     to wcol-n.
  382.            move " F"  to wrow-l.
  383.  
  384.            inquire hoja2  @Range(ColRow) = hrange.
  385.            modify  hrange @Borders::LineStyle = xlEdgeLeft.
  386.            modify  hrange @Font::Size = 8.
  387.        destroy hrange.
  388.      *-----------------  Hoja 2 ---------------------------------------*
  389.      *Parametros Area de Impresion (PrintArea = ColRow)
  390.            move " A"  to wcol-l.
  391.            move 1     to wcol-n.
  392.            move " F"  to wrow-l.
  393.      *----------------------------------------------------------------*
  394.            modify hoja2
  395.                   PageSetup::Orientation = xlLandscape
  396.                   PageSetup::LeftMargin    wLeftMargin
  397.                   PageSetup::RightMargin   wRightMargin
  398.                   PageSetup::TopMargin     wTopMargin
  399.                   PageSetup::BottomMargin  wBottomMargin
  400.                   PageSetup::HeaderMargin  wHeaderMargin
  401.                   PageSetup::FooterMargin  wFooterMargin
  402.      *           PageSetup::PaperSize     xlPaperLegal
  403.                   PageSetup::PrintTitleRows("1:2")
  404.                   PageSetup::LeftFooter("&F")
  405.                   PageSetup::RightFooter("&P")
  406.                   PageSetup::Zoom = 90
  407.                   PageSetup::PrintArea   = ColRow.
  408.      *----------------------------------------------------------------*
  409.      *      modify  hoja2 printout().
  410.      *----------------------------------------------------------------*
  411.      *Ajustar a la seleccion Hoja 1
  412.            inquire hoja1 @Range("A:AF") = hrange.
  413.            modify  hrange Columns::AutoFit().
  414.      *----------------------------------------------------------------*
  415.      *Ajustar a la seleccion Hoja 2
  416.            inquire hoja2 @Range("A:AF") = hrange.
  417.            modify  hrange Columns::AutoFit().
  418.      *----------------------------------------------------------------*
  419.      *Activo Hoja 1
  420.            modify  hoja1  @Activate = ().
  421.      *----------------------------------------------------------------*
  422.      *Muestro Excel
  423.            modify hexcelapp @Visible = 1.
  424.      *----------------------------------------------------------------*
  425.      *FIN PROGRAMA,
  426.            destroy hoja2.
  427.            destroy hoja1.
  428.      *     modify  hexcelwkb   @close(0).
  429.        destroy hexcelwkb.
  430.      *     modify  hexcelapp   @quit().
  431.        destroy hexcelapp.
  432.      *----------------------------------------------------------------*
  433.            STOP RUN.



Post añadido a las 15:51. Post anterior a las 15:50


@Roberto, Espero que sirva.

Última edición por Gusaiello fecha: 25 de marzo de 2026 a las 19:51. Razón: Completar
Gusaiello is offline   Responder Con Cita