VTemplate模板引擎制作html报表

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
 
<body>
 
<p>
	<table style="width:50%;" cellpadding="2" cellspacing="0" border="1" bordercolor="#000000">
		<tbody>
			<tr>
				<td>
					序号
				</td>
				<td>
					姓名
				</td>
				<td>
					成绩
				</td>
			</tr>
<vt:foreach from="$Student" item="student" index="i">
			<tr>
				<td>
					{$:i}号
				</td>
				<td>
					{$:student.name}
				</td>
				<td>
					{$:student.score}分
				</td>
			</tr>
</vt:foreach>
 
		</tbody>
	</table>
<br />
</p>
</body>
</html>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VTemplate.Engine;
using VTemplate.WebTester;
 
namespace VT
{
    public partial class Form1 : Form
    {
        List<Student> listStudent = new List<Student>();
        public Form1()
        {
            InitializeComponent();
   
            Student student = new Student();
            student.name = "张三";
            student.score = 90;
            listStudent.Add(student);
            Student student1 = new Student();
            student1.name = "李四";
            student1.score = 78;
            listStudent.Add(student1);
            Student student2 = new Student();
            student2.name = "张三";
            student2.score = 89;
            listStudent.Add(student2);
            listStudent.Add(student2);
            listStudent.Add(student2);
            listStudent.Add(student2);
            listStudent.Add(student2);
            listStudent.Add(student2);
            listStudent.Add(student2);
 
 
            //document.Render(context.Response.Output)
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            TemplateDocument document = new TemplateDocument(Application.StartupPath + "\\Untitled-2.html", Encoding.UTF8, TemplateDocumentConfig.Default);
            document.Variables.SetValue("Student", listStudent);
            document.RenderTo(Application.StartupPath + "\\Untitled-2 - 副本.html", Encoding.UTF8);
        }
    }

    class Student
    {
        public string name { get; set; }
        public double score { get; set; }
    }
}

四、效果如下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值