Upload data to Excel template

The function EXPORT_TO_SPREADSHEET gives you a possibility to fill an existing Excel file. You can use such file as template and format it previously - setup colors, borders, etc.
Remember: the Excel file has to exist before program is executed. The data must be transferred to an existing and valid Excel file. The function EXPORT_TO_SPREADSHEET doesn't create the file, it only transfers data.
REPORT zexcel_fill.

TYPE-POOLS:
  soi.

DATA:
  lv_file      TYPE string VALUE 'c:\tmp\test.xlsx',
  lv_url(256)  TYPE c,
  ls_range     TYPE soi_dimension_item,
  lt_range     TYPE soi_dimension_table,
  lt_excel     TYPE soi_generic_table,
  ls_excel     TYPE soi_generic_item.

CONCATENATE 'file://' lv_file INTO lv_url.

ls_range-row     = 1.
ls_range-column  = 1.
ls_range-rows    = 2.
ls_range-columns = 2.
APPEND ls_range TO lt_range.

ls_excel-row = '1'. ls_excel-column = '1'. ls_excel-value = 'A'. APPEND ls_excel TO lt_excel.
ls_excel-row = '1'. ls_excel-column = '2'. ls_excel-value = 'B'. APPEND ls_excel TO lt_excel.
ls_excel-row = '2'. ls_excel-column = '1'. ls_excel-value = 'C'. APPEND ls_excel TO lt_excel.
ls_excel-row = '2'. ls_excel-column = '2'. ls_excel-value = 'D'. APPEND ls_excel TO lt_excel.

CALL FUNCTION 'EXPORT_TO_SPREADSHEET'
  EXPORTING
    item_url      = lv_url
    document_type = 'Excel.Sheet'
  TABLES
    data_table    = lt_excel
    ranges        = lt_range.

WRITE: / 'OK'.
See other related notes in my infodepot:
Upload Excel file to internal table
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2013 http://www.kerum.pl/infodepot/

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.