1

I am able to add filters using OLE2 in ABAP and my excel file getting created successfully. The issue is filter is not working - I can see filters attached to field columns but I can not click.

Abhishek
  • 99
  • 1
  • 14
  • Give you code. What happens when you click? Are they disabled or what? Give screenshot – Suncatcher Jul 04 '18 at 07:32
  • When you protect a sheet in Excel there's a tickbox "Allow Filtering" in the protection dialog. If that's not ticked you can add the filters but can't use them. I suspect that's what's happening here – Harassed Dad Jul 04 '18 at 11:19
  • @HarassedDad : exactly this is what I have to write in ABAP code, I have tried setting this property to true but it’s not working. If possible please can you share code block how to lock sheet and allow filter using ABAP code. – Abhishek Jul 05 '18 at 03:51
  • I would advice you to NOT use OLE, because Microsoft tends to change everything every time it changes Office versions. Take a look at ABAP2EXCEL in github (or something like that... google for "ZCL_EXCEL") – VXLozano Jul 05 '18 at 09:39
  • @Suncatcher : Yes they are coming disabled. Below is code which I have : – Abhishek Jul 09 '18 at 20:23
  • @Suncatcher : Yes they are coming disabled. Below is code which I have :
    CALL METHOD OF w_excel 'RANGE' = w_range
        EXPORTING
        #1 = 'A1'                                       "  Column A1  TO D11   Range
        #2 = 'F1'.
      CALL METHOD OF w_range 'AutoFilter' = w_filtering.
      PERFORM err_hdl USING 'AutoFilter'.  
    

    I dont know how to upload Image here but what I have figured out is I have to enable "use AutoFilter" checkbox under "Review >> Protect Sheet >>" then in Popup "use AutoFilter".
    Please help me how can I set this checkbox using ABAP code.
    Thanks-
    – Abhishek Jul 09 '18 at 20:35
  • Insert your code [as appropriate](https://stackoverflow.com/help/formatting), not as comment. – Suncatcher Jul 13 '18 at 13:24

1 Answers1

0
DATA: go_application TYPE ole2_object,
      go_column      TYPE ole2_object,

CALL METHOD OF go_application 'Columns' = go_column.
CALL METHOD OF go_column 'AutoFit'.
SET PROPERTY OF go_column 'AutoFilter' = 1.
 CALL METHOD OF go_sheet 'Protect'
      EXPORTING
        #1  = 'pass' " Password
        #2  = 1 " Protect Drawing Objects
        #3  = 1 " Protect Contents
        #4  = 1 " Protect Scenarios
        #5  = 0
        #6  = 0
        #7  = 0
        #8  = 0
        #9  = 0
        #10 = 0
        #11 = 0
        #12 = 0
        #13 = 0
        #14 = 0
        #15 = 1.

Where #15 put filter ON. Give me feedback if it worked for you

fixeln
  • 34
  • 4