*&---------------------------------------------------------------------*
*&  Include           ZDEV_XML
*&---------------------------------------------------------------------*
*legend
*
*
*l - left
*r - right
* - center
*j - justify
*
*
*00 - size
*
*- - no bold
*B- Bold
*- -  no italic
*I - Italic
*- - no Underline
*U - underline
*
*- no border
*R - Border
*
*-------- no color
*D8D8D8 color
*-    no rotate
*X   rotate 90
*l11B_UR80FF80X   left size 11 bold underline fon lime rotate 90



*  FIND FIRST OCCURRENCE OF '-' IN utf_out.
*  IF sy-subrc = 0.
*    TRANSLATE utf_out USING '- '.
*    CONDENSE  utf_out NO-GAPS.
*    CONCATENATE '-' utf_out INTO utf_out.
*  ENDIF.
*  CONDENSE  utf_out NO-GAPS.

DATA: t_xml_file TYPE string OCCURS 0 WITH HEADER LINE,
      t_style    TYPE string OCCURS 0 WITH HEADER LINE,
      t_xml_header  TYPE string OCCURS 0 WITH HEADER LINE,
      t_style_b  TYPE string OCCURS 0 WITH HEADER LINE,
      lv_str_xml type string,
      _v_filename type string.

DATA: v_dirname TYPE string,
      v_filename TYPE string,
      k TYPE i,
      s(32),
      n(17),
      ind(2),
      ind1(2),
      str TYPE string,
      alignment(7) TYPE c,
      size(2) TYPE n,
      bold TYPE c,
      italic TYPE c,
      underline(6) TYPE c,
      frame TYPE c,
      color(6) TYPE c,
      rotate(20) TYPE c,
      lv_xstring type xstring.

  data
        : lv_ful_path type string
        , lv_USER_ACTION type i
        , lv_file_name type string
        .

data
  len type i.

DEFINE xml_numeric.
  CONDENSE &1.
  len = STRLEN( &1 ) - 1.
  if &1+len(1) = '-'.
    REPLACE '-' in &1 WITH ''.
    CONCATENATE '-' &1 into &1.
  ENDIF.
END-OF-DEFINITION.

*   XML


DEFINE xml_header.
  refresh t_xml_file.
*  
  t_xml_header = '<?xml version="1.0" encoding="Windows-1251"?>'.
  append t_xml_header.
  t_xml_header = '<?mso-application progid="Excel.Sheet"?>'.
  append t_xml_header.
  t_xml_header = '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"'.
  append t_xml_header.
  t_xml_header = 'xmlns:x="urn:schemas-microsoft-com:office:excel">'.
  append t_xml_header.

*   
  t_xml_header = '<Styles>'.
  append t_xml_header.

** : Arial, :   , :8, : , : 
*  t_xml_file = '<Style ss:ID="l8nw">'.
*  append t_xml_file.
*  t_xml_file = '<Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:WrapText="1"/>'.
*  append t_xml_file.
*  t_xml_file = '<Borders/>'.
*  append t_xml_file.
*  t_xml_file = '<Font ss:FontName="Arial Cyr" x:CharSet="204" ss:Size="8" ss:Bold="0"/>'.
*  append t_xml_file.
*  t_xml_file = '</Style>'.
*  append t_xml_file.
*
*  t_xml_file = '<Style ss:ID="l8n">'.
*  append t_xml_file.
*  t_xml_file = '<Alignment ss:Horizontal="Left" ss:Vertical="Center"/> '.
*  append t_xml_file.
*  t_xml_file = '<Borders/>'.
*  append t_xml_file.
*  t_xml_file = '<Font ss:FontName="Arial Cyr" x:CharSet="204" ss:Size="8" ss:Bold="0"/>'.
*  append t_xml_file.
*  t_xml_file = '</Style>'.
*  append t_xml_file.

END-OF-DEFINITION.
DEFINE xml_download .
  v_dirname = &1.
  v_filename = &2.

  t_style = '</Styles>'.
  append t_style.
  append lines of t_style to t_xml_header.

  t_xml_file = '</Workbook>'.
  append t_xml_file.

  append lines of t_xml_file to t_xml_header.

