cancel
Showing results for 
Search instead for 
Did you mean: 

XML FILE that can convert to .XLSX (Excel2007 format) format how can create (DOM )

0 Kudos

Hi All,

I have file which created by DOM method when i tried to send as .xlsx Via mail using Class Cl_bcs It is not able to open .

Please Help ...

COde--------

FORM process_xml_data .

* Creating a ixml Factory
l_ixml = cl_ixml=>create( ).

* Creating the DOM Object Model
l_document = l_ixml->create_document( ).

* Create Root Node 'Workbook'
l_element_root = l_document->create_simple_element( name = 'Workbook' parent = l_document ).
l_element_root->set_attribute( name = 'xmlns' value = 'urn:schemas-microsoft-com:office:spreadsheet' ).

ns_attribute = l_document->create_namespace_decl( name = 'ss' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:spreadsheet' ).
l_element_root->set_attribute_node( ns_attribute ).

ns_attribute = l_document->create_namespace_decl( name = 'x' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:excel' ).
l_element_root->set_attribute_node( ns_attribute ).

* Create node for document properties.
r_element_properties = l_document->create_simple_element( name = 'TEST_REPORT' parent = l_element_root ).
l_value = sy-uname.
l_document->create_simple_element( name = 'Author' value = l_value parent = r_element_properties ).

* Styles
r_styles = l_document->create_simple_element( name = 'Styles' parent = l_element_root ).

* Style for Header
r_style = l_document->create_simple_element( name = 'Style' parent = r_styles ).
r_style->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Header' ).

r_format = l_document->create_simple_element( name = 'Font' parent = r_style ).
r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Interior' parent = r_style ).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#92D050' ).
r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss' value = 'Solid' ).

r_format = l_document->create_simple_element( name = 'Alignment' parent = r_style ).
r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ).

r_border = l_document->create_simple_element( name = 'Borders' parent = r_style ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

* Style for Data
r_style1 = l_document->create_simple_element( name = 'Style' parent = r_styles ).
r_style1->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Data' ).

r_border = l_document->create_simple_element( name = 'Borders' parent = r_style1 ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).


* Worksheet
r_worksheet = l_document->create_simple_element( name = 'Worksheet' parent = l_element_root ).
r_worksheet->set_attribute_ns( name = 'Name' prefix = 'ss' value = 'Sheet1' ).

* Table
r_table = l_document->create_simple_element( name = 'Table' parent = r_worksheet ).
r_table->set_attribute_ns( name = 'FullColumns' prefix = 'x' value = '1' ).
r_table->set_attribute_ns( name = 'FullRows' prefix = 'x' value = '1' ).

* Column Formatting
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '60' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '50' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '60' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '100' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '60' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '60' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '60' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '60' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '65' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '65' ).

r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '60' ).

* Blank Row
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).

* Column Headers Row
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '1' ).

* Sr. No.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Date' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* User Name
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Day' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Full Name
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Emp Id' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Department
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Emp Name' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Login
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Shift Desc' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Login
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Punch In Time' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Login
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Punch Out Time' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Login
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Total Hours Worked' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Login
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Attendance Status' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Login
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Leave Type' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Login
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Biometric / Manual' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).

* Data Table
LOOP AT ist_mail INTO wa_mail.
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
* date.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-zdate.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* Day
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-zday.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* Pernr
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-pernr.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* Emp Name
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-ename.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* shift
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-schkz.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* clock in
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-clock_in.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* clock out
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-clock_out.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* clock total
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-clock_tot.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* status
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-atext.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* leave type
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-atext_leave.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format

* biomatric and manual
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_mail-zatt_typ.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format
CLEAR wa_mail. "Insert - 002 Bug fix: Total hours getting added from previous employee record to next employee first record
ENDLOOP.

* Creating a Stream Factory
l_streamfactory = l_ixml->create_stream_factory( ).

* Connect Internal XML Table to Stream Factory
l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).


* Rendering the Document
l_renderer = l_ixml->create_renderer( ostream = l_ostream document = l_document ).
l_rc = l_renderer->render( ).

* Saving the XML Document
l_xml_size = l_ostream->get_num_written_raw( ).

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; }

ENDFORM. " process_xml_data

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; }

LOOP AT l_xml_table INTO wa_xml.
CLEAR objbin.
objbin-line = wa_xml-data.
APPEND objbin.
ENDLOOP.

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

TRY.

* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).

* -------- create and set document with attachment ---------------
* create document object from internal table with text
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ist_message
i_subject = 'Employee Time Sheet' ).

* add the spread sheet as attachment to document object

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: doc_chng LIKE sodocchgi1.
DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: subj_date(10) TYPE c.
DATA: objbin LIKE solix OCCURS 10 WITH HEADER LINE.

DATA lt_att_head TYPE soli_tab.
DATA lv_filename TYPE string.
DATA lv_text_line TYPE soli.
* lv_filename = 'excel_example.xlsx'.
CONCATENATE 'Attendance Confirmation_of' c_undrscr gv_mail_name c_undrscr wa_temp-pernr '.xlsx'
INTO lv_filename .
CONCATENATE '&SO_FILENAME=' lv_filename INTO lv_text_line.
APPEND lv_text_line TO lt_att_head.


document->add_attachment(
i_attachment_type = 'xls'
i_attachment_subject = 'Attendance Report'
i_attachment_size = lv_size
i_att_content_hex = objbin

i_attachment_header = lt_att_head ).

* add document object to send request
send_request->set_document( document ).

* --------- add recipient (e-mail address) -----------------------
* create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).

* add recipient object to send request
send_request->add_recipient( recipient ).

* ---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).

COMMIT WORK.

IF sent_to_all IS INITIAL.
MESSAGE i500(sbcoms) WITH mailto.
ELSE.
MESSAGE s022(so).
ENDIF.

* ------------ exception handling ----------------------------------
* replace this rudimentary exception handling with your own one !!!
CATCH cx_bcs INTO bcs_exception.
MESSAGE i865(so) WITH bcs_exception->error_type.
ENDTRY.

Accepted Solutions (0)

Answers (0)