NVelocityとMSHTMLによる、レポート作成
DBの内容や集計結果などを、nVelocityによりHTMLへ変換、画面へ表示します。
性格上、Webアプリケーションでは無くクライアントアプリケーションに適してると思われ。
利点
- NVelocityにより、テンプレートへのデータ埋め込みが簡単。
- テンプレートをVisualStudio2003でグラフィカルに編集出来る(テンプレートはHTML形式)
private void BtnConvert_Click(object sender, System.EventArgs e)
{
//Velocity初期化
Velocity.Init() ;
VelocityContext context = new VelocityContext() ;
//名前を分割し、contextへ添付
context.Put("nameList" , TxtName.Text.Split(',')) ;
//変換。
//テンプレートの拡張子を"hoge.vm"ではなく"hoge.html"とすると、編集が楽。
Template template = Velocity.GetTemplate("Sample.html") ;
StringWriter writer = new StringWriter() ;
template.Merge(context , writer) ;
//axWebBrowserへ描画する。
IHTMLDocument2 document = (IHTMLDocument2)axWebBrowser1.Document ;
document.write(writer.ToString()) ;
}