*  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_SAPGUI_DIRECTORY
*    CHANGING
*      SAPGUI_DIRECTORY = V_DIRNAME.


  call method cl_gui_frontend_services=>directory_exist
    exporting
      directory = v_dirname
    receiving
      result    = s.

  if s eq space.
    call method cl_gui_frontend_services=>directory_create
      exporting
        directory = v_dirname
      changing
        rc        = k.
  endif.

  if k ne space.
    message 'Directory not created!' type 'S'.
    stop.
  endif.

  concatenate v_dirname  v_filename into v_filename.
  replace all occurrences of '\' in v_filename with '/'.

  call function 'GUI_DOWNLOAD'
    exporting
      filename                = v_filename
    tables
      data_tab                = t_xml_header     " FILETYPE = 'ASK'
    exceptions
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      others                  = 22.
  if sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
    EXPORTING
        application = 'Excel'
        parameter   = v_filename
        operation   = 'OPEN'
    EXCEPTIONS
      CNTL_ERROR             = 1
      ERROR_NO_GUI           = 2
      BAD_PARAMETER          = 3
      FILE_NOT_FOUND         = 4
      PATH_NOT_FOUND         = 5
      FILE_EXTENSION_UNKNOWN = 6
      ERROR_EXECUTE_FAILED   = 7
      SYNCHRONOUS_FAILED     = 8
      NOT_SUPPORTED_BY_GUI   = 9
      others                 = 10
          .
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

*  call method cl_gui_frontend_services=>execute
*    exporting
*      application = 'Excel'
*      parameter   = v_filename
*      operation   = 'OPEN'.     " SYNCHRONOUS = 'X'

*  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_DELETE
*    EXPORTING
*      FILENAME = V_FILENAME
*    CHANGING
*      RC       = K.

END-OF-DEFINITION.

DEFINE xml_translate.

  CALL FUNCTION 'TREX_TEXT_TO_UTF8'
    EXPORTING
      text                   = &1
   IMPORTING
     BUFFER                 = lv_xstring
*   EXCEPTIONS
*     CONVERSION_ERROR       = 1
*     OTHERS                 = 2
            .
  lv_xstring = &1.

  CALL FUNCTION 'CRM_IC_XML_XSTRING2STRING'
    EXPORTING
      inxstring       = lv_xstring
   IMPORTING
     OUTSTRING       = &1
            .



END-OF-DEFINITION.

define xml_download2 .
  v_dirname = &1.
  v_filename = &2.

*  t_style = '</Styles>'.
*  append t_style.
*  append lines of t_style to t_xml_header.
*
*  t_xml_file = '</Workbook>'.
*  append t_xml_file.

  append lines of t_xml_file to t_xml_header.

*  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_SAPGUI_DIRECTORY
*    CHANGING
*      SAPGUI_DIRECTORY = V_DIRNAME.


  call method cl_gui_frontend_services=>directory_exist
    exporting
      directory = v_dirname
    receiving
      result    = s.

  if s eq space.
    call method cl_gui_frontend_services=>directory_create
      exporting
        directory = v_dirname
      changing
        rc        = k.
  endif.

  if k ne space.
    message 'Directory not created!' type 'S'.
    stop.
  endif.

  concatenate v_dirname  v_filename into v_filename.
  replace all occurrences of '\' in v_filename with '/'.

  call function 'GUI_DOWNLOAD'
    exporting
      filename                = v_filename
    tables
      data_tab                = t_xml_header     " FILETYPE = 'ASK'
    exceptions
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      others                  = 22.
  if sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.


  CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
    EXPORTING
        application = 'Excel'
        parameter   = v_filename
        operation   = 'OPEN'
    EXCEPTIONS
      CNTL_ERROR             = 1
      ERROR_NO_GUI           = 2
      BAD_PARAMETER          = 3
      FILE_NOT_FOUND         = 4
      PATH_NOT_FOUND         = 5
      FILE_EXTENSION_UNKNOWN = 6
      ERROR_EXECUTE_FAILED   = 7
      SYNCHRONOUS_FAILED     = 8
      NOT_SUPPORTED_BY_GUI   = 9
      others                 = 10
          .
  IF SY-SUBRC <> 0.
