Load Excel file with long cells via SAPGUI

て烟熏妆下的殇ゞ 提交于 2019-12-13 05:06:58

问题


I need to read excel files via SAPGUI (not in batch, not from server). Only one sheet/file, not a csv file.

I am aware of a few function modules that do that, but they are restricted to cell sizes of 32 or 40 or 50 characters per cell.

Are there function modules or classes/methods that allow me to read excel files with longer cells? Longer means: either String or defined by the caller or at least 80.

Edit

I used ALSM_EXCEL_TO_INTERNAL_TABLE successfully in other projects where cell size is not that important. This module reads into a structure ALSMEX_TABLINE that restricts data to 50 characters.

KCD_EXCEL_OLE_TO_INT_CONVERT reads into a table with 32 characters / cell.


回答1:


You are right, function module 'ALSM_EXCEL_TO_INTERNAL_TABLE' can manage only 50 characters. In this, one standard alternative is to use function module 'GUI_UPLOAD', which I have used, but in this case you must convert the excel file to a cvs file, which is not what you really want.

The other alternative, according to this link, is to create a copy of 'ALSM_EXCEL_TO_INTERNAL_TABLE' and then create a copy of the structure 'ALSMEX_TABLINE'.

The structure field 'VALUE' of the new structure must be changed to the length you need and then the copy of 'ALSM_EXCEL_TO_INTERNAL_TABLE' would use the new structure of 'ALSMEX_TABLINE'.

I haven't tried this solution but maybe could work for you.

Hope it helps.




回答2:


You can use FILE_READ_AND_CONVERT_SAP_DATA for that aim. Its output table cell is limited to 256 characters, which would be quite sufficient for you. Code sample is given below:

TYPES: tv_data(256)  TYPE c,
       BEGIN OF ts_data,
        value_0001 TYPE tv_data,
        ...
        value_0020 TYPE tv_data,
       END OF ts_data,
       tt_data     TYPE TABLE OF ts_data.

DATA: lv_fname TYPE filename-fileintern,
      pt_data TYPE tt_data.

lv_fname = 'C:\test.xls'.
CALL FUNCTION 'FILE_READ_AND_CONVERT_SAP_DATA'
 EXPORTING
  i_filename           = lv_fname
  i_servertyp          = 'OLE2'
  i_fileformat         = 'XLS'
 TABLES
  i_tab_receiver       = pt_data
 EXCEPTIONS
  file_not_found       = 1
  close_failed         = 2
  authorization_failed = 3
  open_failed          = 4
  conversion_failed    = 5
  OTHERS               = 6.

IF sy-subrc <> 0.
* error handling
ENDIF.


来源:https://stackoverflow.com/questions/32498565/load-excel-file-with-long-cells-via-sapgui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!