How create two worksheets in code xml

Posted by Elena_Perello on 16-Mar-2011 02:59

Hi,

I need to create an xml with two worksheets and do not know how, I do it with one but not more.

I use this code:

PROCEDURE ex_crear:
        /*creamos los nodos comunes*/
        DEFINE INPUT PARAMETER workSheetName  AS CHARACTER NO-UNDO. /*Nombre de la hoja*/
        DEFINE INPUT PARAMETER workSheetStyle AS CHARACTER NO-UNDO. /*Nombre del estilo de la hoja*/
       
        CREATE X-NODEREF  hXpi.
        CREATE X-NODEREF  hXworkbook.
        CREATE X-NODEREF  hXstyles.
        CREATE X-NODEREF  hXstyle.
        CREATE X-NODEREF  hXfont.
        CREATE X-NODEREF  hXworksheet.
        CREATE X-NODEREF  hXtable.
        CREATE X-NODEREF  hXrow.
        CREATE X-NODEREF  hXcell.
        CREATE X-NODEREF  hXdata.
        CREATE X-NODEREF  hXtext.
        CREATE X-NODEREF  hXborders.
        CREATE X-NODEREF  hXborder.
        CREATE X-NODEREF  hXinterior.
        CREATE X-NODEREF  hXNumberFormat.
       

        hXdoc:ENCODING = "UTF-8".

        hXdoc:CREATE-NODE(hXpi,'mso-application',"processing-instruction").
        hXpi:NODE-VALUE = 'progid="Excel.Sheet"'.

        hXdoc:APPEND-CHILD(hXpi).
 
        /* Creamos el workbook */
 
        hXdoc:CREATE-NODE(hXworkbook,"Workbook","element").
 
        hXworkbook:SET-ATTRIBUTE("xmlns:html","http://www.w3.org/TR/REC-html40").
        hXworkbook:SET-ATTRIBUTE("xmlns:o","urn:schemas-microsoft-com:office:office").
        hXworkbook:SET-ATTRIBUTE("xmlns:x","urn:schemas-microsoft-com:office:excel").
        hXworkbook:SET-ATTRIBUTE("xmlns:ss","urn:schemas-microsoft-com:office:spreadsheet").
        hXworkbook:SET-ATTRIBUTE("xmlns","urn:schemas-microsoft-com:office:spreadsheet").
        /*incluimos los estilos*/
       
        /*definimos la etiqueta Styles*/
         hXdoc:CREATE-NODE(hXstyles,"Styles","element").
       
        /*llamamos al procedure interno ex_style tantas veces
                    como estilos queramos crear               */
        RUN ex_style("cuadro",YES,NO ,NO ,?        ,?        ).
        RUN ex_style("negrita",NO ,YES,NO ,?        ,?        ).
        RUN ex_style("cursiva",NO ,NO ,YES,?        ,?        ).
        RUN ex_style("fondo-rojo",NO ,NO ,NO ,"#FF0000",?        ).
        RUN ex_style("fondo-gris",NO ,NO ,NO ,"#969696",?        ).
        RUN ex_style("fuente-roja",NO ,NO ,NO ,?        ,"#FF0000").
        RUN ex_style("fuente-blanca",NO ,NO ,NO ,?        ,"#FFFFFF").
        RUN ex_style("fuente-azul",NO ,YES ,NO ,?,"#0000B3").
        RUN ex_style("cabecera",YES ,YES,YES ,"#0000B3","#FFFFFF").
        RUN ex_style("cabecerasincuadro",NO ,YES,YES ,"#0000B3","#FFFFFF").
        RUN ex_style("cuadronegrita",YES,YES,NO ,?        ,?        ).
        RUN ex_style("cuadronegcur",YES,YES,YES ,?        ,?        ).
        RUN ex_style("negritacur",NO,YES,YES ,?        ,?        ).
       

        /*añadimos todos los estilos una vez creados*/
         hXworkbook:APPEND-CHILD(hXstyles).

        /*creamos la hoja */
        hXdoc:CREATE-NODE(hXworksheet,"Worksheet","element").
        hXworkSheet:SET-ATTRIBUTE("ss:Name",workSheetName).

        /*creamos la tabla*/
        hXdoc:CREATE-NODE(hXtable,"Table","element").

        IF workSheetStyle NE ? THEN
            hXtable:SET-ATTRIBUTE("ss:StyleID",STRING(workSheetStyle)).

END PROCEDURE.


All Replies

Posted by Thomas Mercer-Hursh on 16-Mar-2011 11:33

This isn't really an OpenEdge Architect question, but rather an ABL question.

Have you checked out Alon Blich's OpenXML tools at OE Hive http://www.oehive.org/project/lib

Posted by Admin on 17-Mar-2011 16:32

Hello Elena,

Sure. You can create Excel and Word XML files (.xlsx and .docx files)

I'd be happy to give you a presentation and answer any questions you might have.

Here's a link to the project home page

http://www.oehive.org/project/libooxml

Please download the test drive version and try the samples.

- Alon

+972-54-2188086

This thread is closed