*    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.   " SYNCHRONOUS = 'X'

*  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_DELETE
*    EXPORTING
*      FILENAME = V_FILENAME
*    CHANGING
*      RC       = K.

end-of-definition.



*  
DEFINE xml_open_worksheet.
  concatenate '<Worksheet ss:Name="' &1 '"> <Table>' into t_xml_file.
  append t_xml_file.
END-OF-DEFINITION.


define xml_simple.
  t_xml_file = &1.
  append t_xml_file.
end-of-definition.

*  
DEFINE xml_close_worksheet.
  t_xml_file = '</Table>'.
  append t_xml_file.
  t_xml_file =  '<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">'.
  append t_xml_file.
  if &1 = 'X'.
    t_xml_file =  '<PageSetup><Layout x:Orientation="Landscape"/></PageSetup>'.
    append t_xml_file.
  else.
    t_xml_file =  '<PageSetup><Layout x:Orientation="Portrait"/></PageSetup>'.
    append t_xml_file.
  endif.
  concatenate '<Zoom>' &2 '</Zoom>' into t_xml_file.
  append t_xml_file.
  concatenate '<Print><Scale>' &3 '</Scale></Print>' into t_xml_file.
  append t_xml_file.
  t_xml_file = '</WorksheetOptions></Worksheet>'.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_column.
  t_xml_file =  &1.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_columnwidth.
  n = &1.
  shift n left deleting leading space.
  concatenate '<Column ss:AutoFitWidth="0" ss:Width="' n '"/>' into t_xml_file.
  append t_xml_file.
END-OF-DEFINITION.

define xml_columnwidthindex.
  n = &1.
  shift n left deleting leading space.
  concatenate '<Column ss:Index="' &2 '" ss:AutoFitWidth="0" ss:Width="' n '"/>' into t_xml_file.
  "concatenate '<Column ss:AutoFitWidth="0" ss:Width="' n '"/>' into t_xml_file.
  append t_xml_file.
end-of-definition.

define xml_columnwidthindexspan.
  n = &1.
  shift n left deleting leading space.
  concatenate '<Column ss:Index="' &2 '" ss:AutoFitWidth="0" ss:Width="' &1 '" ss:Span="' &3'"/>' into t_xml_file.
  append t_xml_file.
end-of-definition.

DEFINE xml_blanck_row.
  xml_beginrow ''.
  xml_endrow.
END-OF-DEFINITION.

DEFINE xml_beginrow.
  if &1 = 'X'.
    t_xml_file = '<Row ss:AutoFitHeight="0">'.
  else.
    t_xml_file = '<Row>'.
  endif.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_beginrowheight.
  n = &2.
  if &1 = 'X'.
    t_xml_file =  '<Row ss:AutoFitHeight="0">'.
  else.
    concatenate '<Row ss:Height="' n '">' into t_xml_file.
*    t_xml_file = '<Row >'.
  endif.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_beginrowindex.
  ind = &2.
  if &1 = 'X'.
    concatenate '<Row ss:Index="' ind '" ss:AutoFitHeight="0">' into t_xml_file.
  else.
    concatenate '<Row ss:Index="' ind '">' into t_xml_file.
  endif.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_endrow.
  t_xml_file = '</Row>'.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_writecellindex.
  perform xml_style using &2.
  ind = &1.
  case &3.
    when 'N' or 'n'.
      n = abs( &4 ).
      shift n left deleting leading space.
      if &4 < 0.
        concatenate '-'  n into n.
      endif.
      concatenate '<Cell ss:Index="' ind '" ss:StyleID="' &2 '"><ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">' n '</ss:Data></Cell>' into t_xml_file.
    when others.
      str = &4.
      concatenate '<Cell ss:Index="' ind '" ss:StyleID="' &2 '"><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">' str '</ss:Data></Cell>' into t_xml_file.
  endcase.
  append t_xml_file.
