cancel
Showing results for 
Search instead for 
Did you mean: 

Issue while downloading to an excel file

Former Member
0 Kudos

Hi,

I'm using the following Function Modules to download an internal table to an excel file.


     1.       'SCMS_STRING_TO_XSTRING'

     2.       'CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE'

My Internal table has multiple columns with values entered by the users. The problem is, due to double quotes ("),

values beginning with quotes are somehow getting merged into a single cell.

Also, entries with double quotes (") in between the text are allowed for an example to denote inch (5" monitor). I would prefer not to delete any double quotes from the text.

Can someone suggest a way-out.

Thanks


Accepted Solutions (1)

Accepted Solutions (1)

former_member215632
Discoverer
0 Kudos

Hi,

You have this issue due to Excel special interpretation of double-quote character. You can try to avoid this surrounding entire value of string columns into pair of double-quotes and replacing actual double-quotes in the value by two. Code like this:

REPLACE all OCCURRENCES OF '"' in lv_val WITH '""'.

CONCATENATE '"' lv_val '"' INTO lv_str.

But I'd like to recommend you to take a look at abap2xlsx project. Using it export of internal table contents to the Excel file is really simple:

  DATA: lo_excel      TYPE REF TO zcl_excel,

         lo_worksheet  TYPE REF TO zcl_excel_worksheet,

         lo_writer     TYPE REF TO zif_excel_writer,

         lv_xdata      TYPE xstring,

         lt_test       TYPE TABLE OF sflight.

   " Creates active sheet

   CREATE OBJECT lo_excel.

   lo_worksheet = lo_excel->get_active_worksheet( ).

   " Data selection and binding to the Excel sheet

   SELECT * FROM sflight INTO TABLE lt_test. "#EC CI_NOWHERE

   lo_worksheet->bind_table( ip_table  = lt_test ).

  

  "Writing data to the Excel2007 file and sending it to the Front-End

   CREATE object lo_writer TYPE zcl_excel_writer_2007.

   lv_xdata = lo_writer->write_file( lo_excel ).

   cl_wd_runtime_services=>attach_file_to_response(

   i_filename = 'test.xlsx'

   i_content  = lv_xdata

   i_mime_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ).



Answers (1)

Answers (1)

guillaume-hrc
Active Contributor
0 Kudos

Hi,

There is certainly an escape character to prevent double-quotes from being interpreted as beginning of value.

Couldn't you juste replace with 2 single-quotes ?

There is Chr(34) but it is not really nice...

Some REPLACE ALL OCCURRENCES ... before your conversion to XSTRING and should you get rid of this issue.

Best regards,

Guillaume

Former Member
0 Kudos

Hi,

Thanks for your reply.

The fields are user input and i can't delete (replace) the quotes. In case of replace, i'd lose some meaningful inputs like (5" monitor).

I simply want all the quotes preserved and each column in the internal table to be downloaded to separate columns in excel. Right now, multiple columns are getting converted to a single column due to the quotes.