abap2xlsx/ZA2X/PROG/ZDEMO_EXCEL17.slnk
Ivan 24c5fca308 Update slinkees
Update of all the slinkees files with the latest version of SAPLink to
simplify merge of pull request
2015-01-12 14:55:28 -06:00

67 lines
3.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<PROG NAME="ZDEMO_EXCEL17" VARCL="X" SUBC="1" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: Sheet Protection" LENGTH="33 "/>
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="24 "/>
<textElement ID="S" KEY="P_PWD" ENTRY="D ." LENGTH="9 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_EXCEL17
*&amp;
*&amp;---------------------------------------------------------------------*
*&amp;
*&amp;
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel17.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_style_protection TYPE REF TO zcl_excel_style,
lv_style_protection_guid TYPE zexcel_cell_style,
lo_style TYPE REF TO zcl_excel_style,
lv_style TYPE zexcel_cell_style.
CONSTANTS: gc_save_file_name TYPE string VALUE &apos;17_SheetProtection.xlsx&apos;.
INCLUDE zdemo_excel_outputopt_incl.
PARAMETERS: p_pwd TYPE zexcel_aes_password LOWER CASE DEFAULT &apos;secret&apos;.
START-OF-SELECTION.
CREATE OBJECT lo_excel.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;zif_excel_sheet_protection~protected = zif_excel_sheet_protection=&gt;c_protected.
* lo_worksheet-&gt;zif_excel_sheet_protection~password = &apos;DAA7&apos;. &quot;it is the encoded word &quot;secret&quot;
lo_worksheet-&gt;zif_excel_sheet_protection~password = zcl_excel_common=&gt;encrypt_password( p_pwd ).
lo_worksheet-&gt;zif_excel_sheet_protection~sheet = zif_excel_sheet_protection=&gt;c_active.
lo_worksheet-&gt;zif_excel_sheet_protection~objects = zif_excel_sheet_protection=&gt;c_active.
lo_worksheet-&gt;zif_excel_sheet_protection~scenarios = zif_excel_sheet_protection=&gt;c_active.
&quot; First style to unlock a cell
lo_style_protection = lo_excel-&gt;add_new_style( ).
lo_style_protection-&gt;protection-&gt;locked = zcl_excel_style_protection=&gt;c_protection_unlocked.
lv_style_protection_guid = lo_style_protection-&gt;get_guid( ).
&quot; Another style which should not affect the unlock style
lo_style = lo_excel-&gt;add_new_style( ).
lo_style-&gt;fill-&gt;filltype = zcl_excel_style_fill=&gt;c_fill_solid.
lo_style-&gt;fill-&gt;fgcolor-rgb = &apos;FFCC3333&apos;.
lv_style = lo_style-&gt;get_guid( ).
lo_worksheet-&gt;set_cell( ip_row = 3 ip_column = &apos;C&apos; ip_value = &apos;This cell is locked locked and has the second formating&apos; ip_style = lv_style ).
lo_worksheet-&gt;set_cell( ip_row = 4 ip_column = &apos;C&apos; ip_value = &apos;This cell is unlocked&apos; ip_style = lv_style_protection_guid ).
lo_worksheet-&gt;set_cell( ip_row = 5 ip_column = &apos;C&apos; ip_value = &apos;This cell is locked as all the others empty cell&apos; ).
lo_worksheet-&gt;set_cell( ip_row = 6 ip_column = &apos;C&apos; ip_value = &apos;This cell is unlocked&apos; ip_style = lv_style_protection_guid ).
lo_worksheet-&gt;set_cell( ip_row = 7 ip_column = &apos;C&apos; ip_value = &apos;This cell is unlocked&apos; ip_style = lv_style_protection_guid ).
lo_worksheet-&gt;set_cell( ip_row = 8 ip_column = &apos;C&apos; ip_value = &apos;This cell is locked as all the others empty cell&apos; ).
*** Create output
lcl_output=&gt;output( lo_excel ).</source>
</PROG>