END-OF-DEFINITION.

*&---------------------------------------------------------------------*
DEFINE xml_writecell.
  perform xml_style using &1.
  case &2.
    when 'N' or 'n'.
      n = abs( &3 ).
      shift n left deleting leading space.
      if &3 < 0.
        concatenate '-'  n into n.
      endif.
      concatenate '<Cell ss:StyleID="' &1 '"><ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">' n '</ss:Data></Cell>' into t_xml_file.
    when others.
      str = &3.
      concatenate '<Cell ss:StyleID="' &1 '"><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">' str '</ss:Data></Cell>' into t_xml_file.
  endcase.
  append t_xml_file.
END-OF-DEFINITION.
*&---------------------------------------------------------------------*
DEFINE xml_writemergeacross.
  ind = &1.
  perform xml_style using &2.
  case &3.
    when 'N' or 'n'.
      n = &4.
      shift n left deleting leading space.
      concatenate '<Cell ss:MergeAcross="' ind '" ss:StyleID="' &2 '"><ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">' n '</ss:Data></Cell>' into t_xml_file.
    when others.
      str = &4.
      concatenate '<Cell ss:MergeAcross="' ind '" ss:StyleID="' &2 '"><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">' str '</ss:Data></Cell>' into t_xml_file.
  endcase.
  append t_xml_file.
END-OF-DEFINITION.

*&---------------------------------------------------------------------*
DEFINE xml_writemergedown.
  ind = &1.
  perform xml_style using &2.
  case &3.
    when 'N' or 'n'.
      n = &4.
      shift n left deleting leading space.
      concatenate '<Cell ss:MergeDown="' ind '" ss:StyleID="' &2 '"><ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">' n '</ss:Data></Cell>' into t_xml_file.
    when others.
      str = &4.
      concatenate '<Cell ss:MergeDown="' ind '" ss:StyleID="' &2 '"><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">' str '</ss:Data></Cell>' into t_xml_file.
  endcase.
  append t_xml_file.
END-OF-DEFINITION.

*&---------------------------------------------------------------------*
DEFINE xml_writemergeacrossdown.
  ind = &1.
  ind1 = &2.
  perform xml_style using &3.
  case &4.
    when 'N' or 'n'.
      n = &5.
      shift n left deleting leading space.
      concatenate '<Cell  ss:MergeAcross="' ind '"  ss:MergeDown="' ind1 '" ss:StyleID="' &3 '"><ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">' n '</ss:Data></Cell>' into t_xml_file.
    when others.
      str = &5.
      concatenate '<Cell  ss:MergeAcross="' ind '" ss:MergeDown="' ind1 '" ss:StyleID="' &3 '"><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">' str '</ss:Data></Cell>' into t_xml_file.
  endcase.
  append t_xml_file.
END-OF-DEFINITION.

*&---------------------------------------------------------------------*
DEFINE xml_writemergeindexacross.
  ind = &1.
  ind1 = &2.
  perform xml_style using &3.
  case &4.
    when 'N' or 'n'.
      n = &5.
      shift n left deleting leading space.
      concatenate '<Cell ss:Index="' ind '" ss:MergeAcross="' ind1 '"  ss:StyleID="' &3 '"><ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">' n '</ss:Data></Cell>' into t_xml_file.
    when others.
      str = &5.
      concatenate '<Cell ss:Index="' ind '"  ss:MergeAcross="' ind1 '"  ss:StyleID="' &3 '"><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">' str '</ss:Data></Cell>' into t_xml_file.
  endcase.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_writemergeindexdown.
  ind = &1.
  ind1 = &2.
  perform xml_style using &3.
  case &4.
    when 'N' or 'n'.
      n = &5.
      shift n left deleting leading space.
      concatenate '<Cell ss:Index="' ind '" ss:MergeDown="' ind1 '"  ss:StyleID="' &3 '"><ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">' n '</ss:Data></Cell>' into t_xml_file.
    when others.
      str = &5.
      concatenate '<Cell ss:Index="' ind '"  ss:MergeDown="' ind1 '"  ss:StyleID="' &3 '"><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">' str '</ss:Data></Cell>' into t_xml_file.
  endcase.
  append t_xml_file.
