매개변수 | 유형 | 값전달 | 선택적 | 타자 | 참조유형 | 기본값 | 내역 |
I_ITAB | Importing | Type Ref To | DATA | ||||
I_HEADER | Importing | V | V | Type | EXTDFIEST | DD Internal: Information on Table Fields | |
I_TABLE_EXPORT | Importing | V | V | Type | ABAP_BOOL | ABAP_FALSE | |
I_ADDITIONAL_HTML | Importing | V | V | Type | STRING | Additional HTML Data | |
E_XSTRING | Exporting | V | Type | XSTRING | |||
E_STRING | Exporting | V | Type | STRING | |||
E_XSTRING_TABLE | Exporting | V | Type | XSTRING | |||
E_STRING_TABLE | Exporting | V | Type | STRING |
method convert_itab_to_html .
** HEADER column number and ITAB column number should be same **
** HEADER column order and ITAB column order should be same **
data: l_string type string,
l_style type string.
data: lapp_type type char30,
str type string,
l_header type extdfies.
data: date_created type string,
s_tst type timestamp,
c_tst(15) type c.
data: html type string.
data: html_table type string.
****Setup the Application type for Character Set Conversion to Binary String
" -- original source broken korean character >>
"lapp_type = 'text/html; charset=ks_c_5601-1987'.
" -- it changed original source >>
"lapp_type = 'text/html; '.
field-symbols: <tab> type table,
<wa> type any,
<f> type any,
<r> type any.
****Get Reference to our Internal Table
assign i_itab->* to <tab>.
***Read the Table Structure
data: struct type extdfiest.
field-symbols <wa_desc> like line of struct.
call method me->get_table_structure
exporting
i_itab = i_itab
receiving
e_struct = struct.
** make time stamp
get time stamp field s_tst.
c_tst = s_tst.
concatenate c_tst(4) '-' c_tst+4(2) '-' c_tst+6(2) 'T' c_tst+8(2)
':' c_tst+10(2) ':' c_tst+12(2) 'Z' into date_created.
**** make html
** <html> & Office xml namespace
concatenate
``
`<html xmlns:o="urn:schemas-microsoft-com:office:office"`
` xmlns:x="urn:schemas-microsoft-com:office:excel"`
` xmlns="http://www.w3.org/TR/REC-html40">`
cl_abap_char_utilities=>cr_lf
into html.
** html header
concatenate html
`<head>`
"`<meta http-equiv=Content-Type content="text/html; charset=ks_c_5601-1987">`
`<meta name=ProgId content=Excel.Sheet>`
`<meta name=Generator content="Microsoft Excel 11">`
into html separated by cl_abap_char_utilities=>cr_lf.
** Excel Document Info xml data.
concatenate html
``
`<!--[if gte mso 9]><xml>` cl_abap_char_utilities=>cr_lf
` <o:DocumentProperties>` cl_abap_char_utilities=>cr_lf
` <o:Author>` sy-uname `</o:Author>` cl_abap_char_utilities=>cr_lf
` <o:Created>` date_created `</o:Created>` cl_abap_char_utilities=>cr_lf
` <o:LastSaved>` date_created `</o:LastSaved>` cl_abap_char_utilities=>cr_lf
into html.
concatenate html
` <o:Company>Excel via BSP</o:Company>`
` </o:DocumentProperties>`
`</xml><![endif]-->`
into html separated by cl_abap_char_utilities=>cr_lf.
** Office html CSSstyle
concatenate html
``
`<style>`
`<!--table`
` {mso-displayed-decimal-separator:"\.";`
` mso-displayed-thousand-separator:"\,";}`
`@page`
` {margin:.98in .79in .98in .79in;`
` mso-header-margin:.49in;`
` mso-footer-margin:.49in;}`
`tr`
` {mso-height-source:auto;`
` mso-ruby-visibility:none;}`
`col`
` {mso-width-source:auto;`
` mso-ruby-visibility:none;}`
`br`
` {mso-data-placement:same-cell;}`
`.style0`
` {mso-number-format:General;`
` text-align:general;`
` vertical-align:bottom;`
` white-space:nowrap;`
` mso-rotate:0;`
` mso-background-source:auto;`
` mso-pattern:auto;`
` color:windowtext;`
` font-size:9.0pt;`
` font-weight:400;`
` font-style:normal;`
` text-decoration:none;`
` font-family:Arial, sans-serif;`
` mso-generic-font-family:auto;`
` mso-font-charset:129;`
` border:none;`
` mso-protection:locked visible;`
` mso-style-name:Standard;`
` mso-style-id:0;}`
`td`
` {mso-style-parent:style0;`
` padding-top:1px;`
` padding-right:1px;`
` padding-left:1px;`
` mso-ignore:padding;`
` color:windowtext;`
` font-weight:400;`
` font-style:normal;`
` text-decoration:none;`
` font-family:Arial, sans-serif;`
` mso-generic-font-family:auto;`
` mso-font-charset:0;`
` mso-number-format:General;`
` text-align:general;`
` vertical-align:bottom;`
` border:.5pt solid windowtext;`
` mso-pattern:auto;`
` mso-protection:locked visible;`
` white-space:nowrap;`
` mso-rotate:0;}`
`.xl24` "Packed/Float Data type
` {mso-style-parent:style0;`
` mso-number-format:"\#\,\#\#0\.00_ ";}`
`.xl25` "Integer Type
` {mso-style-parent:style0;`
` mso-number-format:"\#\,\#\#0_ ";}`
`.xl26` "Currency Type
` {mso-style-parent:style0;`
` mso-number-format:"\#\,\#\#0";} `
`.xl27`
` {mso-style-parent:style0;`
` font-weight:700;`
` border:.5pt solid windowtext;`
` background:silver;`
` mso-pattern:auto none;}`
`ruby`
` {ruby-align:left;}`
`rt`
` {color:windowtext;`
` font-size:8.0pt;`
` font-weight:400;`
` font-style:normal;`
` text-decoration:none;`
` font-family:돋움, monospace;`
` mso-font-charset:129;`
` mso-char-type:none;`
` display:none;}`
`-->`
`</style>`
into html separated by cl_abap_char_utilities=>cr_lf.
** Office Excel Workbook & Sheet info xml data.
concatenate html
``
`<!--[if gte mso 9]><xml>`
` <x:ExcelWorkbook>`
` <x:ExcelWorksheets>`
` <x:ExcelWorksheet>`
` <x:Name>Sheet1</x:Name>`
` <x:WorksheetOptions>`
` <x:ProtectContents>False</x:ProtectContents>`
` <x:ProtectObjects>False</x:ProtectObjects>`
` <x:ProtectScenarios>False</x:ProtectScenarios>`
` </x:WorksheetOptions>`
` </x:ExcelWorksheet>`
` </x:ExcelWorksheets>`
` <x:ProtectStructure>False</x:ProtectStructure>`
` <x:ProtectWindows>False</x:ProtectWindows>`
` </x:ExcelWorkbook>`
`</xml><![endif]-->`
`</head>`
into html separated by cl_abap_char_utilities=>cr_lf.
** Start Body html
concatenate html
``
`<body link=blue vlink=purple>`
`<table x:str border=1 cellpadding=0 cellspacing=0 width="100%" style='border-width:.05pt;border-collapse:collapse'>`
`<col style='mso-width-source:userset;mso-width-alt:800'>`
``
into html separated by cl_abap_char_utilities=>cr_lf.
if i_table_export eq abap_true.
concatenate html_table
`<table x:str border=1 cellpadding=0 cellspacing=0 width="100%" style='border-width:.05pt;border-collapse:collapse'>`
`<col style='mso-width-source:userset;mso-width-alt:800'>`
``
into html_table separated by cl_abap_char_utilities=>cr_lf.
endif.
if i_header[] is initial.
i_header[] = struct[].
endif.
** make header html <col>
loop at i_header into l_header.
concatenate html `<col style='mso-width-source:userset'>`
cl_abap_char_utilities=>cr_lf
into html.
endloop.
if i_table_export eq abap_true.
loop at i_header into l_header.
concatenate html_table `<col style='mso-width-source:userset'>`
cl_abap_char_utilities=>cr_lf into html_table.
endloop.
endif.
** make header html <tr><td>...</td></tr>
concatenate html
``
`<tr height=17 style='height:12.75pt'>`
* `<td></td>`
cl_abap_char_utilities=>cr_lf
into html separated by cl_abap_char_utilities=>cr_lf.
loop at i_header into l_header.
concatenate html `<td class=xl27 style="font-weight:700">`
l_header-coltitle
`</td>`
cl_abap_char_utilities=>cr_lf
into html.
endloop.
if i_table_export eq abap_true.
concatenate html_table
``
`<tr height=17 style='height:12.75pt'>`
* `<td></td>`
cl_abap_char_utilities=>cr_lf
into html_table separated by cl_abap_char_utilities=>cr_lf.
loop at i_header into l_header.
concatenate html_table `<td class=xl27 style="font-weight:700">`
l_header-coltitle
`</td>`
cl_abap_char_utilities=>cr_lf
into html_table.
endloop.
endif.
concatenate html
`</tr>`
cl_abap_char_utilities=>cr_lf
into html.
if i_table_export eq abap_true.
concatenate html_table
`</tr>`
cl_abap_char_utilities=>cr_lf
into html_table.
endif.
** make body
data: output type string.
data: s(256) type c.
data: l_css type string.
data: l_page type ref to cl_bsp_page_base.
create object l_page.
*****Loop through the Data Table
loop at <tab> assigning <wa>.
****For each component (field) in the table -Output the data
loop at struct assigning <wa_desc>.
assign component sy-tabix of structure <wa> to <f>.
check sy-subrc = 0.
if <wa_desc> is assigned and <wa_desc>-convexit is not initial.
****Process any output conversion routines
concatenate 'CONVERSION_EXIT_' <wa_desc>-convexit '_OUTPUT' into str.
call function str
exporting
input = <f>
importing
output = s.
**** If <F> has conversion routines, <F> is character type.
concatenate `<td style="mso-number-format:'\@'">`
s
into s.
else.
****Use the BSP Page - to string Method to output any data type as a string
****INTTYPE is ABAP Data type
case <wa_desc>-inttype.
* - Packed number : Check Currency
when 'P'.
"Currency
if ( <wa_desc>-datatype eq 'CURR' and
( <wa_desc>-reftable is not initial and <wa_desc>-reffield is not initial ) ).
"try to get currency value in current work area
assign component <wa_desc>-reffield of structure <wa> to <r>.
if sy-subrc eq 0.
"currency value found
s = l_page->if_bsp_page~to_string( value = <f>
format = l_page->if_bsp_page~co_format_currency
reference_value = <r> ).
else.
"default Currency - KRW
s = l_page->if_bsp_page~to_string( value = <f>
format = l_page->if_bsp_page~co_format_currency
reference_value = 'KRW' ).
endif.
l_css = 'x126'. "currency css
replace all occurrences of ',' in s with space.
condense s no-gaps.
if <wa_desc>-sign eq 'X'.
call function 'CLOI_PUT_SIGN_IN_FRONT'
changing
value = s.
endif.
concatenate `<td class=`
l_css
` x:num="`
s
`">`
s
into s.
else.
"other - normal Packed Number
l_css = 'x124'. "Packed/Float css
move <f> to s.
condense s.
if <wa_desc>-sign eq 'X'.
call function 'CLOI_PUT_SIGN_IN_FRONT'
changing
value = s.
endif.
concatenate `<td class=`
l_css
` x:num="`
s
`">`
s
into s.
endif.
* - Float
when 'F'.
s = l_page->if_bsp_page~to_string( value = <f> ).
move <f> to s.
condense s.
if <wa_desc>-sign eq 'X'.
call function 'CLOI_PUT_SIGN_IN_FRONT'
changing
value = s.
endif.
concatenate `<td class=x124 x:num="`
s
`">`
s
into s.
* - Integer
when 'I' or 'N' or 'b' or 's'.
move <f> to s.
condense s.
if <wa_desc>-sign eq 'X'.
call function 'CLOI_PUT_SIGN_IN_FRONT'
changing
value = s.
endif.
concatenate `<td class=x125 x:num="`
s
`">`
s
into s.
* - Date
when 'D'.
s = l_page->if_bsp_page~to_string( value = <f>
format = l_page->if_bsp_page~co_format_long ).
concatenate `<td style="mso-number-format:'\@';">`
s
into s.
* Time
when 'T'.
s = l_page->if_bsp_page~to_string( value = <f> ).
concatenate `<td style='mso-number-format:"hh\:mm\:ss"'>`
s
into s.
* Other - Character \@ is TEXT type of Excel Cell. No TO_STRING Conversion
when others.
concatenate `<td style="mso-number-format:'\@'">`
<f>
into s.
endcase.
endif.
if s is initial.
concatenate `<td style="mso-number-format:'\@'">`
s
into s.
endif.
** make column
concatenate l_string
s
`</td>`
cl_abap_char_utilities=>cr_lf
into l_string.
clear : s,l_css.
endloop.
** make row
concatenate html
cl_abap_char_utilities=>cr_lf
`<tr height=17 style='height:12.75pt'>`
* cl_abap_char_utilities=>cr_lf
* `<td class=x127></td>`
cl_abap_char_utilities=>cr_lf
l_string
`</tr>`
cl_abap_char_utilities=>cr_lf
into html.
if i_table_export eq abap_true.
concatenate html_table
cl_abap_char_utilities=>cr_lf
`<tr height=17 style='height:12.75pt'>`
* cl_abap_char_utilities=>cr_lf
* `<td class=x127></td>`
cl_abap_char_utilities=>cr_lf
l_string
`</tr>`
cl_abap_char_utilities=>cr_lf
into html_table.
endif.
clear l_string.
endloop.
** end of html
concatenate html
` </table>`
into html separated by cl_abap_char_utilities=>cr_lf.
if i_table_export eq abap_true.
concatenate html_table
` </table>`
into html_table separated by cl_abap_char_utilities=>cr_lf.
endif.
* Additional HTML Code added here
if i_additional_html is not initial.
concatenate html
`<br/>`
i_additional_html
` </body>`
`</html>`
into html separated by cl_abap_char_utilities=>cr_lf.
else.
concatenate html
` </body>`
`</html>`
into html separated by cl_abap_char_utilities=>cr_lf.
endif.
** return html data by string format
e_string = html.
***Convert the string to Binary string (euc-kr)
call function 'SCMS_STRING_TO_XSTRING'
exporting
text = html
mimetype = lapp_type
importing
buffer = e_xstring
exceptions
failed = 1
others = 2.
if i_table_export eq abap_true.
e_string_table = html_table.
call function 'SCMS_STRING_TO_XSTRING'
exporting
text = html_table
mimetype = lapp_type
importing
buffer = e_xstring_table
exceptions
failed = 1
others = 2.
endif.
endmethod.
위 클래스 사용법은 예시글에 있음
'SAP > BSP' 카테고리의 다른 글
BSP - ZIP 파일 생성(여러개 파일을 묶어서 다운로드) (0) | 2010.04.09 |
---|---|
BSP - 엑셀 다운로드 예시 (0) | 2010.04.08 |
Table View에 사용되는 스타일 시트 (0) | 2008.06.05 |
Table View에 관하여.... (0) | 2008.06.05 |
BSP디버깅 (0) | 2008.05.17 |