Hi,
You can use transformation to create more than one tab in excel sheet. first you have to create transformation in xslt_tool tcode then call that transformation by passing the internal table with data in your code to get the excel sheet data.
check the codes attached code how to call transformation inyour code and the transformation code to create tabs in excel shhet.
method IF_HTTP_EXTENSION~HANDLE_REQUEST.
DATA: lv_content TYPE string,
lv_content_type TYPE string,
lv_request_method TYPE string,
lv_cuguid TYPE string,
lv_doc_id TYPE string,
lv_logfile TYPE string,
lv_uri TYPE string,
lv_path TYPE string,
lv_disp TYPE string,
lv_cu_guid TYPE crmt_object_guid,
lv_quantity TYPE string,
lv_temp TYPE string,
lv_id TYPE string,
lv_dummy(1).
DATA: lt_form_fields TYPE tihttpnvp,
lt_header_fields TYPE tihttpnvp,
lt_ascii_content TYPE sdokcntascs,
lv_error TYPE skwf_error.
DATA: lt_serv_items TYPE TABLE OF ztreeview,
lv_xstring TYPE xstring.
DATA: lv_object_id TYPE crmt_object_id_db,
lv_processtype TYPE crmt_process_type_db.
CALL METHOD server->request->if_http_entity~get_form_fields
CHANGING
fields = lt_form_fields.
CALL METHOD server->request->if_http_entity~get_header_fields
CHANGING
fields = lt_header_fields.
lv_id = 'test_xml_download'.
*here, we check if the request came from a valid(current?) session.
*this will atleast prevent accessing data through a simple http GET query.
lv_uri = cl_crm_web_utility=>create_url( iv_path = '/sap/crm/test_xml'
iv_absolute = ' '
iv_query = ' '
iv_in_same_session = 'X'
iv_no_cookie = 'X'
iv_server_object = server ).
lv_path = server->request->if_http_entity~get_header_field( `~path` ).
CHECK lv_uri EQ lv_path.
* -> get HTTP request method
lv_request_method = server->request->if_http_entity~get_header_field( `~request_method` ).
CASE lv_request_method.
* -> HTTP WebDAV options
WHEN 'OPTIONS'.
server->response->set_header_field( name = 'Allow'
value = 'OPTIONS, TRACE, GET, HEAD, DELETE, COPY, MOVE, PROPFIND, PROPPATCH, SEARCH, SUBSCRIBE, UNSUBSCRIBE, POLL, BDELETE, BCOPY, BMOVE, BPROPPATCH, BPROPFIND, MKCOL, LOCK, UNLOCK' ).
server->response->set_header_field( name = 'Public'
value = 'OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH, SUBSCRIBE, UNSUBSCRIBE, POLL, BDELETE, BCOPY, BMOVE, BPROPPATCH, BPROPFIND' ).
* -> HTTP get method
WHEN 'GET' OR
'POST'.
CALL METHOD server->request->get_form_data
EXPORTING
name = 'id'
CHANGING
data = lv_id.
CALL METHOD server->request->get_form_data
EXPORTING
name = 'doc_id'
CHANGING
data = lv_doc_id.
lv_content = 'Test_bom_download.xml'.
CLEAR lv_content_type.
CLEAR lv_disp.
lv_content_type = 'text/plain; charset=UTF-16'.
CONCATENATE 'attachment;filename=' lv_doc_id INTO lv_disp.
lv_content_type = 'text/xml; charset=UTF-16'.
SELECT * FROM ztreeview INTO TABLE lt_serv_items.
CALL TRANSFORMATION ztest1
SOURCE rows = lt_serv_items
RESULT XML lv_xstring.
server->response->set_header_field( name = 'content-disposition' value = lv_disp ).
server->response->set_header_field( name = 'Cache-Control' value = '' ).
server->response->set_header_field( name = 'ContentType' value = lv_content_type ).
server->response->set_header_field( name = 'expires' value = '0' ).
server->response->set_data( data = lv_xstring ).
ENDCASE.
endmethod.
Transformation code. you have to create your transformation xslt_tool tcode and then call this transformation in your code.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" xmlns:asx="http://www.sap.com/abapxml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsd:annotation>
<xsd:documentation>
Treeview Log
</xsd:documentation>
</xsd:annotation>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction>
<?mso-application progid="Excel.Sheet"?>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="asx:values">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o=
"urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns=
"urn:schemas-microsoft-com:office:office">
<Author>deepika.chandrasehar</Author>
<LastAuthor>deepika.chandrasehar</LastAuthor>
<Created>2012-06-12T12:40:46Z</Created>
<Company>Accenture</Company>
<Version>
12.00</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>11820</WindowHeight>
<WindowWidth>19155</WindowWidth>
<WindowTopX>0</WindowTopX>
<WindowTopY>
45</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Arial" x:Family="Swiss"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s62">
<NumberFormat ss:Format="@"/>
</Style>
<Style ss:ID="s63">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:Bold="1" ss:FontName="Arial" ss:Size="12" x:Family="Swiss"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s64">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<NumberFormat ss:Format="Short Date"/>
</Style>
<Style ss:ID="s65">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<NumberFormat ss:Format="[$-409]m/d/yy\ h:mm\ AM/PM;@"/>
</Style>
<Style ss:ID="s66">
<Font ss:Bold="1" ss:Color="#FF0000" ss:FontName="Arial" x:Family="Swiss"/>
<NumberFormat ss:Format="@"/>
</Style>
<Style ss:ID="s67">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:Bold="1" ss:FontName="Arial" x:Family="Swiss"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s69">
<Font ss:FontName="Arial" x:Family="Swiss"/>
</Style>
<Style ss:ID="s70">
<Font ss:FontName="Arial" x:Family="Swiss"/>
<NumberFormat ss:Format="@"/>
</Style>
<Style ss:ID="s71">
<Font ss:Bold="1" ss:Color="#008080" ss:FontName="Arial" x:Family="Swiss"/>
<NumberFormat ss:Format="@"/>
</Style>
<Style ss:ID="s72">
<Font ss:Bold="1" ss:Color="#008000" ss:FontName="Arial" x:Family="Swiss"/>
<NumberFormat ss:Format="@"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1"> ->first worksheet
<Table ss:DefaultColumnWidth="60" ss:ExpandedColumnCount="10" ss:ExpandedRowCount="20000" x:FullColumns="1" x:FullRows="1">
<Column ss:Width="254.25"/>
<Column ss:StyleID="s62" ss:Width="114.75"/>
<Column ss:StyleID="s62" ss:Width="144"/>
<Column ss:Width="121.5"/>
<Column ss:Width="166.5"/>
<Column ss:Width="72.75"/>
<Column ss:StyleID="s62" ss:Width="567.75"/>
<Column ss:Width="90.75"/>
<Column ss:Width="99.75"/>
<Column ss:AutoFitWidth="0" ss:Width="108.75"/>
<Row>
<Cell ss:StyleID="s67">
<Data ss:Type="String">Document ID</Data>
</Cell>
<Cell ss:StyleID="s67">
<Data ss:Type="String">Document Description</Data>
</Cell>
<Cell ss:StyleID="s67">
<Data ss:Type="String">Parent ID</Data>
</Cell>
<Cell ss:StyleID="s67">
<Data ss:Type="String">Document Status</Data>
</Cell>
<Cell ss:StyleID="s67">
<Data ss:Type="String">Error Type</Data>
</Cell>
</Row>
<xsl:for-each select="ROWS/ZTREEVIEW"> ->ZTREEVIEW is structure name of the internal table
<Row ss:AutoFitHeight="0" ss:Height="15.75">
<Cell>
<Data ss:Type="Number">
<xsl:value-of select="DOC_ID"/> ->field names
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="DOC_DESC"/>
</Data>
</Cell>
<Cell>
<Data ss:Type="Number">
<xsl:value-of select="PARENT_ID"/>
</Data>
</Cell>
<Cell ss:StyleID="s64">
<Data ss:Type="String">
<xsl:value-of select="DOC_STATUS"/>
</Data>
</Cell>
<Cell ss:StyleID="s64"/>
<Cell ss:StyleID="s64">
<Data ss:Type="String">
<xsl:value-of select="DOC_ERROR_TYPE"/>
</Data>
</Cell>
<Cell ss:StyleID="s64"/>
</Row>
</xsl:for-each>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Header x:Margin="0.3"/>
<Footer x:Margin="0.3"/>
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top=
"0.75"/>
</PageSetup>
<Print>
<ValidPrinterInfo/>
<PaperSizeIndex>9</PaperSizeIndex>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<Selected/>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet2"> ->second worksheet
</Worksheet>
</Workbook>
</xsl:template>
</xsl:transform>
Regards,
Deepika.