END-OF-DEFINITION.



DEFINE xml_close_worksheet_only.
  t_xml_file = '</Worksheet>'.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_close_worksheet_to_options.
  t_xml_file = '</Table>'.
  append t_xml_file.
  t_xml_file =  '<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">'.
  append t_xml_file.
  if &1 = 'X'.
    t_xml_file =  '<PageSetup><Layout x:Orientation="Landscape"/></PageSetup>'.
    append t_xml_file.
  else.
    t_xml_file =  '<PageSetup><Layout x:Orientation="Portrait"/></PageSetup>'.
    append t_xml_file.
  endif.
  concatenate '<Zoom>' &2 '</Zoom>' into t_xml_file.
  append t_xml_file.
  concatenate '<Print><Scale>' &3 '</Scale></Print>' into t_xml_file.
  append t_xml_file.
  t_xml_file = '</WorksheetOptions>'."</Worksheet>'.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_open_pagebreaks.
  t_xml_file = '<PageBreaks xmlns="urn:schemas-microsoft-com:office:excel">'.
  append t_xml_file.
  t_xml_file =  '<RowBreaks>'.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_close_pagebreaks.
  t_xml_file = '</RowBreaks>'.
  append t_xml_file.
  t_xml_file =  '</PageBreaks> '.
  append t_xml_file.
END-OF-DEFINITION.

DEFINE xml_add_pagebreak.
  t_xml_file = '<RowBreak>'.
  append t_xml_file.
  concatenate '<Row>' &1 '</Row>' into t_xml_file.
  append t_xml_file.
  t_xml_file = '</RowBreak>'.
  append t_xml_file.
END-OF-DEFINITION.

initialization.

  CLEAR t_xml_file.
  REFRESH t_xml_file.
  CLEAR t_style.
  REFRESH t_style.
  CLEAR t_style_b.
  REFRESH t_style_b.
  CLEAR t_xml_header.
  REFRESH t_xml_header.

*&---------------------------------------------------------------------*
*&      Form  xml_style
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->STYLE      text
*----------------------------------------------------------------------*
FORM xml_style USING style TYPE c.
  DATA: length TYPE i.

  READ TABLE t_style_b WITH KEY table_line = style TRANSPORTING NO FIELDS.
  IF sy-subrc <> 0.
    alignment = style+0(1).
    size = style+1(2).
    SHIFT size LEFT DELETING LEADING '0'.

    bold = style+3(1).
    italic = style+4(1).
    underline = style+5(1).
    frame = style+6(1).
    DESCRIBE FIELD style LENGTH length IN CHARACTER MODE.

    IF length > 12.
      color = style+7(6).
    ELSE.
      color = ''.
    ENDIF.

    IF length = 14.
      rotate = ' ss:Rotate="90"'.
    ELSE.
      rotate = ''.
    ENDIF.



    CASE alignment.
      WHEN 'L'.
        alignment = 'Left'.
      WHEN 'l'.
        alignment = 'Left'.
      WHEN 'R'.
        alignment = 'Right'.
      WHEN 'r'.
        alignment = 'Right'.
      WHEN 'C'.
        alignment = 'Center'.
      WHEN 'c'.
        alignment = 'Center'.
      WHEN OTHERS.
        alignment = 'Justify'.
    ENDCASE.

    IF bold = 'B' .
      bold = '1'.
    ELSE.
      bold ='0'.
    ENDIF.

    IF italic = 'I' .
      italic = '1'.
    ELSE.
      italic ='0'.
    ENDIF.

    IF underline = 'U' .
      underline = 'Single'.
    ELSE.
      underline ='0'.
    ENDIF.

    IF frame = 'R' .
      frame = '1'.
    ELSE.
      frame ='0'.
    ENDIF.


    APPEND style TO t_style_b.

    CONCATENATE '<Style ss:ID="' style '">' INTO t_style.
    APPEND t_style.
    CONCATENATE '<Alignment ss:Horizontal="' alignment  '" ss:Vertical="Center" ss:WrapText="1" ' INTO t_style.
    CONCATENATE t_style rotate ' />' INTO t_style SEPARATED BY space.
    APPEND t_style.

    IF  frame = '1' .
      t_style = '<Borders>'.
      APPEND t_style.
      t_style = '<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>'.
      APPEND t_style.
      t_style = '<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>'.
      APPEND t_style.
      t_style = '<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>'.
      APPEND t_style.
      t_style = '<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>'.
      APPEND t_style.
      t_style = '</Borders>'.
      APPEND t_style.
    ELSE.
      t_style = '<Borders/>'.
      APPEND t_style.
    ENDIF.

    IF color <> ''.
      CONCATENATE  '<Interior ss:Color="#' color '" ss:Pattern="Solid"/>' INTO t_style.
      APPEND t_style.
    ENDIF.

    CONCATENATE '<Font ss:FontName="Arial Cyr" x:CharSet="204" ss:Size="' size '" ss:Bold="' bold '" ss:Italic="' italic '" ' INTO t_style.
    IF underline <> '0'.
      CONCATENATE t_style 'ss:Underline="'  INTO t_style SEPARATED BY space.
      CONCATENATE t_style  underline '"/>' INTO t_style .
    ELSE.
      CONCATENATE t_style  '/>' INTO t_style SEPARATED BY space.
    ENDIF.
    APPEND t_style.
    t_style = '</Style>'.
    APPEND t_style.


  ENDIF.


