class ZCL_EXCEL_HUGE_FILE_READER definition public inheriting from ZCL_EXCEL_READER_2007 create public . public section. protected section. methods LOAD_WORKSHEET redefinition . methods LOAD_SHARED_STRINGS redefinition . private section. types: begin of t_cell_content, datatype type zexcel_cell_data_type, value type zexcel_cell_value, formula type zexcel_cell_formula, style type zexcel_cell_style, end of t_cell_content . types: begin of t_cell_coord, row type zexcel_cell_row, column type zexcel_cell_column_alpha, end of t_cell_coord . types: begin of t_cell. include type t_cell_coord as coord. include type t_cell_content as content. types: end of t_cell . interface IF_SXML_NODE load . constants C_END_OF_STREAM type IF_SXML_NODE=>NODE_TYPE value IF_SXML_NODE=>CO_NT_FINAL. "#EC NOTEXT constants C_ELEMENT_OPEN type IF_SXML_NODE=>NODE_TYPE value IF_SXML_NODE=>CO_NT_ELEMENT_OPEN. "#EC NOTEXT constants C_ELEMENT_CLOSE type IF_SXML_NODE=>NODE_TYPE value IF_SXML_NODE=>CO_NT_ELEMENT_CLOSE. "#EC NOTEXT data: begin of gs_buffer_style, index type i value -1, guid type zexcel_cell_style, end of gs_buffer_style . constants C_ATTRIBUTE type IF_SXML_NODE=>NODE_TYPE value IF_SXML_NODE=>CO_NT_ATTRIBUTE. "#EC NOTEXT methods SKIP_TO importing !IV_ELEMENT_NAME type STRING !IO_READER type ref to IF_SXML_READER raising LCX_NOT_FOUND . methods FILL_CELL_FROM_ATTRIBUTES importing !IO_READER type ref to IF_SXML_READER returning value(ES_CELL) type T_CELL raising LCX_NOT_FOUND . methods READ_SHARED_STRINGS importing !IO_READER type ref to IF_SXML_READER returning value(ET_SHARED_STRINGS) type STRINGTAB . methods GET_CELL_COORD importing !IV_COORD type STRING returning value(ES_COORD) type T_CELL_COORD . methods PUT_CELL_TO_WORKSHEET importing !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET !IS_CELL type T_CELL . methods GET_SHARED_STRING importing !IV_INDEX type ANY returning value(EV_VALUE) type STRING raising LCX_NOT_FOUND . methods GET_STYLE importing !IV_INDEX type ANY returning value(EV_STYLE_GUID) type ZEXCEL_CELL_STYLE raising LCX_NOT_FOUND . methods READ_WORKSHEET_DATA importing !IO_READER type ref to IF_SXML_READER !IO_WORKSHEET type ref to ZCL_EXCEL_WORKSHEET raising LCX_NOT_FOUND . methods GET_SXML_READER importing !IV_PATH type STRING returning value(EO_READER) type ref to IF_SXML_READER raising ZCX_EXCEL . *"* use this source file for the definition and implementation of *"* local helper classes, interface definitions and type *"* declarations * Signal "not found" class lcx_not_found implementation. method constructor. super->constructor( textid = textid previous = previous ). me->error = error. endmethod. method if_message~get_text. result = error. endmethod. endclass. *"* use this source file for any type of declarations (class *"* definitions, interfaces or type declarations) you need for *"* components in the private section * Signal for "Not found" class lcx_not_found definition inheriting from cx_static_check. public section. data error type string. methods constructor importing error type string textid type sotr_conc optional previous type ref to cx_root optional. methods if_message~get_text redefinition. endclass. *"* use this source file for any macro definitions you need *"* in the implementation part of the class method fill_cell_from_attributes. while io_reader->node_type ne c_end_of_stream. io_reader->next_attribute( ). if io_reader->node_type ne c_attribute. exit. endif. case io_reader->name. when `t`. es_cell-datatype = io_reader->value. when `s`. if io_reader->value is not initial. es_cell-style = get_style( io_reader->value ). endif. when `r`. es_cell-coord = get_cell_coord( io_reader->value ). endcase. endwhile. io_reader->current_node( ). endmethod. method get_cell_coord. zcl_excel_common=>convert_columnrow2column_a_row( exporting i_columnrow = iv_coord importing e_column = es_coord-column e_row = es_coord-row ). endmethod. method get_shared_string. data: lv_tabix type i. lv_tabix = iv_index + 1. read table shared_strings into ev_value index lv_tabix. if sy-subrc ne 0. raise exception type lcx_not_found exporting error = |Entry { iv_index } not found in Shared String Table|. endif. endmethod. method get_style. data: lv_tabix type i, lo_style type ref to zcl_excel_style. if gs_buffer_style-index ne iv_index. lv_tabix = iv_index + 1. read table styles into lo_style index lv_tabix. if sy-subrc ne 0. raise exception type lcx_not_found exporting error = |Entry { iv_index } not found in Style Table|. else. gs_buffer_style-index = iv_index. gs_buffer_style-guid = lo_style->get_guid( ). endif. endif. ev_style_guid = gs_buffer_style-guid. endmethod. method get_sxml_reader. data: lv_xml type xstring. lv_xml = get_from_zip_archive( iv_path ). eo_reader = cl_sxml_string_reader=>create( lv_xml ). endmethod. method LOAD_SHARED_STRINGS. data: lo_reader type ref to if_sxml_reader. lo_reader = get_sxml_reader( ip_path ). shared_strings = read_shared_strings( lo_reader ). endmethod. method load_worksheet. data: lo_reader type ref to if_sxml_reader. lo_reader = get_sxml_reader( ip_path ). read_worksheet_data( io_reader = lo_reader io_worksheet = io_worksheet ). endmethod. method put_cell_to_worksheet. call method io_worksheet->set_cell exporting ip_column = is_cell-column ip_row = is_cell-row ip_value = is_cell-value ip_formula = is_cell-formula ip_data_type = is_cell-datatype ip_style = is_cell-style. endmethod. method read_shared_strings. while io_reader->node_type ne c_end_of_stream. io_reader->next_node( ). if io_reader->node_type eq c_element_close and io_reader->name eq `t`. append io_reader->value to et_shared_strings. endif. endwhile. endmethod. method read_worksheet_data. data: ls_cell type t_cell. * Skip to <sheetData> element skip_to( iv_element_name = `sheetData` io_reader = io_reader ). * Main loop: Evaluate the <c> elements and its children while io_reader->node_type ne c_end_of_stream. io_reader->next_node( ). case io_reader->node_type. when c_element_open. if io_reader->name eq `c`. ls_cell = fill_cell_from_attributes( io_reader ). endif. when c_element_close. case io_reader->name. when `c`. put_cell_to_worksheet( is_cell = ls_cell io_worksheet = io_worksheet ). when `f`. ls_cell-formula = io_reader->value. when `v`. if ls_cell-datatype eq `s`. ls_cell-value = get_shared_string( ls_cell-value ). else. ls_cell-value = io_reader->value. endif. when `is`. ls_cell-value = io_reader->value. when `sheetData`. exit. endcase. endcase. endwhile. endmethod. method skip_to. * Skip forward to given element while io_reader->name ne iv_element_name or io_reader->node_type ne c_element_open. io_reader->next_node( ). if io_reader->node_type = c_end_of_stream. raise exception type lcx_not_found exporting error = |XML error: Didn't find element <{ iv_element_name }>|. endif. endwhile. endmethod.