diff --git a/ZA2X/CLAS/ZCL_EXCEL.slnk b/ZA2X/CLAS/ZCL_EXCEL.slnk index 534b638..e6f94e5 100644 --- a/ZA2X/CLAS/ZCL_EXCEL.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL.slnk @@ -1,5 +1,6 @@ - + + class ZCL_EXCEL definition public final @@ -9,6 +10,8 @@ *"* do not include other source files here!!! public section. + interfaces ZIF_EXCEL_BOOK_PROTECTION . + data PROPERTIES type ref to ZCL_EXCEL_PROPERTIES . data SECURITY type ref to ZCL_EXCEL_SECURITY . @@ -72,15 +75,25 @@ private section. *"* implementation or private method's signature *"* use this source file for any macro definitions you need *"* in the implementation part of the class - - - - - - - - - + + + + + + + + METHOD zif_excel_book_protection~initialize. + me->zif_excel_book_protection~protected = zif_excel_book_protection=>c_unprotected. + me->zif_excel_book_protection~lockrevision = zif_excel_book_protection=>c_unlocked. + me->zif_excel_book_protection~lockstructure = zif_excel_book_protection=>c_unlocked. + me->zif_excel_book_protection~lockwindows = zif_excel_book_protection=>c_unlocked. + CLEAR me->zif_excel_book_protection~workbookpassword. + CLEAR me->zif_excel_book_protection~revisionspassword. +ENDMETHOD. + + + + method ADD_NEW_DRAWING. DATA: lv_guid TYPE guid_16. * Create default blank worksheet @@ -90,16 +103,16 @@ private section. drawings->add( eo_drawing ). endmethod. - - + + method ADD_NEW_RANGE. * Create default blank range CREATE OBJECT eo_range. ranges->add( eo_range ). endmethod. - - + + method ADD_NEW_STYLE. * Create default style CREATE OBJECT eo_style. @@ -107,9 +120,9 @@ endmethod. endmethod. - - - + + + method ADD_NEW_WORKSHEET. DATA: lv_guid TYPE guid_16. * Create default blank worksheet @@ -121,8 +134,8 @@ endmethod. worksheets->active_worksheet = worksheets->size( ). endmethod. - - method CONSTRUCTOR. + + METHOD constructor. DATA: lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_style TYPE REF TO zcl_excel_style. @@ -134,30 +147,32 @@ endmethod. CREATE OBJECT styles. CREATE OBJECT drawings. + me->zif_excel_book_protection~initialize( ). + me->add_new_worksheet( ). me->add_new_style( ). " Standard style lo_style = me->add_new_style( ). " Standard style with fill gray125 lo_style->fill->filltype = zcl_excel_style_fill=>c_fill_pattern_gray125. -endmethod. +ENDMETHOD. - - + + method GET_ACTIVE_WORKSHEET. eo_worksheet = me->worksheets->get( me->worksheets->active_worksheet ). endmethod. - - + + method GET_DRAWINGS_ITERATOR. eo_iterator = me->drawings->get_iterator( ). endmethod. - - + + method GET_NEXT_TABLE_ID. DATA: lo_worksheet TYPE REF TO zcl_excel_worksheet, lo_iterator TYPE REF TO cl_object_collection_iterator, @@ -176,40 +191,40 @@ endmethod. endmethod. - - + + method GET_RANGES_ITERATOR. eo_iterator = me->ranges->get_iterator( ). endmethod. - - + + method GET_STYLES_ITERATOR. eo_iterator = me->styles->get_iterator( ). endmethod. - - + + method GET_WORKSHEETS_ITERATOR. eo_iterator = me->worksheets->get_iterator( ). endmethod. - - + + method GET_WORKSHEETS_NAME. ep_name = me->worksheets->name. endmethod. - - + + method GET_WORKSHEETS_SIZE. ep_size = me->worksheets->size( ). diff --git a/ZA2X/CLAS/ZCL_EXCEL_STYLE.slnk b/ZA2X/CLAS/ZCL_EXCEL_STYLE.slnk index cf4afa9..66c961e 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_STYLE.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_STYLE.slnk @@ -36,13 +36,13 @@ private section. *"* implementation or private method's signature *"* use this source file for any macro definitions you need *"* in the implementation part of the class - - - - + + + + - - + + method CONSTRUCTOR. diff --git a/ZA2X/CLAS/ZCL_EXCEL_STYLE_ALIGNMENT.slnk b/ZA2X/CLAS/ZCL_EXCEL_STYLE_ALIGNMENT.slnk index b3dfe17..08f0125 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_STYLE_ALIGNMENT.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_STYLE_ALIGNMENT.slnk @@ -1,5 +1,5 @@ - + class ZCL_EXCEL_STYLE_ALIGNMENT definition public final diff --git a/ZA2X/CLAS/ZCL_EXCEL_STYLE_BORDERS.slnk b/ZA2X/CLAS/ZCL_EXCEL_STYLE_BORDERS.slnk index bfdbbde..11f4a1a 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_STYLE_BORDERS.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_STYLE_BORDERS.slnk @@ -1,5 +1,5 @@ - + class ZCL_EXCEL_STYLE_BORDERS definition public final diff --git a/ZA2X/CLAS/ZCL_EXCEL_STYLE_FILL.slnk b/ZA2X/CLAS/ZCL_EXCEL_STYLE_FILL.slnk index 083e487..52cb3a2 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_STYLE_FILL.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_STYLE_FILL.slnk @@ -1,5 +1,5 @@ - + class ZCL_EXCEL_STYLE_FILL definition public final diff --git a/ZA2X/CLAS/ZCL_EXCEL_STYLE_NUMBER_FORMAT.slnk b/ZA2X/CLAS/ZCL_EXCEL_STYLE_NUMBER_FORMAT.slnk index f2f3264..763ef8e 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_STYLE_NUMBER_FORMAT.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_STYLE_NUMBER_FORMAT.slnk @@ -1,5 +1,5 @@ - + class ZCL_EXCEL_STYLE_NUMBER_FORMAT definition public final diff --git a/ZA2X/CLAS/ZCL_EXCEL_STYLE_PROTECTION.slnk b/ZA2X/CLAS/ZCL_EXCEL_STYLE_PROTECTION.slnk index f77f3f2..4e242c9 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_STYLE_PROTECTION.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_STYLE_PROTECTION.slnk @@ -1,5 +1,5 @@ - + class ZCL_EXCEL_STYLE_PROTECTION definition public final diff --git a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk index 8cc6c23..e320ca2 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_WRITER_2007.slnk @@ -3657,34 +3657,40 @@ endmethod. - method CREATE_XL_WORKBOOK. + METHOD create_xl_workbook. ** Constant node name - DATA: lc_xml_node_workbook TYPE string VALUE 'workbook', - lc_xml_node_fileversion TYPE string VALUE 'fileVersion', - lc_xml_node_workbookpr TYPE string VALUE 'workbookPr', - lc_xml_node_bookviews TYPE string VALUE 'bookViews', - lc_xml_node_workbookview TYPE string VALUE 'workbookView', - lc_xml_node_sheets TYPE string VALUE 'sheets', - lc_xml_node_sheet TYPE string VALUE 'sheet', - lc_xml_node_calcpr TYPE string VALUE 'calcPr', - lc_xml_node_definednames TYPE string VALUE 'definedNames', - lc_xml_node_definedname TYPE string VALUE 'definedName', + DATA: lc_xml_node_workbook TYPE string VALUE 'workbook', + lc_xml_node_fileversion TYPE string VALUE 'fileVersion', + lc_xml_node_workbookpr TYPE string VALUE 'workbookPr', + lc_xml_node_bookviews TYPE string VALUE 'bookViews', + lc_xml_node_workbookview TYPE string VALUE 'workbookView', + lc_xml_node_sheets TYPE string VALUE 'sheets', + lc_xml_node_sheet TYPE string VALUE 'sheet', + lc_xml_node_calcpr TYPE string VALUE 'calcPr', + lc_xml_node_workbookprotection TYPE string VALUE 'workbookProtection', + lc_xml_node_definednames TYPE string VALUE 'definedNames', + lc_xml_node_definedname TYPE string VALUE 'definedName', " Node attributes - lc_xml_attr_appname TYPE string VALUE 'appName', - lc_xml_attr_lastedited TYPE string VALUE 'lastEdited', - lc_xml_attr_lowestedited TYPE string VALUE 'lowestEdited', - lc_xml_attr_rupbuild TYPE string VALUE 'rupBuild', - lc_xml_attr_themeversion TYPE string VALUE 'defaultThemeVersion', - lc_xml_attr_xwindow TYPE string VALUE 'xWindow', - lc_xml_attr_ywindow TYPE string VALUE 'yWindow', - lc_xml_attr_windowwidth TYPE string VALUE 'windowWidth', - lc_xml_attr_windowheight TYPE string VALUE 'windowHeight', - lc_xml_attr_name TYPE string VALUE 'name', - lc_xml_attr_sheetid TYPE string VALUE 'sheetId', - lc_xml_attr_id TYPE string VALUE 'id', - lc_xml_attr_calcid TYPE string VALUE 'calcId', + lc_xml_attr_appname TYPE string VALUE 'appName', + lc_xml_attr_lastedited TYPE string VALUE 'lastEdited', + lc_xml_attr_lowestedited TYPE string VALUE 'lowestEdited', + lc_xml_attr_rupbuild TYPE string VALUE 'rupBuild', + lc_xml_attr_themeversion TYPE string VALUE 'defaultThemeVersion', + lc_xml_attr_xwindow TYPE string VALUE 'xWindow', + lc_xml_attr_ywindow TYPE string VALUE 'yWindow', + lc_xml_attr_windowwidth TYPE string VALUE 'windowWidth', + lc_xml_attr_windowheight TYPE string VALUE 'windowHeight', + lc_xml_attr_name TYPE string VALUE 'name', + lc_xml_attr_sheetid TYPE string VALUE 'sheetId', + lc_xml_attr_id TYPE string VALUE 'id', + lc_xml_attr_calcid TYPE string VALUE 'calcId', + lc_xml_attr_lockrevision TYPE string VALUE 'lockRevision', + lc_xml_attr_lockstructure TYPE string VALUE 'lockStructure', + lc_xml_attr_lockwindows TYPE string VALUE 'lockWindows', + lc_xml_attr_revisionspassword TYPE string VALUE 'revisionsPassword', + lc_xml_attr_workbookpassword TYPE string VALUE 'workbookPassword', " Node namespace lc_r_ns TYPE string VALUE 'r', lc_xml_node_ns TYPE string VALUE 'http://schemas.openxmlformats.org/spreadsheetml/2006/main', @@ -3752,6 +3758,35 @@ endmethod. value = '124226' ). lo_element_root->append_child( new_child = lo_element ). + " workbookProtection node + IF me->excel->zif_excel_book_protection~protected EQ abap_true. + lo_element = lo_document->create_simple_element( name = lc_xml_node_workbookprotection + parent = lo_document ). + MOVE me->excel->zif_excel_book_protection~workbookpassword TO lv_value. + IF lv_value IS NOT INITIAL. + lo_element->set_attribute_ns( name = lc_xml_attr_workbookpassword + value = lv_value ). + ENDIF. + MOVE me->excel->zif_excel_book_protection~revisionspassword TO lv_value. + IF lv_value IS NOT INITIAL. + lo_element->set_attribute_ns( name = lc_xml_attr_revisionspassword + value = lv_value ). + ENDIF. + MOVE me->excel->zif_excel_book_protection~lockrevision TO lv_value. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_lockrevision + value = lv_value ). + MOVE me->excel->zif_excel_book_protection~lockstructure TO lv_value. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_lockstructure + value = lv_value ). + MOVE me->excel->zif_excel_book_protection~lockwindows TO lv_value. + CONDENSE lv_value NO-GAPS. + lo_element->set_attribute_ns( name = lc_xml_attr_lockwindows + value = lv_value ). + lo_element_root->append_child( new_child = lo_element ). + ENDIF. + " bookviews node lo_element = lo_document->create_simple_element( name = lc_xml_node_bookviews parent = lo_document ). @@ -3798,13 +3833,13 @@ endmethod. " ranges node - lo_element = lo_document->create_simple_element( name = lc_xml_node_definedNames + lo_element = lo_document->create_simple_element( name = lc_xml_node_definednames parent = lo_document ). lo_iterator = excel->get_ranges_iterator( ). WHILE lo_iterator->if_object_collection_iterator~has_next( ) EQ abap_true. " range node - lo_sub_element = lo_document->create_simple_element_ns( name = lc_xml_node_definedName + lo_sub_element = lo_document->create_simple_element_ns( name = lc_xml_node_definedname parent = lo_document ). lo_range ?= lo_iterator->if_object_collection_iterator~get_next( ). lv_value = lo_range->name. @@ -3823,7 +3858,6 @@ endmethod. value = '125725' ). lo_element_root->append_child( new_child = lo_element ). - ********************************************************************** * STEP 5: Create xstring stream lo_streamfactory = lo_ixml->create_stream_factory( ). @@ -3831,7 +3865,7 @@ endmethod. lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream document = lo_document ). lo_renderer->render( ). -endmethod. +ENDMETHOD. diff --git a/ZA2X/DTEL/ZEXCEL_BOOK_PROTECTION.slnk b/ZA2X/DTEL/ZEXCEL_BOOK_PROTECTION.slnk new file mode 100644 index 0000000..74b78a8 --- /dev/null +++ b/ZA2X/DTEL/ZEXCEL_BOOK_PROTECTION.slnk @@ -0,0 +1,4 @@ + + + + diff --git a/ZA2X/INTF/ZIF_EXCEL_BOOK_PROTECTION.slnk b/ZA2X/INTF/ZIF_EXCEL_BOOK_PROTECTION.slnk new file mode 100644 index 0000000..77dfa42 --- /dev/null +++ b/ZA2X/INTF/ZIF_EXCEL_BOOK_PROTECTION.slnk @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/ZA2X/PROG/ZDEMO_EXCEL.slnk b/ZA2X/PROG/ZDEMO_EXCEL.slnk index d215316..647ef46 100644 --- a/ZA2X/PROG/ZDEMO_EXCEL.slnk +++ b/ZA2X/PROG/ZDEMO_EXCEL.slnk @@ -1,5 +1,5 @@ - + @@ -30,5 +30,8 @@ SUBMIT zdemo_excel10 AND RETURN. " Bind table with field catalog SUBMIT zdemo_excel12 AND RETURN. " Column size SUBMIT zdemo_excel13 AND RETURN. " Merge cell SUBMIT zdemo_excel14 AND RETURN. " Alignment -SUBMIT zdemo_excel15 AND RETURN. " Read Excel and write it back +SUBMIT zdemo_excel15 AND RETURN. " Read Excel and write it back +SUBMIT zdemo_excel16 AND RETURN. " Read Excel and write it back +SUBMIT zdemo_excel17 AND RETURN. " Lock sheet +SUBMIT zdemo_excel18 AND RETURN. " Lock workbook diff --git a/ZA2X/PROG/ZDEMO_EXCEL18.slnk b/ZA2X/PROG/ZDEMO_EXCEL18.slnk new file mode 100644 index 0000000..f968ab9 --- /dev/null +++ b/ZA2X/PROG/ZDEMO_EXCEL18.slnk @@ -0,0 +1,58 @@ + + + + + + + + *&---------------------------------------------------------------------* +*& Report ZIFE_TEST_EXCEL +*& +*&---------------------------------------------------------------------* +*& +*& +*&---------------------------------------------------------------------* + +REPORT zdemo_excel18. + +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, + lo_style_protection TYPE REF TO zcl_excel_style, + lv_style_protection_guid TYPE zexcel_cell_style, + lv_file TYPE xstring, + lv_bytecount TYPE i, + lt_file_tab TYPE STANDARD TABLE OF solisti1. + +CREATE OBJECT lo_excel. + +" Get active sheet +lo_excel->zif_excel_book_protection~protected = zif_excel_book_protection=>c_protected. +lo_excel->zif_excel_book_protection~lockrevision = zif_excel_book_protection=>c_locked. +lo_excel->zif_excel_book_protection~lockstructure = zif_excel_book_protection=>c_locked. +lo_excel->zif_excel_book_protection~lockwindows = zif_excel_book_protection=>c_locked. + + +lo_worksheet = lo_excel->get_active_worksheet( ). +lo_worksheet->set_cell( ip_row = 4 ip_column = 'C' ip_value = 'This cell is unlocked' ip_style = lv_style_protection_guid ). + +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:\Protection.xlsx' + filetype = 'BIN' + TABLES + data_tab = lt_file_tab. +