ENDFORM. "xml_style

*&---------------------------------------------------------------------*
*&      Form  out_to_xml1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM out_to_xml_test .


  DATA:  lv_str TYPE string,
        _v_filename TYPE string.


  xml_header.

  xml_open_worksheet ''.
  xml_columnwidth '300'.
  xml_columnwidth '80'.
  xml_columnwidth '80'.
  xml_columnwidth '80'.
  xml_columnwidth '80'.
  xml_columnwidth '80'.
  xml_columnwidth '80'.


  xml_beginrowheight '' '20'.
  xml_writecell  'l11B_UR80FF80'  's' '    '.
*  xml_endrow.
*  xml_beginrowheight '' '20'.
  xml_writemergeacross 2 'l11B_UR80FF80' 's' ''.
  xml_endrow.

  CONCATENATE '  "  " '   '' INTO lv_str SEPARATED BY space.

  xml_beginrowheight '' '20'.
  xml_writecell  'l11B_UR80FF80' 's' lv_str.
  xml_writecell 'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' ''.
  xml_writemergeacross 2 'l11B_UR80FF80' 's' ' '.

  xml_endrow.



  CONCATENATE '  '    '' INTO lv_str SEPARATED BY space.

  xml_beginrowheight '' '20'.
  xml_writecell  'l11B_UR80FF80' 's' lv_str.
  xml_writecell 'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' ''.
  xml_writemergeacross 2 'l11B_UR80FF80' 's' '__________________..'.

  xml_endrow.

  xml_beginrowheight '' '20'.
  xml_writecellindex 1 'l11B_UR80FF80' 's' '(   4 )'.
  xml_endrow.

