cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

.xls/.xlsx/.csv files are giving popup message while opening the file.

Subbaka11
Participant
0 Likes
3,065

I am using GUI_DOWNLOAD to download internal table data as Excel file, however while opening the file getting popup as 

"The file format and extension of ABC.xls’ don’t match. This file could be corrupted or unsafe. Unless you trust its source, don’t open it. Do you want to open it anyway?"

dubbaka_0-1729873290893.png

 

Can we remove this popup using ABAP coding? please let me know.

    CLEAR P_FILE .
    CONCATENATE P_FILE2 '\' LS_EKKO-EBELN '.xls' INTO P_FILE.
      CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
            filename              P_FILE
            filetype              'ASC'
            write_field_separator 'X'
          TABLES
            data_tab              LT_PO_EXCEL
            fieldnames            lt_header  .

 

Accepted Solutions (1)

Accepted Solutions (1)

RaymondGiuseppi
Active Contributor

Basically, Excel is warning you because you haven't generated an actual XLS, XLSX or CSV file with GUI_DOWNLOAD (or CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD).

  • Use one of the tools that actually generates Excel or CSV files (FAQ)
Subbaka11
Participant
0 Likes

Hello Raymond,

Thanks for your response,

I have changed file name as .csv and passed below parameters to GUI_DOWNLOAD.

    CODEPAGE              '4103'
    WRITE_BOM             'X'    REPORT  ZTRY_CSV.

TYPE-POOLStruxs.
TYPES:
  BEGIN OF ty_Line,
    vbeln LIKE vbap-vbeln,
    posnr LIKE vbap-posnr,
  END OF ty_Line.

DATAitab   TYPE table of ty_Line.

SELECT
  vbeln
  posnr
  UP TO 10 ROWS
  FROM vbap
  INTO TABLE itab.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename              'D:\TEMP\DEMO1.CSV'
    filetype              'ASC'
    write_field_separator ',' " OR 'X'
    CODEPAGE              '4103'
    WRITE_BOM             'X'
  TABLES
    data_tab              itab
*   fieldnames            =  lt_header  .
  . 

This code is generating Micro soft excel file with comma separator and creating separate columns for each field.

RaymondGiuseppi
Active Contributor

Actually, this is a text file with tab delimiter 😎

Sandra_Rossi
Active Contributor

@Subbaka11"this is a text file with tab delimiter" ... which is not intended to be used in a file named with the extension .xls (https://en.wikipedia.org/wiki/Microsoft_Excel "File formats -- Up until the 2007 version, Microsoft Excel used a proprietary binary file format called Excel Binary File Format (.XLS)")

Subbaka11
Participant
0 Likes

Hello Raymond, I using .csv extension and it is creating Microsoft excel comma separated values file, MS popup is also not coming. Will it create any issue? Please find the properties of downloaded file.

dubbaka_0-1730226198965.pngdubbaka_1-1730226206793.png

 

 

 

RaymondGiuseppi
Active Contributor
CSV is basically a text file format, so no problem should arise
Sandra_Rossi
Active Contributor
@Subbaka11 About "I using .csv extension and it is creating Microsoft excel comma separated values file", you don't understand, it's not because you use GUI_DOWNLOAD with a given file extension that SAP will choose the format inside the file. In Excel, a tab-delimited file is considered correctly if you use the extension .txt.txt. If you use the extension .csv, Excel will open the file by considering the tabs as part of one field. Windows says it's format CSV because of ".csv", not because of the format inside the file. Note that with WRITE_FIELD_SEPARATOR, GUI_DOWNLOAD can only generate a tab-delimited file (not CSV). The blank value is for no field separator at all, and ANYTHING NOT blank is for tab-delimited.
RaymondGiuseppi
Active Contributor
0 Likes

Consider using an FM such as SAP_CONVERT_TO_CSV_FORMAT or a class such as CL_SIMPLE_CSV_CONVERTER to generate an actual formatted CSV file.

Answers (0)