復(fù)制代碼 代碼如下:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body >
<table $htmlformat[0] cellpadding="10" cellspacing="0" bgcolor="#eeeeee">
<tr>
<td valign="middle">
<span>$htmlformat[3]</span>
</td>
</tr>
</table>
</body>
</html>
復(fù)制代碼 代碼如下:
//---------------------讀html模板頁面到stringbuilder對象里----
string[] format=new string[4];//定義和htmlyem標(biāo)記數(shù)目一致的數(shù)組
StringBuilder htmltext=new StringBuilder();
try
{
using (StreamReader sr = new StreamReader("存放模板頁面的路徑和頁面名"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
htmltext.Append(line);
}
sr.Close();
}
}
catch
{
Response.Write("<Script>alert('讀取文件錯誤')</Script>");
}
//---------------------給標(biāo)記數(shù)組賦值------------
format[0]="background=/"bg.jpg/"";//背景圖片
format[1]= "#990099";//字體顏色
format[2]="150px";//字體大小
format[3]= "<marquee>生成的模板html頁面</marquee>";//文字說明
//----------替換htm里的標(biāo)記為你想加的內(nèi)容
for(int i=0;i<4;i++)
{
htmltext.Replace("$htmlformat["+i+"]",format[i]);
}
//----------生成htm文件------------------
try
{
using(StreamWriter sw=new StreamWriter("存放路徑和頁面名",false,System.Text.Encoding.GetEncoding("GB2312")))
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
}
}
catch
{
Response.Write ("The file could not be wirte:");
}
新聞熱點
疑難解答
圖片精選