*  xml_beginrow ''.
*  xml_endrow.



  xml_beginrow ''.
  xml_writecellindex 1 'l11-_--FF0000' 's' ''.
  xml_writecellindex 2 'r18-_--FF0000' 's' ' .'.
  xml_writecellindex 3 'c11-_-R80FF80' 's' ' '.
  xml_writecellindex 4 'j11B_UR80FF80' 's' ''.
  xml_writecellindex 5 'l01B_UR80FF80' 's' ''.
  xml_writecellindex 6 'l11B_UR80FF80' 's' '% '.
  xml_writecellindex 7 'l11B_UR80FF80' 's' '.'.
  xml_endrow.


  xml_beginrow ''.
  xml_endrow.

  xml_beginrow ''.
  xml_writecellindex 3 'l11B_UR80FF80' 's' ''.
  xml_writecellindex 4 'l11B_UR80FF80' 's' ''.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell    'l11B_UR80FF80' 's' ' '.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.
  xml_endrow.

  xml_beginrow ''.
  xml_endrow.

  xml_beginrow ''.
  xml_writecellindex 3 'l11B_UR80FF80' 's' ''.
  xml_writecellindex 4 'l11B_UR80FF80' 's' ''.
  xml_writecellindex 5 'l11B_UR80FF80' 's' ''.
  xml_writecellindex 6 'l11B_UR80FF80' 's' ''.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell    'l11B_UR80FF80' 's' ' '.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' ' '.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' '  '.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.
  xml_endrow.

  xml_beginrow ''.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell  'l11B_UR80FF80' 's' '  '.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' '   '.
  xml_writecell    'l11B_UR80FF80' 's' ''.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.
  xml_endrow.


  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' ' '.
  xml_writecell    'l11B_UR80FF80' 's' ''.

  xml_writecell    'l11B_UR80FF80' 'n' '123'.
  xml_endrow.

  xml_beginrow ''.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writemergeacross 2 'l11B_UR80FF80' 's' '. -'.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writemergeacross 2 'l11B_UR80FF80' 's' ' '.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell 'r8___RFF0000' 's' ' ..'.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writemergeacross 2 'l11B_UR80FF80' 's' '    '.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' ' ..'.
  xml_endrow.

  xml_beginrow ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writemergeacross 2 'l11B_UR80FF80' 's' '  '.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell    'l11B_UR80FF80' 's' ''.
  xml_writecell 'l11B_UR80FF80' 's' ' ..'.
  xml_endrow.

  xml_close_worksheet 'X' '80' '67'.
  CONCATENATE 'REP_DC_' sy-datum sy-uzeit '.xml' INTO _v_filename.
  xml_download 'C:\Temp\' _v_filename.

ENDFORM. " OUT_TO_XML1

defINE xml_download4.

  data
        : lv_ful_path4 type string
        , lv_USER_ACTION4 type i
*        , lv_file_name4 type string
        .

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    EXPORTING
      WINDOW_TITLE         =  ' '
      DEFAULT_EXTENSION    =  '*.xml'
      DEFAULT_FILE_NAME    =  '.xml'
*      WITH_ENCODING        =
      FILE_FILTER          = ' XML";" (*.xml)|*.xml'
*      INITIAL_DIRECTORY    =
*      PROMPT_ON_OVERWRITE  = 'X'
    CHANGING
      FILENAME             = v_filename
      PATH                 =  v_dirname
      FULLPATH             = lv_ful_path4
      USER_ACTION          = lv_USER_ACTION4
*      FILE_ENCODING        =
    EXCEPTIONS
      CNTL_ERROR           = 1
      ERROR_NO_GUI         = 2
      NOT_SUPPORTED_BY_GUI = 3
      others               = 4
          .
  IF SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  if lv_USER_ACTION4 ne 0.
    exit.
  endif.
*  v_dirname = &1.
*  v_filename = &2.

*  t_style = '</Styles>'.
*  append t_style.
*  append lines of t_style to t_xml_header.
*
*  t_xml_file = '</Workbook>'.
*  append t_xml_file.

  append lines of t_xml_file to t_xml_header.

*  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_SAPGUI_DIRECTORY
*    CHANGING
*      SAPGUI_DIRECTORY = V_DIRNAME.


  call method cl_gui_frontend_services=>directory_exist
    exporting
      directory = v_dirname
    receiving
      result    = s.

  if s eq space.

    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_CREATE
      EXPORTING
        DIRECTORY                = v_dirname
      CHANGING
        RC                       = k
      EXCEPTIONS
        DIRECTORY_CREATE_FAILED  = 1
        CNTL_ERROR               = 2
        ERROR_NO_GUI             = 3
        DIRECTORY_ACCESS_DENIED  = 4
        DIRECTORY_ALREADY_EXISTS = 5
        PATH_NOT_FOUND           = 6
        UNKNOWN_ERROR            = 7
        NOT_SUPPORTED_BY_GUI     = 8
        WRONG_PARAMETER          = 9
        others                   = 10
            .
    IF SY-SUBRC <> 0.
     MESSAGE '     ' type 'S'.
     stop.
    ENDIF.


