Skip to Content
0
Jan 29, 2021 at 04:51 PM

Change of the format of the cell in excel to accounting using XML class

54 Views

Hi Experts!

I have a requirement to change the cell format of excel to 'Accounting'. Currently the cell format is in 'General'.

I am using if_ixml_element class to generate excel.

Please find my code below.

* 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 ). "#EC NOTEXT 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 = 'LOG' parent = l_element_root ). l_value = sy-uname. l_document->create_simple_element( name = 'Author' value = l_value parent = r_element_properties ). "#EC NOTEXT

* Styles

r_styles = l_document->create_simple_element( name = 'Styles' parent = l_element_root ). "#EC NOTEXT

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

r_border = l_document->create_simple_element( name = 'Borders' parent = r_style1 ). "#EC NOTEXT

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). "#EC NOTEXT

*r_format = l_document->create_simple_element( name = 'NumberFormat' parent = r_style1 ).

r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ). "#EC NOTEXT

r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). "#EC NOTEXT

r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). "#EC NOTEXT

* r_format->set_attribute_ns( name = 'NumberFormat' prefix = 'ss' * value = '_-$* #,##0.00_-;-$* #,##0.00_-;_-$* "-"??_-;_-@_-' ). "#EC NOTEXT

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). "#EC NOTEXT

r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ). "#EC NOTEXT

r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). "#EC NOTEXT

r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). "#EC NOTEXT

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). "#EC NOTEXT

r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ). "#EC NOTEXT

r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). "#EC NOTEXT

r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). "#EC NOTEXT

r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). "#EC NOTEXT

Please suggest me the solution.

Please find the complete code in the attachment.source-code.txt

Thanks in advance.

Divya.

Attachments

source-code.txt (24.0 kB)