Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Excel download with listbox / Dropdown in one column for field plant

Former Member

Requirement is to add dropdown and set values to one field to excel file downloading with predefined format of few columns.

10 REPLIES 10

raymond_giuseppi
Active Contributor
0 Kudos

Did you perform some search on OLE, and Excel macro recording /or/ look for abap2xlsx project.

0 Kudos

Thanks for writing..

No i have not used any OLE method and no micro for that....

I need logic to write in my abap code...

0 Kudos

abap2xlsx provides the demo program ZDEMO_EXCEL9, with this result:

And with the following code:

lo_worksheet->set_cell( ip_row = 2 ip_column = 'C' ip_value = c_fruits ).
lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 'Apple' ).
lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 'Banana' ).
lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 'Blueberry' ).
lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = 'Ananas' ).
lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 'Grapes' ).

lo_range            = lo_excel->add_new_range( ).
lo_range->name      = c_fruits.
lo_range->set_value( ip_sheet_name    = lv_title
                     ip_start_column  = 'C'
                     ip_start_row     = 4
                     ip_stop_column   = 'C'
                     ip_stop_row      = 8 ).

lo_data_validation              = lo_worksheet->add_new_data_validation( ).
lo_data_validation->type        = zcl_excel_data_validation=>c_type_list.
lo_data_validation->formula1    = c_fruits.
lo_data_validation->cell_row    = row.
lo_data_validation->cell_column = 'A'.
lo_worksheet->set_cell( ip_row = row ip_column = 'A' ip_value = 'Select a value' ).

0 Kudos

Thanks for showing the way to achieve.

The full code is this : Problem is with custom classes defined here? Why custom and what to add there?

REPORT  zdemo_excel6bis.

DATA: lo_excel                TYPE REF TO zcl_excel,
      lo_excel_writer         TYPE REF TO zif_excel_writer,
      lo_worksheet            TYPE REF TO zcl_excel_worksheet,
      lv_file                 TYPE xstring,
      lv_bytecount            TYPE i,
      lt_file_tab             TYPE STANDARD TABLE OF solisti1,
      lo_style                TYPE REF TO zcl_excel_style,
      lv_style_guid           TYPE zexcel_cell_style.

CREATE OBJECT lo_excel.

lo_style = lo_excel->add_new_style( ).
lo_style->number_format->format_code = zcl_excel_style_number_format=>c_format_number_comma_sep1.
lv_style_guid = lo_style->get_guid( ).

" Get active sheet
lo_worksheet = lo_excel->get_active_worksheet( ).

lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 100 ip_style = lv_style_guid ).
lo_worksheet->set_cell( ip_row = 5 ip_column = 'C' ip_value = 1000  ).
lo_worksheet->set_cell( ip_row = 6 ip_column = 'C' ip_value = 150 ).
lo_worksheet->set_cell( ip_row = 7 ip_column = 'C' ip_value = -10  ).
lo_worksheet->set_cell( ip_row = 8 ip_column = 'C' ip_value = 500  ).
lo_worksheet->set_cell( ip_row = 9 ip_column = 'C' ip_formula = 'SUM(C4:C8)' ).

CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer->write_file( lo_excel ).

"convert to table
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer        = lv_file
  IMPORTING
    output_length = lv_bytecount
  TABLES
    binary_tab    = lt_file_tab.
"Save the file
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    bin_filesize = lv_bytecount
    filename     = 'C:\FormulaBis.xlsx'
    filetype     = 'BIN'
  TABLES 

data_tab = lt_file_tab.

0 Kudos

These custom classes are provided with abap2xlsx project material (it's free; search internet to download it).

0 Kudos

Thanks.

I have searched a lot and gone through so many linksbut didnt find any code or these customised classes.

If you can provide me then i would be greatful.

Thanks

0 Kudos

Start with links from abap2xlsx in the wiki

former_member400468
Active Participant
0 Kudos

Hi!

You can record a macro using such steps: go to Data tab, select Data Validation and set Allow = List, Source = range of cells which contain allowed values. And then call this macro while creating your output.

Hope it's helpful

Evgeny

0 Kudos

Thanks for writing..

I am not getting direction to it that how to initiate as right now i am just using GUI_Download to download file and passed structure excel.

If i get how to write and what to then i will be able to manage.

former_member822693
Discoverer
0 Kudos

Hi, Could you please let me know if you where able to solve this issue. We have a similar requirement.