Global $aFunc[7][4] = _
[[3], _
['Function Name', 'Index', 'Relative Address', 'Size'], _
['_FreeImage_GetImageType@4', '118', '0x00001180', '32'], _
['_FreeImage_GetRedMask@4', '130', '0x000011A0', '32'], _
['_FreeImage_GetGreenMask@4', '114', '0x000011C0', '32'], _
['_FreeImage_GetBlueMask@4', '91', '0x000011E0', '32'], _
['_FreeImage_HasBackgroundColor@4', '144', '0x00001200', '32']]
#cs
$a_Array - двухмерный массив данных
$s_Title - заголовок страницы
$i_Toggle - заголовок таблицы ( $Array[1][x] only )
1 - выводить
0 – не выводить
$i_Width - задаёт ширину таблицы в пикселях или процентах
(по умолчанию 100 %)
(ширина первой колонки 100%)
$s_OutHtmlFile - имя HTML файла на выходе (по умолчанию report.html)
$s_OutCssFile - имя CSS файла на выходе (по умолчанию стиль пишется в тэг HEAD)
#ce
;~ Example 1
_ReportHtmlTable($aFunc)
;~ Example 2
;~ _ReportHtmlTable($aFunc, 'Функции FreeImage', 0, '960 px', 'my_report.html', 'style.css')
#Region Function
Func _ReportHtmlTable($a_Array, $s_Title = '', $i_Toggle = 0, $i_Width = '', $s_OutHtmlFile = '', $s_OutCssFile = '')
#Region CSS template
Local $s_StyleTmp = 'body {color: #808080; font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px;}' & @CR _
&'table {' & @CR _
& @TAB &'margin: 10px auto;' & @CR _
& @TAB &'border-spacing: 0px;' & @CR _
& @TAB &'border-collapse: collapse;' & @CR _
& @TAB &'font-family: Arial;' & @CR _
& @TAB &'font-size: 12px;' & @CR _
&'}' & @CR _
&'td {' & @CR _
& @TAB &'padding: 4px 8px;' & @CR _
& @TAB &'border: 1px solid #808080;' & @CR _
& @TAB &'color: #808080;' & @CR _
&'}' & @CR _
&'th {padding: 4px;' & @CR _
& @TAB &'border: 1px solid #808080;' & @CR _
& @TAB &'font-width: bold;' & @CR _
& @TAB &'background-color: #c0c0c0;' & @CR _
& @TAB &'font-weight: bold;' & @CR _
& @TAB &'font-size: 14px;' & @CR _
& @TAB &'color: #ffffff;' & @CR _
& @TAB &'white-space: nowrap;' & @CR _
&'}' & @CR _
&'.first {' & @CR _
& @TAB &'width: 100%;' & @CR _
& @TAB &'text-align:left;' & @CR _
&'}' & @CR _
&'.second {' & @CR _
& @TAB &'text-align:center;' & @CR _
&'}' & @CR _
&'.row {' & @CR _
& @TAB &'background-color: #f1f1f1;' & @CR _
&'}'
#EndRegion CSS template
#Region Html template
Local $s_HtmlTmp = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' _
&'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">' _
&'<title>%title%</title>%style%</head><body>%body%</body></html>'
#EndRegion Html template
If UBound($a_Array, 0) <> 2 Then _
Return SetError(1, 0, 0)
If $i_Toggle >= 1 Then
$i_Toggle = 2
ElseIf $i_Toggle <= 0 Then
$i_Toggle = 1
EndIf
If Not $i_Width Then $i_Width = 100 &"%"
If Not $s_OutHtmlFile Then $s_OutHtmlFile = @ScriptDir &'\report.html'
Local $s_Date = StringFormat('%02d-%02d-%04d / %02d:%02d:%02d', @MDAY, @MON, @YEAR, @HOUR, @MIN, @SEC)
Local $i_Row = UBound($a_Array, 1)
Local $i_Col = UBound($a_Array, 2)
Local $s_Row
Local $s_Cell
; Создаём таблицу
For $r = $i_Toggle To $i_Row -1
For $c = 0 To $i_Col -1
Switch $i_Toggle
Case 1
$s_Cell &= '<th>'& $a_Array[$r][$c] &'</th>'
Case 2
If $c = 0 Then
$s_Class = 'first'
Else
$s_Class = 'second'
EndIf
If Not Mod($r, $i_Toggle) Then
$s_Cell &= '<td class="'& $s_Class &'">'& $a_Array[$r][$c] &'</td>'
Else
$s_Class &= ' row'
$s_Cell &= '<td class="'& $s_Class &'">'& $a_Array[$r][$c] &'</td>'
EndIf
EndSwitch
Next
$s_Row &= '<tr>'& $s_Cell &'</tr>'
$s_Cell = ""
$i_Toggle = 2
Next
; Пишем заголовок
If $s_Title = '' Then
$s_HtmlTmp = StringRegExpReplace($s_HtmlTmp, '%title%', 'Report created: ' & $s_Date)
Else
$s_HtmlTmp = StringRegExpReplace($s_HtmlTmp, '%title%', $s_Title)
EndIf
; Пишем стиль
If $s_OutCssFile = '' Then
$s_HtmlTmp = StringRegExpReplace($s_HtmlTmp, '%style%', '<style type="text/css">'& $s_StyleTmp &'</style>')
Else
If Not FileExists(@ScriptDir &"\"& $s_OutCssFile) Then
$s_HtmlTmp = StringRegExpReplace($s_HtmlTmp, '%style%', '<link rel="stylesheet" type="text/css" href="' & $s_OutCssFile & '">')
$h_File = FileOpen($s_OutCssFile, 2)
FileWrite($h_File, $s_StyleTmp)
FileClose($h_File)
Else
$s_HtmlTmp = StringRegExpReplace($s_HtmlTmp, '%style%', '<link rel="stylesheet" type="text/css" href="' & $s_OutCssFile & '">')
EndIf
EndIf
$s_HtmlTmp = StringRegExpReplace($s_HtmlTmp, '%body%', '<table border="0" width="'& $i_Width &'">'& $s_Row &'</table>')
; Пишем файл
$h_File = FileOpen($s_OutHtmlFile, 2)
FileWrite($h_File, BinaryToString(StringToBinary($s_HtmlTmp, 4)))
FileClose($h_File)
Return SetError(0, 0, 1)
EndFunc ;==>_ReportHtmlTable
#EndRegion Function