昨天我们做的Table具有了Print方法,可以简单的打印数据。
现在我需要一个Table,可以把Table中的数据以Html的Table的格式输出。
而我只需要重写Print方法
 1Table是怎样炼成的:HtmlTablepublic class HtmlTable : Table
 2    }

现在我将SaleReport改继承HtmlTable(参见Table是怎样炼成的:SaleReport Table的继承者 ),其他都不要改动。
然后我们运行该SaleReport

 1Table是怎样炼成的:HtmlTable            SaleReport report = new SaleReport("销售台帐");
 2Table是怎样炼成的:HtmlTable            report.AddRecord("Alex""Phone"2600);
 3Table是怎样炼成的:HtmlTable            report.AddRecord("Alex""PC"4560);
 4Table是怎样炼成的:HtmlTable            report.AddRecord("Alex""Table"234);
 5Table是怎样炼成的:HtmlTable            report.AddRecord("Sidney""Phone"2100);
 6Table是怎样炼成的:HtmlTable            report.AddRecord("Sidney""TV"4500);
 7Table是怎样炼成的:HtmlTable            report.AddRecord("Tom""oven"300);
 8Table是怎样炼成的:HtmlTable            report.AddRecord("Leo""oven"240);
 9Table是怎样炼成的:HtmlTable
10Table是怎样炼成的:HtmlTable            report.Print();

运行的结果是

 1Table是怎样炼成的:HtmlTable<table>
 2Table是怎样炼成的:HtmlTable<thead>
 3Table是怎样炼成的:HtmlTable<tr>
 4Table是怎样炼成的:HtmlTable<th>序号</th>
 5Table是怎样炼成的:HtmlTable<th>姓名</th>
 6Table是怎样炼成的:HtmlTable<th>商品名称</th>
 7Table是怎样炼成的:HtmlTable<th>日期</th>
 8Table是怎样炼成的:HtmlTable<th>数量</th>
 9Table是怎样炼成的:HtmlTable</tr>
10Table是怎样炼成的:HtmlTable</thead>
11Table是怎样炼成的:HtmlTable<tr>
12Table是怎样炼成的:HtmlTable<td>1</td>
13Table是怎样炼成的:HtmlTable<td>Alex</td>
14Table是怎样炼成的:HtmlTable<td>Phone</td>
15Table是怎样炼成的:HtmlTable<td>2007-2-14 20:39:31</td>
16Table是怎样炼成的:HtmlTable<td>2600</td>
17Table是怎样炼成的:HtmlTable</tr>
18Table是怎样炼成的:HtmlTable<tr>
19Table是怎样炼成的:HtmlTable<td>2</td>
20Table是怎样炼成的:HtmlTable<td>Alex</td>
21Table是怎样炼成的:HtmlTable<td>PC</td>
22Table是怎样炼成的:HtmlTable<td>2007-2-14 20:39:31</td>
23Table是怎样炼成的:HtmlTable<td>4560</td>
24Table是怎样炼成的:HtmlTable</tr>
25Table是怎样炼成的:HtmlTable<tr>
26Table是怎样炼成的:HtmlTable<td>3</td>
27Table是怎样炼成的:HtmlTable<td>Alex</td>
28Table是怎样炼成的:HtmlTable<td>Table</td>
29Table是怎样炼成的:HtmlTable<td>2007-2-14 20:39:31</td>
30Table是怎样炼成的:HtmlTable<td>234</td>
31Table是怎样炼成的:HtmlTable</tr>
32Table是怎样炼成的:HtmlTable<tr>
33Table是怎样炼成的:HtmlTable<td>4</td>
34Table是怎样炼成的:HtmlTable<td>Sidney</td>
35Table是怎样炼成的:HtmlTable<td>Phone</td>
36Table是怎样炼成的:HtmlTable<td>2007-2-14 20:39:31</td>
37Table是怎样炼成的:HtmlTable<td>2100</td>
38Table是怎样炼成的:HtmlTable</tr>
39Table是怎样炼成的:HtmlTable<tr>
40Table是怎样炼成的:HtmlTable<td>5</td>
41Table是怎样炼成的:HtmlTable<td>Sidney</td>
42Table是怎样炼成的:HtmlTable<td>TV</td>
43Table是怎样炼成的:HtmlTable<td>2007-2-14 20:39:31</td>
44Table是怎样炼成的:HtmlTable<td>4500</td>
45Table是怎样炼成的:HtmlTable</tr>
46Table是怎样炼成的:HtmlTable<tr>
47Table是怎样炼成的:HtmlTable<td>6</td>
48Table是怎样炼成的:HtmlTable<td>Tom</td>
49Table是怎样炼成的:HtmlTable<td>oven</td>
50Table是怎样炼成的:HtmlTable<td>2007-2-14 20:39:31</td>
51Table是怎样炼成的:HtmlTable<td>300</td>
52Table是怎样炼成的:HtmlTable</tr>
53Table是怎样炼成的:HtmlTable<tr>
54Table是怎样炼成的:HtmlTable<td>7</td>
55Table是怎样炼成的:HtmlTable<td>Leo</td>
56Table是怎样炼成的:HtmlTable<td>oven</td>
57Table是怎样炼成的:HtmlTable<td>2007-2-14 20:39:31</td>
58Table是怎样炼成的:HtmlTable<td>240</td>
59Table是怎样炼成的:HtmlTable</tr>
60Table是怎样炼成的:HtmlTable</table>

现在我们得到了一个可以在HTML上产生表格的结果了。
谁说这个Table没有必要写的?

 

 

相关文章:

  • 2021-11-10
  • 2021-07-17
  • 2021-07-09
  • 2021-11-21
  • 2022-12-23
  • 2021-07-07
  • 2021-07-03
  • 2021-11-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-07-11
  • 2021-07-31
相关资源
相似解决方案