*    call method cl_gui_frontend_services=>directory_create
*      exporting
*        directory =
*      changing
*        rc        = .
  endif.

  if k ne space.
    message 'Directory not created!' type 'S'.
    stop.
  endif.

  concatenate v_dirname  v_filename into v_filename.
  replace all occurrences of '\' in v_filename with '/'.


  call function 'GUI_DOWNLOAD'
    exporting
      filename                = v_filename
    tables
      data_tab                = t_xml_header     " FILETYPE = 'ASK'
    exceptions
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      others                  = 22.
  if sy-subrc <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
  CONCATENATE '  ' v_filename into v_filename SEPARATED BY space.
MESSAGE v_filename TYPE 'I'.

END-OF-DEFINITION.


defINE xml_download5.



  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    EXPORTING
      WINDOW_TITLE         =  ' '
      DEFAULT_EXTENSION    =  '*.xls'
      DEFAULT_FILE_NAME    =  &1
*      WITH_ENCODING        =
      FILE_FILTER          = ' Excel(*.xls)|*.xls| XML";" (*.xml)|*.xml'
*      INITIAL_DIRECTORY    =
*      PROMPT_ON_OVERWRITE  = 'X'
    CHANGING
      FILENAME             = v_filename
      PATH                 =  v_dirname
      FULLPATH             = lv_ful_path
      USER_ACTION          = lv_USER_ACTION
*      FILE_ENCODING        =
    EXCEPTIONS
      CNTL_ERROR           = 1
      ERROR_NO_GUI         = 2
      NOT_SUPPORTED_BY_GUI = 3
      others               = 4
          .
  IF SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  if lv_USER_ACTION ne 0.
    exit.
  endif.
*  v_dirname = &1.
*  v_filename = &2.

*  t_style = '</Styles>'.
*  append t_style.
*  append lines of t_style to t_xml_header.
*
*  t_xml_file = '</Workbook>'.
*  append t_xml_file.

  append lines of t_xml_file to t_xml_header.

*  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_SAPGUI_DIRECTORY
*    CHANGING
*      SAPGUI_DIRECTORY = V_DIRNAME.


  call method cl_gui_frontend_services=>directory_exist
    exporting
      directory = v_dirname
    receiving
      result    = s.

  if s eq space.

    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_CREATE
      EXPORTING
        DIRECTORY                = v_dirname
      CHANGING
        RC                       = k
      EXCEPTIONS
        DIRECTORY_CREATE_FAILED  = 1
        CNTL_ERROR               = 2
        ERROR_NO_GUI             = 3
        DIRECTORY_ACCESS_DENIED  = 4
        DIRECTORY_ALREADY_EXISTS = 5
        PATH_NOT_FOUND           = 6
        UNKNOWN_ERROR            = 7
        NOT_SUPPORTED_BY_GUI     = 8
        WRONG_PARAMETER          = 9
        others                   = 10
            .
    IF SY-SUBRC <> 0.
     MESSAGE '     ' type 'S'.
     stop.
    ENDIF.


*    call method cl_gui_frontend_services=>directory_create
*      exporting
*        directory =
*      changing
*        rc        = .
  endif.

  if k ne space.
    message 'Directory not created!' type 'S'.
    stop.
  endif.

  concatenate v_dirname  v_filename into v_filename.
  replace all occurrences of '\' in v_filename with '/'.


  call function 'GUI_DOWNLOAD'
    exporting
      filename                = v_filename
    tables
      data_tab                = t_xml_header     " FILETYPE = 'ASK'
    exceptions
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      others                  = 22.
  if sy-subrc <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
  CONCATENATE '  ' v_filename into v_filename SEPARATED BY space.
MESSAGE v_filename TYPE 'I'.

END-OF-DEFINITION.