langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
121
Task/Create-an-HTML-table/NetRexx/create-an-html-table-1.netrexx
Normal file
121
Task/Create-an-HTML-table/NetRexx/create-an-html-table-1.netrexx
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
-- create some test data. Put the data in a Rexx indexed string
|
||||
maxI = 1000
|
||||
rng = Random()
|
||||
xyz = ''
|
||||
xyz[0] = 1; xyz[1] = '. X Y Z' -- use a dot to indicate an empty cell
|
||||
loop r_ = 1 for 5
|
||||
ra = r_ rng.nextInt(maxI) rng.nextInt(maxI) rng.nextInt(maxI)
|
||||
xyz[0] = r_ + 1; xyz[r_ + 1] = ra
|
||||
end r_
|
||||
|
||||
-- build an HTML string
|
||||
html = htmlHeader()
|
||||
html = html || htmlTable(xyz)
|
||||
html = html || htmlFooter()
|
||||
|
||||
-- display HTML at standard output device
|
||||
say html
|
||||
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-- HTML boilerplate header
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method htmlHeader() public static returns Rexx
|
||||
html = '<?xml version="1.0" encoding="UTF-8"?>\n' -
|
||||
|| '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' -
|
||||
|| '<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">\n' -
|
||||
|| '<head>\n' -
|
||||
|| '<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>\n' -
|
||||
|| '<title>RCreateHTMLTable</title>\n' -
|
||||
|| '<style type="text/css">\n' -
|
||||
|| '<!--\n' -
|
||||
|| '/* <![DATA[ */\n' -
|
||||
|| 'body {font-family: "Lucida Grande", "Geneva", "Verdana", "Helvetica Neue", "Helvetica", "DejaVu Sans", "Arial", sans-serif;}\n' -
|
||||
|| 'table, th, td {table-layout: fixed; border: 1px solid black; border-collapse: collapse; padding: 0.25em; font-size: 85%;}\n' -
|
||||
|| 'th, td {width: 6em;}\n' -
|
||||
|| 'th {color: white; background-color: green;}\n' -
|
||||
|| 'td {text-align: right;}\n' -
|
||||
|| 'p.classname {\n' -
|
||||
|| ' font-size: inherit;\n' -
|
||||
|| '}\n' -
|
||||
|| '/* ]] */\n' -
|
||||
|| '//-->\n' -
|
||||
|| '</style>\n' -
|
||||
|| '</head>\n' -
|
||||
|| '<body>\n' -
|
||||
|| '<h1>Rosetta Code – NetRexx Sample Output</h2>\n' -
|
||||
|| '<h2><a href="http://rosettacode.org/wiki/Create_an_HTML_table">Create an HTML table</a></h2>\n' -
|
||||
|| ''
|
||||
|
||||
return html
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-- HTML footer
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method htmlFooter() public static returns Rexx
|
||||
html = '</body>\n' -
|
||||
|| '</html>\n' -
|
||||
|| ''
|
||||
return html
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-- Create the table
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method htmlTable(rows, caption = '') public static returns Rexx
|
||||
html = '<table>\n'
|
||||
if caption.length() > 0 then do
|
||||
html = html -
|
||||
|| '<caption>'caption'</caption>\n' -
|
||||
|| '<thead>\n' -
|
||||
|| ''
|
||||
end
|
||||
html = html -
|
||||
|| htmlCsvTableRow(rows[1], 'th')'\n' -
|
||||
|| '</thead>\n' -
|
||||
|| '<tbody>\n' -
|
||||
|| ''
|
||||
loop r_ = 2 to rows[0]
|
||||
html = html -
|
||||
|| htmlCsvTableRow(rows[r_])
|
||||
end r_
|
||||
html = html -
|
||||
|| '</tbody>\n' -
|
||||
|| '</table>\n' -
|
||||
|| ''
|
||||
return html
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-- Add a row to the table
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method htmlCsvTableRow(row, tag = 'td', sep = ' ', emptyCell = '.') public static returns Rexx
|
||||
if tag = null then tag = 'td'
|
||||
row = row.strip('t')
|
||||
-- replace HTML special characters with symbol entities
|
||||
row = row.changestr('&', '&') -- need to do this one first to avoid double translation
|
||||
row = row.changestr('"', '"')
|
||||
row = row.changestr("'", ''')
|
||||
row = row.changestr('<', '<')
|
||||
row = row.changestr('>', '>')
|
||||
elmts = ''
|
||||
elmts[0] = 0
|
||||
e_ = 0
|
||||
loop while row.length() > 0
|
||||
parse row elmt (sep) row
|
||||
if elmt == emptyCell then elmt = ' ' -- replace empy cells with non-breaking spaces
|
||||
e_ = e_ + 1; elmts[0] = e_; elmts[e_] = elmt
|
||||
end
|
||||
html = '<tr>\n' -
|
||||
|| ''
|
||||
loop e_ = 1 to elmts[0]
|
||||
html = html -
|
||||
|| '<'tag'>'elmts[e_]'</'tag'>\n' -
|
||||
|| ''
|
||||
end e_
|
||||
html = html -
|
||||
|| '</tr>\n' -
|
||||
|| ''
|
||||
return html
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
|
||||
<title>RCreateHTMLTable</title>
|
||||
<style type="text/css">
|
||||
<!--
|
||||
/* <![DATA[ */
|
||||
body {font-family: "Lucida Grande", "Geneva", "Verdana", "Helvetica Neue", "Helvetica", "DejaVu Sans", "Arial", sans-serif;}
|
||||
table, th, td {table-layout: fixed; border: 1px solid black; border-collapse: collapse; padding: 0.25em; font-size: 85%;}
|
||||
th, td {width: 6em;}
|
||||
th {color: white; background-color: green;}
|
||||
td {text-align: right;}
|
||||
p.classname {
|
||||
font-size: inherit;
|
||||
}
|
||||
/* ]] */
|
||||
//-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Rosetta Code – NetRexx Sample Output</h2>
|
||||
<h2><a href="http://rosettacode.org/wiki/Create_an_HTML_table">Create an HTML table</a></h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>X</th>
|
||||
<th>Y</th>
|
||||
<th>Z</th>
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>626</td>
|
||||
<td>128</td>
|
||||
<td>386</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>985</td>
|
||||
<td>568</td>
|
||||
<td>636</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>639</td>
|
||||
<td>622</td>
|
||||
<td>591</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td>843</td>
|
||||
<td>268</td>
|
||||
<td>436</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>5</td>
|
||||
<td>132</td>
|
||||
<td>526</td>
|
||||
<td>251</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
; file: html-table.lsp
|
||||
; url: http://rosettacode.org/wiki/Create_an_HTML_table
|
||||
; author: oofoe 2012-01-29
|
||||
|
||||
(seed (time-of-day)) ; Initialize random number generator.
|
||||
|
||||
; The "tab" variable tracks the HTML indent. "pad" composes a line
|
||||
; with the appropriate indent and a terminal newline.
|
||||
|
||||
(setq tab 0)
|
||||
(define (pad text) (string (dup " " tab) text "\n"))
|
||||
|
||||
; NewLISP allows almost any character in an identifier, so I can name
|
||||
; my functions after the HTML elements they invoke. This one formats a
|
||||
; single table data cell.
|
||||
|
||||
(define (<td> text) (pad (string "<td>" text "</td>")))
|
||||
|
||||
; "<tr>" will accept either a number of arguments, each one to be
|
||||
; formatted as a table cell, or a single list argument, which is
|
||||
; broken into table cells. For convenience, I format each list item
|
||||
; with the "<td>" function so I can feed it raw lists.
|
||||
|
||||
(define (<tr>)
|
||||
(let ((data (args))
|
||||
(s (pad "<tr>")))
|
||||
|
||||
(if (list? (data 0)) (setq data (data 0)))
|
||||
|
||||
(inc tab)
|
||||
(dolist (el data) (extend s (<td> el)))
|
||||
(dec tab)
|
||||
|
||||
(extend s (pad "</tr>"))
|
||||
s))
|
||||
|
||||
; By defining "<table>" as a macro, I ensure that the rows won't be
|
||||
; evaluated until I've got the table started, which preserves the
|
||||
; formatting.
|
||||
|
||||
(define-macro (<table>)
|
||||
(let ((s (pad "<table>")))
|
||||
(inc tab) (doargs (row) (extend s (eval row))) (dec tab)
|
||||
(extend s (pad "</table>"))
|
||||
s
|
||||
))
|
||||
|
||||
; Test
|
||||
|
||||
(print (<table> (<tr> "" "X" "Y" "Z")
|
||||
(<tr> (cons 0 (rand 1000 3)))
|
||||
(<tr> (cons 1 (rand 1000 3)))
|
||||
(<tr> (cons 2 (rand 1000 3)))
|
||||
))
|
||||
|
||||
(exit)
|
||||
23
Task/Create-an-HTML-table/OCaml/create-an-html-table-1.ocaml
Normal file
23
Task/Create-an-HTML-table/OCaml/create-an-html-table-1.ocaml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
let () =
|
||||
let buf = Buffer.create 1 in
|
||||
let s = Buffer.add_string buf in
|
||||
Random.self_init();
|
||||
s "<table>";
|
||||
s "<thead align=\"right\">";
|
||||
s "<tr><th></th>";
|
||||
List.iter (fun v ->
|
||||
s ("<td>" ^ v ^ "</td>")
|
||||
) ["X"; "Y"; "Z"];
|
||||
s "</tr>";
|
||||
s "</thead>";
|
||||
s "<tbody align=\"right\">";
|
||||
for i = 0 to pred 3 do
|
||||
s ("<tr><td>" ^ string_of_int i ^ "</td>");
|
||||
for j = 0 to pred 3 do
|
||||
s ("<td>" ^ string_of_int (Random.int 1000) ^ "</td>");
|
||||
done;
|
||||
s "</tr>";
|
||||
done;
|
||||
s "</tbody>";
|
||||
s "</table>";
|
||||
print_endline (Buffer.contents buf)
|
||||
39
Task/Create-an-HTML-table/OCaml/create-an-html-table-2.ocaml
Normal file
39
Task/Create-an-HTML-table/OCaml/create-an-html-table-2.ocaml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
open XHTML.M_01_01
|
||||
|
||||
let _td s = td [pcdata s]
|
||||
let _th s = th [pcdata s]
|
||||
|
||||
let my_table =
|
||||
table ~a:[a_border 1]
|
||||
(tr
|
||||
(_th "") [
|
||||
(_th "X");
|
||||
(_th "Y");
|
||||
(_th "Z")]
|
||||
)
|
||||
[
|
||||
(tr
|
||||
(_td "1") [
|
||||
(_td "aa");
|
||||
(_td "bb");
|
||||
(_td "cc")]
|
||||
);
|
||||
(tr
|
||||
(_td "2") [
|
||||
(_td "dd");
|
||||
(_td "ee");
|
||||
(_td "ff")]
|
||||
);
|
||||
]
|
||||
|
||||
let my_page =
|
||||
html
|
||||
(head (title (pcdata "My Page")) [])
|
||||
(body
|
||||
[ h1 [pcdata "My Table"];
|
||||
my_table;
|
||||
]
|
||||
)
|
||||
|
||||
let () =
|
||||
pretty_print ~width:80 print_string my_page
|
||||
25
Task/Create-an-HTML-table/OCaml/create-an-html-table-3.ocaml
Normal file
25
Task/Create-an-HTML-table/OCaml/create-an-html-table-3.ocaml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#use "topfind"
|
||||
#require "tyxml"
|
||||
|
||||
module X = XHTML.M_01_01 (* XHTML 1.1 *)
|
||||
module P = XHTML.P_01_01
|
||||
|
||||
let make_table () =
|
||||
let td1 = X.td [X.pcdata "1"] in
|
||||
let td2 = X.td [X.pcdata "2"] in
|
||||
let td3 = X.td [X.pcdata "3"] in
|
||||
let my_tr = X.tr td1 [td2; td3] in
|
||||
let my_table = X.table my_tr [] in
|
||||
(my_table)
|
||||
|
||||
let () =
|
||||
let my_title = X.title (X.pcdata "My Page") in
|
||||
let my_head = X.head my_title [] in
|
||||
let my_h1 = X.h1 [X.pcdata "My Table"] in
|
||||
|
||||
let my_table = make_table () in
|
||||
|
||||
let my_body = X.body [my_h1; my_table] in
|
||||
let my_html = X.html my_head my_body in
|
||||
P.print print_endline my_html;
|
||||
;;
|
||||
11
Task/Create-an-HTML-table/OCaml/create-an-html-table-4.ocaml
Normal file
11
Task/Create-an-HTML-table/OCaml/create-an-html-table-4.ocaml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
let make_table () =
|
||||
let br = X.a_border 1 in
|
||||
let th s = X.th [X.pcdata s] in
|
||||
let td s = X.td [X.pcdata s] in
|
||||
let my_thead = X.thead (X.tr (th "") [th "X"; th "Y"; th "Z"]) [] in
|
||||
let my_tr1 = X.tr (td "1") [td "AAA"; td "BBB"; td "CCC"] in
|
||||
let my_tr2 = X.tr (td "2") [td "DDD"; td "EEE"; td "FFF"] in
|
||||
let my_tr3 = X.tr (td "3") [td "GGG"; td "HHH"; td "III"] in
|
||||
let my_tbody = X.tbody my_tr1 [my_tr2; my_tr3] in
|
||||
let my_table = X.tablex ~thead:my_thead ~a:[br] my_tbody [] in
|
||||
(my_table)
|
||||
41
Task/Create-an-HTML-table/Oz/create-an-html-table.oz
Normal file
41
Task/Create-an-HTML-table/Oz/create-an-html-table.oz
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
declare
|
||||
|
||||
[Roads] = {Module.link ['x-ozlib://wmeyer/roads/Roads.ozf']}
|
||||
|
||||
fun {Table Session}
|
||||
html(
|
||||
head(title("Show a table with row and column headings")
|
||||
style(type:"text/css"
|
||||
css(td 'text-align':center)
|
||||
))
|
||||
body(
|
||||
{TagFromList table
|
||||
tr(th th("X") th("Y") th("Z"))
|
||||
|
|
||||
{CreateRows 3 5}
|
||||
}))
|
||||
end
|
||||
|
||||
fun {CreateRows NumCols NumRows}
|
||||
{List.map {List.number 1 NumRows 1}
|
||||
fun {$ Row}
|
||||
{TagFromList tr
|
||||
td( {Int.toString Row} )
|
||||
|
|
||||
{List.map {List.number 1 NumCols 1}
|
||||
fun {$ Col}
|
||||
SequentialNumber = (Row-1)*NumCols + Col
|
||||
in
|
||||
td( {Int.toString SequentialNumber} )
|
||||
end
|
||||
}}
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
TagFromList = List.toTuple
|
||||
|
||||
in
|
||||
|
||||
{Roads.registerFunction table Table}
|
||||
{Roads.run}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
html(n=3)={
|
||||
print("<table>\n<tr><th></th><th>X</th><th>Y</th><th>Z</th></tr>");
|
||||
for(i=1,n,
|
||||
print1("<tr><td>"i"</td>");
|
||||
for(j=1,3,print1("<td>"random(9999)"</td>"));
|
||||
print("</tr>")
|
||||
);
|
||||
print("</table>")
|
||||
};
|
||||
|
|
@ -0,0 +1 @@
|
|||
printtex(matrix(4,4,i,j,if(i==1,if(j==1,"",Strchr(86+j)),if(j==1,i,random(9999)))))
|
||||
44
Task/Create-an-HTML-table/PL-I/create-an-html-table.pli
Normal file
44
Task/Create-an-HTML-table/PL-I/create-an-html-table.pli
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* Create an HTML table. 6/2011 */
|
||||
|
||||
create: procedure options (main);
|
||||
|
||||
|
||||
create_table: procedure (headings, table_contents);
|
||||
|
||||
declare headings(*) character (10) varying;
|
||||
declare table_contents(*, *) fixed;
|
||||
declare (i, row, col) fixed;
|
||||
|
||||
put skip edit ('<table>') (a);
|
||||
/* Headings. */
|
||||
put skip edit ('<tr><th></th> ') (a);
|
||||
/* For an empty column heading */
|
||||
do i = 1 to hbound(headings);
|
||||
put edit ('<th>', headings(i), '</th> ' ) (a);
|
||||
end;
|
||||
put edit ('</tr>') (a);
|
||||
|
||||
/* Table contents. */
|
||||
|
||||
do row = 1 to hbound(table_contents, 1);
|
||||
/* row number */
|
||||
put skip edit ('<tr><td>', row, '</td> ') (a);
|
||||
/* row contents */
|
||||
do col = 1 to hbound(table_contents, 2);
|
||||
put edit ('<td>', table_contents(row, col), '</td> ' ) (a);
|
||||
end;
|
||||
put edit ('</tr>') (a);
|
||||
end;
|
||||
put skip edit ('</table>' ) (a);
|
||||
end create_table;
|
||||
|
||||
declare headings (3) character (1) static initial ('X', 'Y', 'Z');
|
||||
|
||||
declare table_contents(3, 3) fixed static initial (
|
||||
4, -3, 8,
|
||||
7, 2, -6,
|
||||
11, 1, 15);
|
||||
|
||||
call create_table (headings, table_contents);
|
||||
|
||||
end create;
|
||||
13
Task/Create-an-HTML-table/Perl-6/create-an-html-table.pl6
Normal file
13
Task/Create-an-HTML-table/Perl-6/create-an-html-table.pl6
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
my @header = < X Y Z>;
|
||||
my $rows = 5;
|
||||
|
||||
sub tag ($tag, $string, $param?) { return "<$tag" ~ ($param ?? " $param" !! '') ~ ">$string" ~ "</$tag>" };
|
||||
|
||||
my $table = tag('tr', ( tag('th', $_) for @header));
|
||||
|
||||
for 1 .. $rows -> $row {
|
||||
$table ~= tag('tr', ( tag('td', $row, 'align="right"')
|
||||
~ (tag('td', (^10000).pick, 'align="right"') for 1..^@header)));
|
||||
}
|
||||
|
||||
say tag('table', $table, 'cellspacing=4 style="text-align:right; border: 1px solid;"');
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<@ SDCLIT>
|
||||
<@ DTBLIT>
|
||||
<@ DTRLITLIT>
|
||||
<@ DTDLITLIT>|[style]background-color:white</@>
|
||||
<@ DTD>X</@>
|
||||
<@ DTD>Y</@>
|
||||
<@ DTD>Z</@>|[style]width:100%; background-color:brown;color:white; text-align:center</@>
|
||||
<@ ITEFORLIT>10|
|
||||
<@ DTRLITCAP>
|
||||
<@ DTDPOSFORLIT>...|[style]background-color:Brown; color:white; text-align:right</@>
|
||||
<@ DTDCAPLIT><@ SAYR!ILI2>1|9999</@>|[style]width:50;text-align:right</@>
|
||||
<@ DTDCAPLIT><@ SAYR!ILI2>1|9999</@>|[style]width:50;text-align:right</@>
|
||||
<@ DTDCAPLIT><@ SAYR!ILI2>1|9999</@>|[style]width:50;text-align:right</@>
|
||||
|[style]background-color:white;color:black</@>
|
||||
</@>
|
||||
</@>
|
||||
|Number Table</@>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import IO;
|
||||
import util::Math;
|
||||
|
||||
str html(str title, str content) = item("html", item("title", title) + item("body", content));
|
||||
str item(str op, str content) = "\<<op>\><content>\</<op>\>";
|
||||
str table(str content) = item("table border=\"0\"", content);
|
||||
str tr(str content) = item("tr", content);
|
||||
str td(str content) = item("td", content);
|
||||
|
||||
public str generateTable(int rows){
|
||||
int i(){return arbInt(10000);};
|
||||
rows = (tr(td("")+td("X")+td("Y")+td("Z"))
|
||||
| it + tr(td("<x>")+td("<i()>")+td("<i()>")+td("<i()>"))
|
||||
| x <- [1..rows]);
|
||||
writeFile(|file:///location|,
|
||||
html("Rosetta Code Table", table(rows)));
|
||||
return "written";
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
rascal>generateTable(10)
|
||||
str: "written"
|
||||
|
|
@ -0,0 +1 @@
|
|||
<html><title>Rosetta Code Table</title><body><table border="0"><tr><td></td><td>X</td><td>Y</td><td>Z</td></tr><tr><td>1</td><td>253</td><td>3988</td><td>3208</td></tr><tr><td>2</td><td>315</td><td>2014</td><td>47</td></tr><tr><td>3</td><td>749</td><td>3379</td><td>1076</td></tr><tr><td>4</td><td>241</td><td>3211</td><td>1848</td></tr><tr><td>5</td><td>1</td><td>1605</td><td>6469</td></tr><tr><td>6</td><td>599</td><td>1243</td><td>1189</td></tr><tr><td>7</td><td>741</td><td>4709</td><td>2854</td></tr><tr><td>8</td><td>918</td><td>482</td><td>7160</td></tr><tr><td>9</td><td>451</td><td>572</td><td>6229</td></tr><tr><td>10</td><td>955</td><td>7970</td><td>9684</td></tr></table border="0"></body></html>
|
||||
13
Task/Create-an-HTML-table/Retro/create-an-html-table.retro
Normal file
13
Task/Create-an-HTML-table/Retro/create-an-html-table.retro
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
needs casket::html'
|
||||
with casket::html'
|
||||
|
||||
: rnd ( -$ ) random 1000 mod toString ;
|
||||
|
||||
[ [ [ ] td [ "x" ] td [ "y" ] td [ "z" ] td ] tr
|
||||
[ [ "1" ] td [ rnd ] td [ rnd ] td [ rnd ] td ] tr
|
||||
[ [ "2" ] td [ rnd ] td [ rnd ] td [ rnd ] td ] tr
|
||||
[ [ "3" ] td [ rnd ] td [ rnd ] td [ rnd ] td ] tr
|
||||
[ [ "4" ] td [ rnd ] td [ rnd ] td [ rnd ] td ] tr
|
||||
[ [ "5" ] td [ rnd ] td [ rnd ] td [ rnd ] td ] tr
|
||||
[ [ "6" ] td [ rnd ] td [ rnd ] td [ rnd ] td ] tr
|
||||
] table
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
html "<table border=1><tr align=center><td>Row</td><td>X</td><td>Y</td><td>Z</td></tr>"
|
||||
for i = 1 to 5
|
||||
html "<tr align=right>"
|
||||
for j = 1 to 4
|
||||
if j = 1 then html "<td>";i;"</td>" else html "<td>";i;j;"</td>"
|
||||
next j
|
||||
html "</tr>"
|
||||
next i
|
||||
html "</table>"
|
||||
18
Task/Create-an-HTML-table/Seed7/create-an-html-table.seed7
Normal file
18
Task/Create-an-HTML-table/Seed7/create-an-html-table.seed7
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var integer: line is 0;
|
||||
var integer: column is 0;
|
||||
begin
|
||||
writeln("<table style=\"text-align:center; border: 1px solid\">");
|
||||
writeln("<tr><th></th><th>X</th><th>Y</th><th>Z</th></tr>");
|
||||
for line range 1 to 3 do
|
||||
write("<tr><th>" <& line <& "</th>");
|
||||
for column range 1 to 3 do
|
||||
write("<td>" <& rand(0, 9999) <& "</td>");
|
||||
end for;
|
||||
writeln("</tr>");
|
||||
end for;
|
||||
writeln("</table>")
|
||||
end func;
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
$$ MODE TUSCRIPT
|
||||
tablefile="table.html"
|
||||
ERROR/STOP CREATE (tablefile,FDF-o,-std-)
|
||||
ACCESS d: WRITE/ERASE/RECORDS/utf8 $tablefile s,tablecontent
|
||||
tablecontent=*
|
||||
WRITE d "<!DOCTYPE html system>"
|
||||
WRITE d "<html><head><title>create html table</title></head>"
|
||||
WRITE d "<body><table><thead align='right'>"
|
||||
WRITE d "<tr><th> </th><th>x</th><th>y</th><th>z</th></tr>"
|
||||
WRITE d "</thead>"
|
||||
WRITE d "<tbody align='right'>"
|
||||
LOOP n=1,5
|
||||
x=RANDOM_NUMBERS (1,9999,1)
|
||||
y=RANDOM_NUMBERS (1,9999,1)
|
||||
z=RANDOM_NUMBERS (1,9999,1)
|
||||
WRITE d "<tr><td>{n}</td><td>{x}</td><td>{y}</td><td>{z}</td></tr>"
|
||||
ENDLOOP
|
||||
WRITE d "</tbody></table></body></html>"
|
||||
ENDACCESS d
|
||||
BROWSE $tablefile
|
||||
54
Task/Create-an-HTML-table/VBA/create-an-html-table.vba
Normal file
54
Task/Create-an-HTML-table/VBA/create-an-html-table.vba
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
Public Sub BuildHTMLTable()
|
||||
'simple HTML table, represented as a string matrix "cells"
|
||||
Const nRows = 6
|
||||
Const nCols = 4
|
||||
Dim cells(1 To nRows, 1 To nCols) As String
|
||||
Dim HTML As String 'the HTML table
|
||||
Dim temp As String
|
||||
Dim attr As String
|
||||
|
||||
' fill table
|
||||
' first row with titles
|
||||
cells(1, 1) = ""
|
||||
cells(1, 2) = "X"
|
||||
cells(1, 3) = "Y"
|
||||
cells(1, 4) = "Z"
|
||||
'next rows with index & random numbers
|
||||
For i = 2 To nRows
|
||||
cells(i, 1) = Format$(i - 1)
|
||||
For j = 2 To nCols
|
||||
cells(i, j) = Format$(Int(Rnd() * 10000))
|
||||
Next j
|
||||
Next i
|
||||
|
||||
'build the HTML
|
||||
HTML = ""
|
||||
For i = 1 To nRows
|
||||
temp = ""
|
||||
'first row as header row
|
||||
If i = 1 Then attr = "th" Else attr = "td"
|
||||
For j = 1 To nCols
|
||||
temp = temp & HTMLWrap(cells(i, j), attr)
|
||||
Next j
|
||||
HTML = HTML & HTMLWrap(temp, "tr")
|
||||
Next i
|
||||
HTML = HTMLWrap(HTML, "table", "style=""text-align:center; border: 1px solid""")
|
||||
Debug.Print HTML
|
||||
End Sub
|
||||
|
||||
Public Function HTMLWrap(s As String, tag As String, ParamArray attributes()) As String
|
||||
'returns string s wrapped in HTML tag with optional "attribute=value" strings
|
||||
'ex.: HTMLWrap("Link text", "a", "href=""http://www.somesite.org""")
|
||||
'returns: <a href="http://www.somesite.org">Link text</a>
|
||||
|
||||
Dim sOpenTag As String
|
||||
Dim sClosingTag As String
|
||||
|
||||
sOpenTag = "<" & tag
|
||||
For Each attr In attributes
|
||||
sOpenTag = sOpenTag & " " & attr
|
||||
Next
|
||||
sOpenTag = sOpenTag & ">"
|
||||
sClosingTag = "</" & tag & ">"
|
||||
HTMLWrap = sOpenTag & s & sClosingTag
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue